-
Notifications
You must be signed in to change notification settings - Fork 457
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 ReDoS (GHSL-2024-323) #5210
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.
Hi, I'm not sure what this is solving, can you provide details?
https://bugs.launchpad.net/snapcraft/+bug/2086622 doesn't seem to exist.
GitHub Security Lab (GHSL) Vulnerability Report, snapcraft:
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #5210 +/- ##
==========================================
- Coverage 94.88% 89.68% -5.20%
==========================================
Files 658 341 -317
Lines 55189 22614 -32575
==========================================
- Hits 52364 20282 -32082
+ Misses 2825 2332 -493 ☔ View full report in Codecov by Sentry. |
Fortunately I don't believe this will affect anything but snapcraft - the only service that would ever run that code is a Launchpad remote build. |
@@ -449,7 +449,7 @@ def _validate_bus_name(cls, name): | |||
) | |||
@classmethod | |||
def _validate_time(cls, timeval): | |||
if not re.match(r"^[0-9]+(ns|us|ms|s|m)*$", timeval): | |||
if not re.match(r"^[0-9]+(ns|us|s|m)*$", timeval): |
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.
Given that these are timeout strings that get passed unaffected to snapd and parsed using golang's time.ParseDuration
, I believe a more correct version of this regex would be:
if not re.match(r"^[0-9]+(ns|us|s|m)*$", timeval): | |
if not re.match(r"^([0-9]+(ns|us|ms|s|m)){1,5}$" timeval): |
Inspired by: #5210 This makes an annotated type for duration strings and uses a stricter regex.
Reading this brought up a few things in my mind related to how we check these duration strings, as I don't think the original regex is even correct. I've made a separate PR that should both correct the values we allow and resolve this issue. |
@lengau: Thanks! Your version is better. My goal was just to fix the ReDoS without changing the behavior of the regex, but yours changes it so that the regex is more precise. I'll close this PR now. |
Thanks again for alerting us to this @kevinbackhouse ! The reproducer was great as it showed both the particular issue and the problem my PR fixes 😀 |
Inspired by: #5210 This makes an annotated type for duration strings and uses a stricter regex.
tox run -m lint
?tox run -e test-py310
? (supported versions:py39
,py310
,py311
,py312
)Fixes a ReDoS: https://bugs.launchpad.net/snapcraft/+bug/2086622 (GHSL-2024-323)