-
Notifications
You must be signed in to change notification settings - Fork 8
Fix weak and inconsistent secret default validation #467
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
Open
ChristianPavilonis
wants to merge
5
commits into
main
Choose a base branch
from
fix/secret-default-validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+168
−34
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
721300d
Fix weak and inconsistent secret default validation
ChristianPavilonis 42f3b10
Address PR review: restore missing test, assert specific error varian…
ChristianPavilonis f45edc2
Merge branch 'main' into fix/secret-default-validation
aram356 cbef697
Address PR review: add proxy_secret validation, centralize placeholde…
ChristianPavilonis e89850b
Merge branch 'main' into fix/secret-default-validation
aram356 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,17 @@ pub struct Publisher { | |
| } | ||
|
|
||
| impl Publisher { | ||
| /// Known placeholder values that must not be used in production. | ||
| #[allow(dead_code)] | ||
| pub const PROXY_SECRET_PLACEHOLDERS: &[&str] = &["change-me-proxy-secret"]; | ||
ChristianPavilonis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// Returns `true` if `proxy_secret` matches a known placeholder value. | ||
| #[allow(dead_code)] | ||
| #[must_use] | ||
| pub fn is_placeholder_proxy_secret(proxy_secret: &str) -> bool { | ||
| Self::PROXY_SECRET_PLACEHOLDERS.contains(&proxy_secret) | ||
| } | ||
|
|
||
| /// Extracts the host (including port if present) from the `origin_url`. | ||
| /// | ||
| /// # Examples | ||
|
|
@@ -180,23 +191,22 @@ impl DerefMut for IntegrationSettings { | |
| pub struct Synthetic { | ||
| pub counter_store: String, | ||
| pub opid_store: String, | ||
| #[validate(length(min = 1), custom(function = Synthetic::validate_secret_key))] | ||
| #[validate(length(min = 1))] | ||
| pub secret_key: String, | ||
| #[validate(length(min = 1))] | ||
| pub template: String, | ||
| } | ||
|
|
||
| impl Synthetic { | ||
| /// Validates that the secret key is not the placeholder value. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns a validation error if the secret key is `"secret_key"` (the placeholder). | ||
| pub fn validate_secret_key(secret_key: &str) -> Result<(), ValidationError> { | ||
| match secret_key { | ||
| "secret_key" => Err(ValidationError::new("Secret key is not valid")), | ||
| _ => Ok(()), | ||
| } | ||
| /// Known placeholder values that must not be used in production. | ||
| #[allow(dead_code)] | ||
| pub const SECRET_KEY_PLACEHOLDERS: &[&str] = &["secret-key", "secret_key", "trusted-server"]; | ||
ChristianPavilonis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// Returns `true` if `secret_key` matches a known placeholder value. | ||
| #[allow(dead_code)] | ||
| #[must_use] | ||
| pub fn is_placeholder_secret_key(secret_key: &str) -> bool { | ||
| Self::SECRET_KEY_PLACEHOLDERS.contains(&secret_key) | ||
| } | ||
|
Collaborator
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. 🤔 thinking — Placeholder matching is case-sensitive. Someone setting pub fn is_placeholder_secret_key(secret_key: &str) -> bool {
Self::SECRET_KEY_PLACEHOLDERS
.iter()
.any(|p| p.eq_ignore_ascii_case(secret_key))
} |
||
| } | ||
|
|
||
|
|
@@ -613,6 +623,7 @@ mod tests { | |
| #[test] | ||
| fn test_settings_missing_required_fields() { | ||
| let re = Regex::new(r"origin_url = .*").expect("regex should compile"); | ||
|
|
||
| let toml_str = crate_test_settings_str(); | ||
| let toml_str = re.replace(&toml_str, ""); | ||
|
|
||
|
|
@@ -623,6 +634,42 @@ mod tests { | |
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn is_placeholder_secret_key_rejects_all_known_placeholders() { | ||
| for placeholder in Synthetic::SECRET_KEY_PLACEHOLDERS { | ||
| assert!( | ||
| Synthetic::is_placeholder_secret_key(placeholder), | ||
| "should detect placeholder secret_key '{placeholder}'" | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn is_placeholder_secret_key_accepts_non_placeholder() { | ||
| assert!( | ||
| !Synthetic::is_placeholder_secret_key("test-secret-key"), | ||
| "should accept non-placeholder secret_key" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn is_placeholder_proxy_secret_rejects_all_known_placeholders() { | ||
| for placeholder in Publisher::PROXY_SECRET_PLACEHOLDERS { | ||
| assert!( | ||
| Publisher::is_placeholder_proxy_secret(placeholder), | ||
| "should detect placeholder proxy_secret '{placeholder}'" | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn is_placeholder_proxy_secret_accepts_non_placeholder() { | ||
| assert!( | ||
| !Publisher::is_placeholder_proxy_secret("unit-test-proxy-secret"), | ||
| "should accept non-placeholder proxy_secret" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_settings_empty_toml() { | ||
| let toml_str = ""; | ||
|
|
||
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
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.