-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
chore: Enable G110 rule for gosec #13044
Conversation
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 don't think those changes are actual fixes. In all cases you copy an unlimited amount of data. You are just silencing the (valid) warnings by replacing the triggering io.Copy()
with an infinite loop of copying chunks not triggering the dumb linter by using io.CopyN()
.
I think the only fix in all those spots is to either determine the _actual _ upper limit of the source's content size or by applying a user-set upper limit, either through code or via config options.
internal/content_coding.go
Outdated
_, err = io.Copy(d.buf, r) | ||
if err != nil && !errors.Is(err, io.EOF) { | ||
return nil, err | ||
|
||
for { | ||
_, err = io.CopyN(d.buf, r, 1024*1024) | ||
if err != nil { | ||
if errors.Is(err, io.EOF) { | ||
break | ||
} | ||
return nil, err | ||
} | ||
} | ||
|
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.
How is this different to the code before? You can still exhaust memory by a so called ZIP bomb. The only valid defense is to provide a upper decompression limit, i.e. specify n
value passed to io.CopyN
.
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.
For tests it is easy, we can hardcode n
value.
But ContentDecoder
s from internal/content_coding.go
are used in:
- AMQP Consumer Input Plugin
- Socket Listener Input Plugin
For these two new configuration field should be added (with reasonable default value) to hold upper size limit.
@srebhan Will that be ok?
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.
Yes I think that's OK. We should set this to unlimited somehow... @powersj any opinion?
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.
Sounds go to add, but how do we keep the unlimited? Maybe a setting of 0 == unlimited and if so we use io.Copy
?
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.
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.
Please, review current implementation.
Understood, but what risk do we run by putting in a new default and breaking users?
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.
@powersj For both plugins default was set to 500MB
.
It will not change anything for users operating on payload of smaller size.
Users with bigger payload will need to set larger value in config. We may call it "breaking users" or "fixing security gaps" ;)
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.
ok we chatted and agree with the new default, we will want to call this out in change log for the next release
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.
@zak-pawel I like the approach. I do have some more suggestions though... Sorry!
@srebhan All addressed. |
Download PR build artifacts for linux_amd64.tar.gz, darwin_amd64.tar.gz, and windows_amd64.zip. 📦 Click here to get additional PR build artifactsArtifact URLs |
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.
Awesome work @zak-pawel! Thank you for addressing this issue!
Co-authored-by: Pawel Zak <Pawel Zak> (cherry picked from commit ba16eeb)
resolves #12897