-
-
Notifications
You must be signed in to change notification settings - Fork 655
Fix false positives for SQL string concatenation with constants from another file #247
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
Fix false positives for SQL string concatenation with constants from another file #247
Conversation
If node.Y resolves to a literal, it will not be considered as an issue.
if n.Obj != nil { | ||
return n.Obj.Kind != ast.Var && n.Obj.Kind != ast.Fun | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have a test for this use case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I was thinking so too. But this test case spans across two files and I'm not sure how to do it. Let me try to figure it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can extend the sample.Code
to support multiple files. The test package is built here:
Line 35 in 5f98926
pkg.AddFile(fmt.Sprintf("sample_%d.go", n), sample.Code) |
In this file are the code samples defined:
https://github.com/securego/gosec/blob/master/testutils/source.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a new value to the CodeSample
struct.
type CodeSample struct {
Code string
Errors int
SupportingCode bool
}
Snippets that have it set to true
will not be processed against the rules, but added to the same pkg
as the other snippets to be processed together.
Not sure if this is this most elegant way to allow for testing with multiple files. Feedback will be welcomed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine. You could have also use a Code []string
. To keep multiple files. I will refactoring afterwards.
Thanks for providing the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh yes. It's much better to use Code []string
. If you are okay, can I help with the refactoring? for https://hacktoberfest.digitalocean.com/ 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refactored it in the PR #248
if n.Obj != nil { | ||
return n.Obj.Kind != ast.Var && n.Obj.Kind != ast.Fun | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine. You could have also use a Code []string
. To keep multiple files. I will refactoring afterwards.
Thanks for providing the tests.
Fixes #169. Sorry, it's been a while, was busy with work. 😅
This PR aims to handle the following case:
main.go
constants.go (for example)
Currently, gosec will flag this this out as an issue in
main.go
as thegender
identifier is unresolved.This PR will add
pkg.Files
togosec.context
so that we will be able to resolve that identifier if it happens to be in the global scope of that package.