Skip to content
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

False positive - A secret detected in a go context causes codeql to think all context values are secret #16486

Open
Jamstah opened this issue May 14, 2024 · 3 comments
Labels
acknowledged GitHub staff acknowledges this issue false-positive Go

Comments

@Jamstah
Copy link

Jamstah commented May 14, 2024

Description of the false positive

We use a convenience function to create a logger that includes additional variables taken from a context.Context using the Value call to get the value.

The context itself contains secrets that may be needed. When the logger is created we specify the keys that should be taken from the context to add to the logger.

CodeQL is identifying a Clear-text logging of sensitive information which seems to think that taking any value out of the context, regardless of what is requested, is logging sensitive information.

Code samples or links to source code

This one is detected in the creation of the logger:

https://github.com/distribution/distribution/blob/56a020f7f1fbec903d785b552c97330c58fddae6/internal/dcontext/logger.go#L138
https://github.com/distribution/distribution/security/code-scanning/36

This one is detected when logging an error using context.Errors, which has been populated with a value from the context that is not secret:
https://github.com/distribution/distribution/blob/56a020f7f1fbec903d785b552c97330c58fddae6/registry/handlers/app.go#L831
https://github.com/distribution/distribution/security/code-scanning/23

There are more in the repo that match the same pattern.

milosgajdos added a commit to distribution/distribution that referenced this issue May 14, 2024
Merging despite CodeQL warnings. see this for more details, why we decided to merge: github/codeql#16486
@mbg
Copy link
Member

mbg commented May 14, 2024

Hi @Jamstah 👋

Thanks for reporting this and including the links to the relevant parts of the code and corresponding alerts! That is all very helpful.

This is a tricky one for us to deal with correctly. It is quite a complex problem to identify which elements of your context are accessed (particularly with the loop that takes some items out, depending on which keys are in the array). So we detect that sensitive data flows into the context, but since it's hard to reason about where it flows from there, we taint the entire structure and consequently flag any access.

Fixing false positives is not a current product priority, but we will track this issue internally. I cannot say when it may get looked into though and, even then, it may be a tricky one for us to fix.

In the short term, you can dismiss these alerts if you are happy that they are false positives. If this continues to be a nuisance for you, some options are to either refactor the code to avoid having the sensitive data flow into the context or using a custom CodeQL configuration to exclude the go/clear-text-logging query completely. I appreciate neither of these are ideal though.

@mbg mbg added acknowledged GitHub staff acknowledges this issue Go labels May 14, 2024
@Jamstah
Copy link
Author

Jamstah commented May 14, 2024

Thanks for the analysis and options. I haven't worked with CodeQL much, and my knowledge of go contexts is sketchy, so even some confirmation that what I thought was happening is right is really valuable. I was half expecting you to tell me I read it wrong and its horribly insecure ;)

I've got a PR together which removes sensitive data from the context, so I'll propose that to my co-contributors. I expect its a sensible direction for us anyway. If that doesn't go down well, we'll mark them as false positives in the tool and move on.

I don't know if you want to leave this open or close it, but I won't be offended either way.

@mbg
Copy link
Member

mbg commented May 14, 2024

No problem!

I don't know if you want to leave this open or close it, but I won't be offended either way.

We do want to leave this open so that we can continue to track it until it is resolved at some point of the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
acknowledged GitHub staff acknowledges this issue false-positive Go
Projects
None yet
Development

No branches or pull requests

2 participants