Skip to content

fix(citation): match special-case hosts by domain suffix, not substring - #158

Merged
schiste merged 1 commit into
mainfrom
fix-citation-host-suffix-match
Aug 21, 2026
Merged

fix(citation): match special-case hosts by domain suffix, not substring#158
schiste merged 1 commit into
mainfrom
fix-citation-host-suffix-match

Conversation

@tieguy

@tieguy tieguy commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

is_special_case_host used host.contains("books.google."), so an attacker-controlled host such as books.google.com.evil.example (or xbooks.google.com) was misclassified as the Google Books viewer shell and its body suppressed as unusable.

Now matches on DNS label boundaries: split the host, drop the TLD, require the remaining labels to end with the special-case domain. Subdomains (www.books.google.de) still match.

🤖 Generated with Claude Code

@tieguy
tieguy requested a review from schiste as a code owner July 14, 2026 16:53

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8d9e1760f8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +197 to +202
let Some((_tld, without_tld)) = labels.split_last() else {
return false;
};
SPECIAL_CASE_DOMAINS
.iter()
.any(|needle| host.contains(needle))
.any(|domain| without_tld.ends_with(domain))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve matches for multi-label Google TLDs

Because this drops exactly one label before matching, Google Books country hosts with multi-label public suffixes such as https://books.google.co.uk/... leave without_tld as ['books', 'google', 'co'], which does not end with ['books', 'google']. These hosts were covered by the previous books.google. rule and by the intended books.google.* viewer-shell class, so they now fall through to normal body classification instead of returning ViewerShell.

Useful? React with 👍 / 👎.

@tieguy
tieguy force-pushed the fix-citation-host-suffix-match branch from 8d9e176 to c9ff592 Compare July 16, 2026 19:45
is_special_case_host used a raw substring check (host.contains("books.google.")),
so an attacker-controlled host such as books.google.com.evil.example — or
xbooks.google.com — was misclassified as the Google Books viewer shell and its
body suppressed as unusable. Match on DNS label boundaries instead: split the
host, drop the TLD, and require the remaining labels to end with the special-case
domain labels. Subdomains (www.books.google.de) still match.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@schiste
schiste force-pushed the fix-citation-host-suffix-match branch from c9ff592 to 3d94b48 Compare August 21, 2026 08:12

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d94b48b00

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

};
let host = host.to_ascii_lowercase();
SPECIAL_CASE_HOSTS
let labels: Vec<&str> = host.split('.').collect();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Strip the DNS root label before dropping the TLD

For a valid fully qualified URL such as https://books.google.com./books?id=x, host_str() retains the trailing dot, so splitting produces ['books', 'google', 'com', '']; this code drops the empty root label rather than com, and the suffix check then returns false. The previous substring rule classified this equivalent Google Books host as ViewerShell, so normalize a trailing root label before removing the TLD.

Useful? React with 👍 / 👎.

@schiste
schiste merged commit 8d03bb2 into main Aug 21, 2026
4 checks passed
@schiste
schiste deleted the fix-citation-host-suffix-match branch August 21, 2026 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants