Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions crates/engine/src/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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());

Copy link
Copy Markdown
Contributor

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-auth branch runs for every kind, including database kinds (postgres, mysql, sqlserver). clean_login returns early for an empty auth and never checks the kind, so a keyName on a database connection now removes a matching query parameter from its address. Before this change the same input only cleared keyName.

Failure scenario: connection.new {"kind":"mysql","name":"Shop","address":"mysql://reader@db.example/shop?charset=utf8mb4","keyName":"charset"} saves mysql://reader@db.example/shop, returns stripped: 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.

Suggested change
.filter(|name| (c.auth.trim().is_empty() || c.auth.trim().eq_ignore_ascii_case("query")) && !name.is_empty());
let query_name = Some(c.key_name.trim()).filter(|name| {
let auth = c.auth.trim();
let no_method = auth.is_empty() && SERVICE_KINDS.contains(&c.kind.as_str());
(no_method || auth.eq_ignore_ascii_case("query")) && !name.is_empty()
});

A regression test for a MySQL or Postgres address with a query parameter named like the keyName would cover this.

let given = query_name.map_or_else(|| t.to_string(), |name| crate::render::rustgis_tiles::logins::without_query_parameter(t, name));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never silent (confidence: medium, plausible): connection.test without an id calls clean(c)?.0 in crates/engine/src/cmd/connections.rs:1043 and discards the stripped flag. With this change, {"kind":"wmts","address":"…?zqkey=…","keyName":"zqkey"} (no auth) is tested with the parameter removed, and no notice is produced on that path. The same gap already exists for generic credential names such as ?token=, but this PR widens the set of names it covers.

Suggested direction: have tested surface the flag, for example by emitting the same stripped notice shown_stripped produces, or by returning an error that says the address holds a key and should be saved with a login method.

let stored = sources::redact(&given);
let stripped = stored != t;
Expand Down
23 changes: 23 additions & 0 deletions crates/engine/src/tests/service_logins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2727,6 +2727,29 @@ fn a_key_in_the_address_is_left_out_and_its_parameter_offered_as_the_login() {
assert!(bare.get("strippedParameters").is_none(), "{bare}");
let said = format!("{bare}{:?}", s.notices_since(mark));
assert!(!said.contains("RGSYNTHbare757"), "{said}");
// Legacy semicolons separate query pairs too. A public pair dropped alongside a key is not
// offered as a credential name.
let legacy = s
.run(
"connection.new",
&json!({"kind":"wmts","name":"Legacy separators","address":format!("{origin}/legacy?x=1;token=RGSYNTHlegacy757")}),
)
.unwrap();
assert_eq!(legacy["stripped"], true);
assert_eq!(legacy["strippedParameters"], json!(["token"]));
// A custom key name is a redaction hint even before a method is chosen; the saved definition
// must be as safe as its replay log. An explicit no-login method leaves ordinary data alone.
let no_method = s
.run("connection.new", &json!({"kind":"wmts","name":"Custom without method","address":format!("{origin}/custom?zqwithoutmethod757=RGSYNTHnomethod757&layer=a"),"keyName":"zqwithoutmethod757"}))
.unwrap();
assert_eq!(no_method["stripped"], true);
assert_eq!(no_method["address"], format!("{origin}/custom?layer=a"));
assert!(!s.connections.to_json().contains("RGSYNTHnomethod757"));
let explicit_none = s
.run("connection.new", &json!({"kind":"wmts","name":"Explicit no login","address":format!("{origin}/none?zqordinary757=public-code"),"keyName":"zqordinary757","auth":"none"}))
.unwrap();
assert!(explicit_none.get("stripped").is_none());
assert_eq!(explicit_none["address"], format!("{origin}/none?zqordinary757=public-code"));
}

/// A key in a query login is sent on the wire to the origin (and only as the parameter the
Expand Down
Loading