Skip to content

Commit 81017a4

Browse files
committed
fix(sitemap): cover credential redaction for a parseable sitemap URL, note map_search change
sitemap_urls_from_well_known carries a credentialed seed's userinfo into the well-known sitemap URL, so an unparseable urlset entry logged against it hit log_unparseable_loc's redaction branch with no test covering it. Add a test that maps a seed URL with credentials over a urlset with one bad <loc> and asserts the log never carries the password. State in both changelogs that map_search now matches the normalized address, so a raw spelling (a default port, or non-ASCII text) no longer matches. Note in the URL discovery guide that sitemap entries are normalized and deduplicated too, alongside the existing HTML link dedup note.
1 parent a5b6ede commit 81017a4

4 files changed

Lines changed: 43 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ All notable changes to crawlberg are documented here.
5858
sitemap-index children and returned in its normalized form. A `<loc>` that does not parse is
5959
dropped. An address is returned once per `map()` call, even when several sitemaps list it, and a
6060
duplicate does not count toward `map_limit`. A relative `<loc>` is now subject to
61-
`exclude_paths`, like every other entry. (#323)
61+
`exclude_paths`, like every other entry. `map_search` now matches the normalized address, so a
62+
search for a raw spelling, such as a default port or non-ASCII text in the path or host, no
63+
longer matches. (#323)
6264

6365
- **The vendored C header gate failed for lag rather than for a defect.** It required each
6466
prebuilt platform bundle's `crawlberg.h` to declare exactly the same C API as the canonical

‎crates/crawlberg/src/map.rs‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,4 +883,37 @@ mod tests {
883883
"the dropped <loc> must be logged by length, got {fields:?}"
884884
);
885885
}
886+
887+
#[test]
888+
#[serial_test::serial(dropped_target_log)]
889+
fn map_redacts_credentials_carried_by_a_credentialed_seed_url_when_logging_an_unparseable_urlset_loc() {
890+
// ~keep `sitemap_urls_from_well_known` builds the well-known sitemap URL from the
891+
// ~keep seed's authority, which carries the seed's userinfo along. That built URL
892+
// ~keep parses, so this exercises `log_unparseable_loc`'s `source_url_parses` branch,
893+
// ~keep the one M10 (log `source_url` unredacted) leaves uncovered.
894+
let runtime = tokio::runtime::Builder::new_current_thread()
895+
.enable_all()
896+
.build()
897+
.expect("a current-thread runtime must build");
898+
let mock = runtime.block_on(MockServer::start());
899+
let base = mock.uri();
900+
let seed_url = base.replacen("http://", "http://user:hunter2@", 1);
901+
let bad_loc = "https://ex ample.com/bad";
902+
let locs = vec![bad_loc.to_owned(), "https://example.com/kept".to_owned()];
903+
runtime.block_on(mount_body(&mock, "/sitemap.xml", "application/xml", urlset(&locs)));
904+
905+
let (result, fields) = capture_events(|| runtime.block_on(map(&seed_url, &local_test_config())));
906+
907+
assert_eq!(
908+
result
909+
.expect("map should succeed")
910+
.urls
911+
.into_iter()
912+
.map(|u| u.url)
913+
.collect::<Vec<_>>(),
914+
vec!["https://example.com/kept".to_owned()],
915+
"a <loc> that does not parse must still be dropped when the seed URL carries credentials"
916+
);
917+
assert_logged_without_secret(&fields, "hunter2", "127.0.0.1");
918+
}
886919
}

‎docs-site/src/content/docs/changelog.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ title: "Changelog"
5858
sitemap-index children and returned in its normalized form. A `<loc>` that does not parse is
5959
dropped. An address is returned once per `map()` call, even when several sitemaps list it, and a
6060
duplicate does not count toward `map_limit`. A relative `<loc>` is now subject to
61-
`exclude_paths`, like every other entry. (#323)
61+
`exclude_paths`, like every other entry. `map_search` now matches the normalized address, so a
62+
search for a raw spelling, such as a default port or non-ASCII text in the path or host, no
63+
longer matches. (#323)
6264

6365
- **The vendored C header gate failed for lag rather than for a defect.** It required each
6466
prebuilt platform bundle's `crawlberg.h` to declare exactly the same C API as the canonical

‎docs-site/src/content/docs/guides/url-discovery.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ The engine handles the full range of sitemap formats:
5858
</urlset>
5959
```
6060

61+
Each `<loc>` is resolved to an absolute, normalized address and deduplicated within the map
62+
operation: two spellings of one page, such as a default port or an upper-case host, count once,
63+
and the same page listed in two sitemaps also counts once.
64+
6165
### Sitemap index files
6266

6367
When a sitemap index is encountered, the engine recursively fetches all referenced child sitemaps:

0 commit comments

Comments
 (0)