Skip to content

fix(sanitize): redact an Authorization value that holds punctuation - #511

Open
liwenjie200543 wants to merge 1 commit into
Tencent-Hunyuan:mainfrom
liwenjie200543:fix/sanitize-authorization-value
Open

liwenjie200543 wants to merge 1 commit into
Tencent-Hunyuan:mainfrom
liwenjie200543:fix/sanitize-authorization-value

Conversation

@liwenjie200543

Copy link
Copy Markdown

_AUTHORIZATION recognises the header and its scheme, then only consumes a value
made of [A-Za-z0-9._~+/=-]. A token holding any other character (!, $, *,
%, (, #) matches nothing at all, so the whole header reaches the model
verbatim — the pattern recognises the credential and then leaves it in place.

The value is now any run of non-space, non-quote characters. " and ' stay out
of the match so a quoted header keeps its closing quote; the {8,} floor and the
scheme list are unchanged, so a short value and a prose Authorization: mention
behave as before.

Before → after (sanitize_model_input):

Authorization: Bearer abc!defghijk12345                 -> Authorization: Bearer <redacted-secret>
Authorization: Token abc$defghijk1234                   -> Authorization: Token <redacted-secret>
curl -H 'Authorization: Bearer abc*defghijk12345' https://example.org
                                                        -> curl -H 'Authorization: Bearer <redacted-secret>' https://example.org

Tests: test_redacts_an_authorization_value_that_holds_punctuation in
memhub/apps/core/tests/test_input_sanitization.py. 23 passed / 1 failed before the
change, 24 passed after. Ran the two sanitization test files standalone (the package
conftest.py imports pwd, which does not exist on Windows).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant