Skip to content

False positive: Go / MongoDB Find method #19537

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

Open
yogurt-ui opened this issue May 20, 2025 · 4 comments
Open

False positive: Go / MongoDB Find method #19537

yogurt-ui opened this issue May 20, 2025 · 4 comments

Comments

@yogurt-ui
Copy link

Description of the false positive

Code samples or links to source code

https://github.com/github/codeql/blob/dc440aaee6695deb0d9676b87e06ea984e1b4ae5/go/ql/src/Security/CWE-089/SqlInjection/

The following code has a large number of vulnerability false positives in the case of a MongoDB database.
The current MongoDB parameters have defined specific data types, and there are no injection vulnerabilities.

type LogFilter struct {
    ID             []string
}
filter *LogFilter
filterM["id"] = filter.ID
cur, err := dl.Find(ctx, filterM, opts)

-->

@jketema
Copy link
Contributor

jketema commented May 20, 2025

Hi @yogurt-ui

Thank you for this false positive report. Resolving this issue is not a current product priority, but we acknowledge the report and will track it internally for future consideration, or if we observe repeated instances of the same problem.

@jketema jketema added the Go label May 20, 2025
@owen-mc
Copy link
Contributor

owen-mc commented May 20, 2025

@yogurt-ui I would like to make sure that we understand your issue. I assume dl in your code excerpt is a mongo.Collection. We consider it a (no)sql injection if any user-controlled data can flow to the second argument to Collection.Find. Do you disagree with this? Or do you think that in your specific situation, user-controlled data cannot flow there? If so, I would need to see more information about the alerts to understand what is going wrong.

@smowton smowton changed the title False positive False positive: Go / MongoDB Find method May 20, 2025
@yogurt-ui
Copy link
Author

@yogurt-ui I would like to make sure that we understand your issue. I assume dl in your code excerpt is a mongo.Collection. We consider it a (no)sql injection if any user-controlled data can flow to the second argument to Collection.Find. Do you disagree with this? Or do you think that in your specific situation, user-controlled data cannot flow there? If so, I would need to see more information about the alerts to understand what is going wrong.
Sorry, I missed a condition,filterM is a structured map type, so it does not pose an injection risk.
type LogFilter struct {
ID []string
}
filter *LogFilter
filterM := bson.M{}
filterM["id"] = filter.ID
cur, err := dl.Find(ctx, filterM, opts)

@owen-mc
Copy link
Contributor

owen-mc commented May 22, 2025

Are you saying that if the second argument of Collection.Find has type bson.M then there cannot be a no-sql injection attack - perhaps because it will be escaped? If so, can you point me to some documentation of that? I wasn't able to find any. On the contrary, the documentation for bson.M says "There's no special handling for this type in addition to what's done anyway for an equivalent map type.", and I found this article which says that it is vulnerable.

It might help if you could point me to a FP detected by code scanning, if there is one publicly visible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy