Repository navigation
fix(engine): keep connection key redaction consistent #2195
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -354,13 +354,16 @@ pub fn stripped_parameters(given: &str, saved: &str) -> Vec<String> { | |
| use crate::render::rustgis_tiles::logins; | ||
| fn names(address: &str) -> Vec<&str> { | ||
| let query = address.split('#').next().and_then(|a| a.split_once('?')).map_or("", |(_, query)| query); | ||
| query.split('&').filter_map(|pair| pair.split_once('=').map(|(name, _)| name)).filter(|name| !name.is_empty()).collect() | ||
| query.split(['&', ';']).filter_map(|pair| pair.split_once('=').map(|(name, _)| name)).filter(|name| !name.is_empty()).collect() | ||
| } | ||
| let query = given.split('#').next().and_then(|a| a.split_once('?')).map_or("", |(_, query)| query); | ||
| let context = rustgis_data::address::QueryNames::of(query); | ||
| let kept = names(saved); | ||
| let mut left_out: Vec<String> = Vec::new(); | ||
| for name in names(given) { | ||
| if left_out.len() < 4 | ||
| && logins::valid_query_name(name) | ||
| && rustgis_data::address::name_class(name, &context) == rustgis_data::address::NameClass::Credential | ||
| && !kept.contains(&name) | ||
| && !left_out.iter().any(|known| known.eq_ignore_ascii_case(name)) | ||
| { | ||
|
|
@@ -395,8 +398,11 @@ pub fn clean(mut c: Connection) -> Result<(Connection, bool), String> { | |
| return Err("a connection address must be at most 2048 bytes and contain no control characters".into()); | ||
| } | ||
| // A query login's own parameter goes before anything quotes the address (an error included): | ||
| // its name may not be registered yet, so the generic redaction can't see it. | ||
| let query_name = Some(c.key_name.trim()).filter(|name| c.auth.trim().eq_ignore_ascii_case("query") && !name.is_empty()); | ||
| // its name may not be registered yet, so the generic redaction can't see it. A name given | ||
| // without a method still declares a possible key, as it does in the replay log. An explicit | ||
| // other method (`none` included) does not select a query parameter. | ||
| let query_name = Some(c.key_name.trim()) | ||
| .filter(|name| (c.auth.trim().is_empty() || c.auth.trim().eq_ignore_ascii_case("query")) && !name.is_empty()); | ||
| let given = query_name.map_or_else(|| t.to_string(), |name| crate::render::rustgis_tiles::logins::without_query_parameter(t, name)); | ||
|
Contributor
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. Never silent (confidence: medium, plausible): Suggested direction: have |
||
| let stored = sources::redact(&given); | ||
| let stripped = stored != t; | ||
|
|
||
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.
Bug (confidence: medium-high): the new empty-
authbranch runs for every kind, including database kinds (postgres,mysql,sqlserver).clean_loginreturns early for an emptyauthand never checks the kind, so akeyNameon a database connection now removes a matching query parameter from its address. Before this change the same input only clearedkeyName.Failure scenario:
connection.new {"kind":"mysql","name":"Shop","address":"mysql://reader@db.example/shop?charset=utf8mb4","keyName":"charset"}savesmysql://reader@db.example/shop, returnsstripped: true, and emits "A password or token in the address was left out". The removed value is a non-secret setting, and the notice is wrong about it.Suggested fix: limit the empty-method case to web-service kinds.
A regression test for a MySQL or Postgres address with a query parameter named like the
keyNamewould cover this.