Repository navigation
Redact credentials in GitHub review findings #1312
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
ffdcdbf
9103ee0
3be6160
9d59956
b83881a
2652547
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 |
|---|---|---|
|
|
@@ -126,8 +126,8 @@ class Readiness: | |
| _read_scope: ContextVar[tuple[float, str | None, bool] | None] = ContextVar("github_reads", default=None) | ||
| _api_error_diagnostics: ContextVar[bool] = ContextVar("github_api_error_diagnostics", default=False) | ||
| _HTTP_STATUS_RE = re.compile(r"^HTTP/\S+\s+(\d{3})(?:\s+(.*))?$", re.IGNORECASE) | ||
| _GITHUB_TOKEN_RE = re.compile( | ||
| r"\b(?:github_pat_[A-Za-z0-9_]+|gh[pousr]_[A-Za-z0-9_]{10,})\b" | ||
| _CREDENTIAL_TOKEN_RE = re.compile( | ||
| r"\b(?:github_pat_[A-Za-z0-9_]+\b|gh[pousr]_[A-Za-z0-9_]{10,}\b|sk-[A-Za-z0-9_-]{8,})" | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -220,7 +220,7 @@ def _redact_tokens(value: str, token: str = "") -> str: | |
| value = re.sub(r"(?i)\b(authorization)\s*[:=]\s*" | ||
| r"(?:(?:basic|bearer|token)\s+)?[^\s,;]+", r"\1=[REDACTED]", value) | ||
| value = re.sub(r"(?i)\bBearer\s+[^\s,;]+", "Bearer [REDACTED]", value) | ||
| value = _GITHUB_TOKEN_RE.sub("[REDACTED]", value) | ||
| value = _CREDENTIAL_TOKEN_RE.sub("[REDACTED]", value) | ||
| value = re.sub(r"(?i)\b(access_token|auth_token|token)\s*[:=]\s*" | ||
| r"[^\s,;]+", r"\1=[REDACTED]", value) | ||
| value = re.sub(r"(?i)(https?://[^?\s]+)\?[^\s]+", r"\1?[REDACTED]", value) | ||
|
|
@@ -780,7 +780,7 @@ def finding_marker(severity: str, head_sha: str, finding: Finding) -> str: | |
|
|
||
|
|
||
| def _comment_body(f: Finding, head_sha: str, prefix: str = "") -> str: | ||
| text = f"{prefix}**{f.severity}: {f.title}**\n\n{f.body}".rstrip() | ||
| text = prefix + _CREDENTIAL_TOKEN_RE.sub("[REDACTED]", f"**{f.severity}: {f.title}**\n\n{f.body}").rstrip() | ||
|
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: Finding prose uses a narrower credential recogniser than the shared The task says to apply the shared credential recognition to finding prose. |
||
| if f.severity in BLOCKING: | ||
| return f"{finding_marker(f.severity, head_sha, f)}\n{text}" | ||
| return text | ||
|
|
@@ -832,7 +832,7 @@ def _review_body(result: ReviewResult, unplaced: list[Finding], prefix: str = "" | |
| lines.extend(_review_settings_lines(result, include_configured=settings_layout == "current")) | ||
| if unplaced: | ||
| lines.append("\nFindings without a file location:\n") | ||
| lines += [f"- **{f.severity}**: {f.title} — {f.body}".rstrip(" —") for f in unplaced] | ||
| lines += [_CREDENTIAL_TOKEN_RE.sub("[REDACTED]", f"- **{f.severity}**: {f.title} — {f.body}".rstrip(" —")) for f in unplaced] | ||
|
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: The same inline redaction call is duplicated at two publication sites
|
||
| return "\n".join(lines) + _review_transcript(result, legacy_display) | ||
|
|
||
|
|
||
|
|
||
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: The broader
sk-pattern can redact ordinary hyphenated words in both prose and API error diagnostics\bsk-[A-Za-z0-9_-]{8,}matches any standalone word that starts withsk-and has 8 or more following characters, including hyphens. Ordinary text likesk-learn-compatibleor a branch name likesk-refactor-loaderbecomes[REDACTED]. This works against the acceptance item that explanatory text must survive. The regex is shared with_redact_tokens, so the same applies to GhError diagnostics. If false positives matter, require a longer body or a known prefix, for examplesk-(?:ant-|proj-)?[A-Za-z0-9_-]{20,}. The tests use short fake values, so they would need longer ones.