Conversation
mr-cal
left a comment
There was a problem hiding this comment.
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. 🚀 New features to boost your workflow:
|
|
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. |
| @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.
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)