Skip to content

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

Open
tieguy wants to merge 1 commit into
mainfrom
fix-citation-host-suffix-match
Open

fix(citation): match special-case hosts by domain suffix, not substring#158
tieguy wants to merge 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 👍 / 👎.

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>
@tieguy
tieguy force-pushed the fix-citation-host-suffix-match branch from 8d9e176 to c9ff592 Compare July 16, 2026 19:45
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.

1 participant