Repository navigation
Redact credentials in PR check summaries #1284
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
Changes from all commits
8da5c4b
aaa18e3
fbb06bb
84f7512
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -197,6 +197,15 @@ def _api_path(args: tuple[str, ...]) -> str: | |
| return "/" + path.lstrip("/") | ||
|
|
||
|
|
||
| def redact_credentials(value: str) -> str: | ||
| value = re.sub(r"""(?i)(https?://)[^\s/?#'"<>`]+@""", r"\1[REDACTED]@", value) | ||
| value = re.sub(r"""(?i)(\bauthorization(?:\\?['"])?[ \t]*:[ \t]*)(\\?['"])(?:(?!\2)(?:\\.|[^\\\r\n]))+\2""", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Two overlapping Authorization regexes need to be kept in sync by hand Two passes now handle Authorization: one for a quoted key with a quoted value, and one for a quoted header string or an unquoted header. Each has its own escape and quote handling, so a future fix to one can easily miss the other. The ordering also matters: the second pass only avoids redacting |
||
| r"\1\2[REDACTED]\2", value) | ||
| return re.sub(r"""(?i)((?P<quote>['"])?\bauthorization[ \t]*:[ \t]*)""" | ||
|
eowca marked this conversation as resolved.
Resolved
|
||
| r"""(?(quote)(?:\\.|(?!(?P=quote))[^\\\r\n])+|(?:[a-z][\w-]*[ \t]+)?(?:\\.|[^\\\s'"`])+)""", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Broadened scheme prefix can over-redact ordinary command text
|
||
| r"\1[REDACTED]", value) | ||
|
|
||
|
|
||
| def _redact_tokens(value: str, token: str = "") -> str: | ||
| for secret in (token, os.environ.get("GH_TOKEN", ""), | ||
| os.environ.get("GITHUB_TOKEN", "")): | ||
|
|
||
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.
suggestion: Quoted-key values that use a string prefix or
=are still published unredactedThe new first pass only matches when a quote comes straight after the colon, and the second pass is skipped because of the quote after the key. So
{"Authorization": f"Bearer <literal>"}, ab"..."orr"..."value, anddict(Authorization="Bearer <literal>")/Authorization="..."kwargs all reach the Validation block unredacted. The existing'Authorization': '...'and"Authorization": "..."cases are covered. A literal token inside an f-string is unusual, so this is not blocking. If you want it covered, allow an optional[rbfu]{0,2}prefix before group 2 and accept[:=]as the separator. Add one test case for each.