-
-
Notifications
You must be signed in to change notification settings - Fork 167
feat: filter username and password in URLs #864
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
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,23 @@ const SENSITIVE_HEADERS_UPPERCASE: &[&str] = &[ | |
"X_API_KEY", | ||
]; | ||
|
||
const PII_REPLACEMENT: &str = "[Filtered]"; | ||
|
||
/// Determines if the HTTP header with the given name shall be considered as potentially carrying | ||
/// sensitive data. | ||
pub fn is_sensitive_header(name: &str) -> bool { | ||
SENSITIVE_HEADERS_UPPERCASE.contains(&name.to_ascii_uppercase().replace("-", "_").as_str()) | ||
} | ||
|
||
/// Scrub PII (username and password) from the given URL. | ||
pub fn scrub_pii_from_url(mut url: url::Url) -> url::Url { | ||
// the set calls will fail and return an error if the URL is relative | ||
// in those cases, just ignore the errors | ||
if !url.username().is_empty() { | ||
let _ = url.set_username(PII_REPLACEMENT); | ||
} | ||
if url.password().is_some() { | ||
let _ = url.set_password(Some(PII_REPLACEMENT)); | ||
Comment on lines
+26
to
+29
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. The cases in which these can fail are documented as follows:
This happens for instance if the URL is relative. In these cases we just ignore the errors. 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. Please add this information as a code comment, as it could be helpful for future developers |
||
} | ||
url | ||
} |
Uh oh!
There was an error while loading. Please reload this page.