-
Notifications
You must be signed in to change notification settings - Fork 0
fix(plugins): implement structured line-oriented parser for secret redaction #23
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
83833fe
fix(plugins): implement structured line-oriented parser for secret re…
ProfRandom92 592046d
fix(redaction): handle quoted JSON keys and escaped secret values
ProfRandom92 affeb43
test(previews): expand safety redaction matrix for escaped quotes and…
ProfRandom92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| ROOT = Path(__file__).resolve().parents[1] | ||
| sys.path.insert(0, str(ROOT / "hf_space")) | ||
| sys.path.insert(0, str(ROOT / "plugins" / "pr-review-memory")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import pytest | ||
|
|
||
| from previews import scan_secrets | ||
| from renderer import _clean_text | ||
|
|
||
| def test_secret_scan_previews_matrix(): | ||
| assert "secret-assignment" in scan_secrets("TOKEN=value") | ||
| assert "secret-assignment" in scan_secrets("HF_TOKEN=value") | ||
| assert "secret-assignment" in scan_secrets("_HF_TOKEN=value") | ||
| assert "secret-assignment" in scan_secrets("MY_TOKEN_1=value") | ||
| assert "secret-assignment" in scan_secrets("api_key=value") | ||
| assert "secret-assignment" in scan_secrets("SERVICE_API_KEY=value") | ||
| assert "secret-assignment" in scan_secrets("TOKEN = value") | ||
| assert "secret-assignment" in scan_secrets('TOKEN="value"') | ||
| assert "secret-assignment" in scan_secrets("TOKEN='value'") | ||
| assert "secret-assignment" in scan_secrets("export HF_TOKEN=value") | ||
|
|
||
| assert "secret-assignment" not in scan_secrets("HF_TOKEN=\n'value'") | ||
| assert "secret-assignment" not in scan_secrets("NORMAL_VAR=value") | ||
|
|
||
| def test_secret_redaction_renderer_matrix(): | ||
| assert _clean_text("TOKEN=value") == "TOKEN=<redacted>" | ||
| assert _clean_text("HF_TOKEN=value") == "HF_TOKEN=<redacted>" | ||
| assert _clean_text("_HF_TOKEN=value") == "_HF_TOKEN=<redacted>" | ||
| assert _clean_text("MY_TOKEN_1=value") == "MY_TOKEN_1=<redacted>" | ||
| assert _clean_text("api_key=value") == "api_key=<redacted>" | ||
| assert _clean_text("SERVICE_API_KEY=value") == "SERVICE_API_KEY=<redacted>" | ||
| assert _clean_text("TOKEN = value") == "TOKEN = <redacted>" | ||
| assert _clean_text('TOKEN="value"') == 'TOKEN="<redacted>"' | ||
| assert _clean_text("TOKEN='value'") == "TOKEN='<redacted>'" | ||
|
|
||
| # New edge cases | ||
| assert _clean_text('TOKEN="abc\\"def"') == 'TOKEN="<redacted>"' | ||
| assert _clean_text('"TOKEN": "value"') == '"TOKEN": "<redacted>"' | ||
| assert _clean_text("'API_KEY': 'value'") == "'API_KEY': '<redacted>'" | ||
| assert _clean_text('{"api_key": "value"}') == '{"api_key": "<redacted>"}' | ||
| assert _clean_text('{"normal": "value"}') == '{"normal": "value"}' | ||
| assert _clean_text("TOKEN=val1 API_KEY=val2") == "TOKEN=<redacted> API_KEY=<redacted>" | ||
| assert _clean_text('TOKEN="<redacted>"') == 'TOKEN="<redacted>"' | ||
|
|
||
| # Explicit cases required by Thread C | ||
| assert _clean_text('TOKEN="value\\"with\\"escapes"') == 'TOKEN="<redacted>"' | ||
| assert _clean_text("TOKEN='value\\'with\\'escapes'") == "TOKEN='<redacted>'" | ||
| assert _clean_text("HF_TOKEN=") == "HF_TOKEN=" | ||
| assert _clean_text("HF_TOKEN=\n'value'") == "HF_TOKEN= '<redacted>'" # _clean_text collapses newlines to space first | ||
| assert _clean_text("NORMAL_VAR=value") == "NORMAL_VAR=value" | ||
|
|
||
| # Line boundary checks (no processing across lines on raw multiline text) | ||
| from previews import redact_secrets | ||
| assert redact_secrets("HF_TOKEN=\n'value'") == ("HF_TOKEN=\n'value'", False) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.