Treat a redirected host as the same site - #227
Merged
Merged
Conversation
Extracts src/utils/markdown-query.ts into src/utils/mdq/ as a publish-ready package: MarkdownDoc + Selection, insert/remove verbs alongside query, a comment selector, frontmatter handling, JS-value matchers, and a planned jq-like CLI. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FhJNfxLquFknSLJ6V8J9iD
Frontmatter uses yaml's Document API (comment-preserving) rather than a hand-rolled parser; MarkdownDoc gains append/prepend; leading '.' is accepted in the CLI grammar; documents a fourth migration breakage class where MarkdownDoc === string silently stops a guard from firing. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FhJNfxLquFknSLJ6V8J9iD
11 tasks, 68 steps. Ordering keeps the repo green at every boundary: port behind a shim first, migrate the 11 write-return-type breaks second, then add features additively. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FhJNfxLquFknSLJ6V8J9iD
A site registered by its bare domain that redirects to another host under it — most commonly `www.` — failed every navigation. The origin guard compared the landed origin to the configured one exactly and rejected the page before the paths were ever compared, so the log read `URL verification failed: expected /, got /`: both sides print the path, and the paths did match. Hosts now count as the same site when one is the other or a subdomain of it. The port stays significant, the scheme does not, and a sibling subdomain is still a different site. The same comparison guarded network-call and XHR capture, so every request from the redirected host was silently dropped; all three call sites now share `isSameHostFamily()`. A genuine cross-origin drift also names the full URL it reached instead of the bare path. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Exploring a site registered by its bare domain fails on the first navigation when the site redirects to another host under it.
https://olx.ua301s tohttps://www.olx.ua/, and every verification then reported:Both sides print the path, and the paths did match. The rejection came from the origin guard that runs before the path comparison:
Confirmed in a real browser: base
https://olx.ua, landedhttps://www.olx.ua/, strict origin equalityfalse.What changed
isSameHostFamily()insrc/utils/url-matcher.ts— two URLs belong to the same site when the hosts are equal or one is a subdomain of the other. The port stays significant (localhost:3000≠localhost:3001); the scheme does not, so anhttp://config that redirects tohttps://also survives. It encodes the DNS convention rather than any one site's shape.The same strict check was duplicated at three call sites, all now using the helper:
src/ai/navigator.tsorigin === originsrc/action.tsurl.origin !== baseOriginsrc/api/xhr-capture.tsurl.startsWith(baseOrigin)https://olx.ua.evil.testThe mismatch branch now logs the full URL reached instead of the path, so a real cross-origin drift reads
expected /, got https://auth.example.com/rather than/vs/.Config-level origin checks (
validateSiteConfig,siteFolderName, site lookup) are untouched — those decide whichsites/directory a run belongs to and stay exact.Deliberate boundary
app.example.comvsauth.example.comis still rejected: neither is a subdomain of the other. Treating everything under one registrable domain as the same site would need a public-suffix list, which this does not add.Verification
bun test tests/unit— 1444 pass, 0 failbun test tests/integration— 148 pass, 1 skip, 0 failurl-matcher.test.ts(www both directions, subdomain, scheme, sibling subdomains, suffix without a dot boundary, ports) and a www regression test innavigator-origin-guard.test.tsTwo existing navigator assertions changed, since the failure message now names the full URL.
🤖 Generated with Claude Code