From 2e80500747783d4b19cccfa9e6a2f2e4806f66bb Mon Sep 17 00:00:00 2001 From: Alex Osborne Date: Tue, 24 Nov 2026 13:02:26 +0900 Subject: [PATCH] Soft404Detector: match pages reached by their own relative links An app shell served for every path links to e.g. assets/css/app.css. Fetched at /assets/css/app.css, that link looked like an echo of the page's own URL and was removed before fingerprinting, so the page no longer matched the probe, which got the same shell with the link intact. That missed the first level of a relative-link trap. Also compare the content without echoes removed. --- .../modules/processor/Soft404Detector.java | 20 ++++++++++++++++--- .../processor/Soft404DetectorTest.java | 16 +++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/modules/src/main/java/org/archive/modules/processor/Soft404Detector.java b/modules/src/main/java/org/archive/modules/processor/Soft404Detector.java index c89b1a4e..fb0913f0 100644 --- a/modules/src/main/java/org/archive/modules/processor/Soft404Detector.java +++ b/modules/src/main/java/org/archive/modules/processor/Soft404Detector.java @@ -166,7 +166,7 @@ public class Soft404Detector extends Processor { scheduleProbe(curi, server); return ProcessResult.PROCEED; } - if (isExempt(curi) || curi.getFetchStatus() != 200 || fingerprint(curi) != fingerprint) { + if (isExempt(curi) || curi.getFetchStatus() != 200 || !matches(curi, fingerprint)) { return ProcessResult.PROCEED; } curi.getAnnotations().add(ANNOTATION); @@ -240,8 +240,22 @@ public class Soft404Detector extends Processor { } static long fingerprint(CrawlURI curi) { - String normalized = normalize(readContent(curi), echoesOf(curi.getUURI())); - return Hashing.murmur3_128().hashString(normalized, UTF_8).asLong(); + return fingerprint(readContent(curi), echoesOf(curi.getUURI())); + } + + /** + * Whether the content matches the given probe fingerprint, either with its echoes of its own + * URL removed or as is. The latter catches a page reached by a relative link on a copy of + * itself, where the "echo" is part of the page and so also in the probe's content. + */ + static boolean matches(CrawlURI curi, long fingerprint) { + String content = readContent(curi); + return fingerprint(content, echoesOf(curi.getUURI())) == fingerprint + || fingerprint(content, List.of()) == fingerprint; + } + + private static long fingerprint(String content, List echoes) { + return Hashing.murmur3_128().hashString(normalize(content, echoes), UTF_8).asLong(); } /** diff --git a/modules/src/test/java/org/archive/modules/processor/Soft404DetectorTest.java b/modules/src/test/java/org/archive/modules/processor/Soft404DetectorTest.java index f2e00d40..751ce2e1 100644 --- a/modules/src/test/java/org/archive/modules/processor/Soft404DetectorTest.java +++ b/modules/src/test/java/org/archive/modules/processor/Soft404DetectorTest.java @@ -257,6 +257,22 @@ class Soft404DetectorTest { assertTrue(page.getAnnotations().contains(Soft404Detector.ANNOTATION)); } + @Test + void detectsSoft404ReachedByItsOwnRelativeLink() throws Exception { + // an app shell served for every path, fetched at one of its own relative links + String shell = "" + + "
"; + CrawlURI probe = probe(); + recordResponse(probe, shell); + detector.process(probe); + + CrawlURI page = curi("https://example.com/assets/css/styles.css", 200); + recordResponse(page, shell); + detector.process(page); + + assertTrue(page.getAnnotations().contains(Soft404Detector.ANNOTATION)); + } + @Test void detectsSoft404EchoingPercentEncodedUrl() throws Exception { // e.g. www.meetup.com: