-
Notifications
You must be signed in to change notification settings - Fork 6
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
Certain security.txt files can cause parser to hang indefinitely #74
Comments
Some pointers:
The regex might have Catastrophic Backtracking problems? The regex cleaned of newlines and comment: (^-{5}BEGIN\ PGP\ SIGNED\ MESSAGE-{5}(?:\r?\n)(Hash:\ (?P<hashes>[A-Za-z0-9\-,]+)(?:\r?\n){2})?(?P<cleartext>(.*\r?\n)*(.*(?=\r?\n-{5})))(?:\r?\n))?^-{5}BEGIN\ PGP\ (?P<magic>[A-Z0-9 ,]+)-{5}(?:\r?\n)(?P<headers>(^.+:\ .+(?:\r?\n))+)?(?:\r?\n)?(?P<body>([A-Za-z0-9+/]{1,76}={,2}(?:\r?\n))+)^=(?P<crc>[A-Za-z0-9+/]{4})(?:\r?\n)^-{5}END\ PGP\ (?P=magic)-{5}(?:\r?\n)? see this regex101.com, which results in:
Update:
which does not match, and because of some nested Update 2: (^-{5}BEGIN\ PGP\ SIGNED\ MESSAGE-{5}(?:\r?\n)(Hash:\ (?P<hashes>[A-Za-z0-9\-,]+)(?:\r?\n){2})?(?P<cleartext>((^|(([^-]|- )[^\r\n]*))\r?\n)+)?)^-{5}BEGIN\ PGP\ (?P<magic>[A-Z0-9 ,]+)-{5}(?:\r?\n)(?P<headers>(^[a-zA-Z]+:\ [^\r\n]+(?:\r?\n))+)?(?:\r?\n)(?P<body>([A-Za-z0-9+/]{1,76}={,2}(?:\r?\n))+)^=(?P<crc>[A-Za-z0-9+/]{4})(?:\r?\n)^-{5}END\ PGP\ (?P=magic)-{5}(?:\r?\n)?$ This regex seems to be way faster, from 9.9s to 0.2s on my machine on match and no-match. 55c55
< (?P<cleartext>(.*\r?\n)*(.*(?=\r?\n-{5})))(?:\r?\n)
---
> (?P<cleartext>((^|(([^-]|- )[^\r\n]*))\r?\n)+)?
61c61
< (?P<headers>(^.+:\ .+(?:\r?\n))+)?(?:\r?\n)?
---
> (?P<headers>(^[a-zA-Z]+:\ [^\r\n]+(?:\r?\n))+)?(?:\r?\n)?
68c68
< ^-{5}END\ PGP\ (?P=magic)-{5}(?:\r?\n)?
---
> ^-{5}END\ PGP\ (?P=magic)-{5}(?:\r?\n)?$ The last diff also fixed a more than five dash ending. Update 3: the regex still seems wrong, since RFC 4880 - OpenPGP Message Format § 6.2 Forming ASCII Armor states:
Optional whitespace is not matched because of Update 4: Created issue and PR upstream:
Update 5: |
Some specific examples to follow by mail, but certain security.txt files can hang indefinitely in the call to pgpy, specifically in the regex. For example:
Some attempts at isolating this issue to a smaller sample have not shown any particular content that triggers the issue. It may also be dependent on specific Python patch versions or platforms. In some cases, the hang is indefinite, in some cases the parsing is only very slow (several seconds).
Suggestion: consider removing the PGP parsing check until we're certain this issue is resolved.
The text was updated successfully, but these errors were encountered: