Skip to content

Shred overwritten cached credentials #28436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions stdlib/LibGit2/src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1303,13 +1303,17 @@ end

function approve(cache::CachedCredentials, cred::AbstractCredential, url::AbstractString)
cred_id = credential_identifier(url)
if haskey(cache.cred, cred_id) && cred !== cache.cred[cred_id]
Base.shred!(cache.cred[cred_id])
end
cache.cred[cred_id] = cred
nothing
end

function reject(cache::CachedCredentials, cred::AbstractCredential, url::AbstractString)
cred_id = credential_identifier(url)
if haskey(cache.cred, cred_id)
Base.shred!(cache.cred[cred_id])
delete!(cache.cred, cred_id)
end
nothing
Expand Down
22 changes: 18 additions & 4 deletions stdlib/LibGit2/test/libgit2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1734,14 +1734,28 @@ mktempdir() do dir
@test haskey(cache, cred_id)
@test cache[cred_id] === cred

# Reject an approved should cause it to be removed
# Approve the same credential again which does not overwrite
LibGit2.approve(cache, cred, url)
@test haskey(cache, cred_id)
@test cache[cred_id] === cred

# Overwrite an already cached credential
dup_cred = deepcopy(cred)
LibGit2.approve(cache, dup_cred, url) # Shreds `cred`
@test haskey(cache, cred_id)
@test cache[cred_id] === dup_cred
@test dup_cred.pass == password
@test cred.pass != password

cred = dup_cred

# Reject an approved should cause it to be removed and shredded
LibGit2.reject(cache, cred, url)
@test !haskey(cache, cred_id)
@test cred.user == "julia"
@test cred.pass == password
@test cred.user != "julia"
@test cred.pass != password

Base.shred!(cache)
Base.shred!(cred)
Base.shred!(password)
end

Expand Down