mirror of
https://github.com/internetarchive/heritrix3.git
synced 2026-11-26 15:46:58 +00:00
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.
This commit is contained in:
1 parent
c2341ba9e2
commit
2e80500747
2 files changed
+33
-3
No files matched your search
@@ -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<String> echoes) {
|
||||
return Hashing.murmur3_128().hashString(normalize(content, echoes), UTF_8).asLong();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 = "<html><head><link rel=\"stylesheet\" href=\"assets/css/styles.css\">"
|
||||
+ "</head><body><div id=\"root\"></div></body></html>";
|
||||
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: <a href="/login/?returnUri=https%3A%2F%2Fwww.meetup.com%2F...">
|
||||
|
||||
Reference in new issue
Block a user