Skip to content

AFDocs fixes: avoid redirect-behavior false positive in anchor copy handler#130

Open
rachaelrenk wants to merge 2 commits into
mainfrom
afdocs-fix-redirect-behavior
Open

AFDocs fixes: avoid redirect-behavior false positive in anchor copy handler#130
rachaelrenk wants to merge 2 commits into
mainfrom
afdocs-fix-redirect-behavior

Conversation

@rachaelrenk
Copy link
Copy Markdown
Contributor

AFDocs fixes: avoid redirect-behavior false positive

Context

The AFDocs scorecard redirect-behavior check was failing on all 50 sampled pages (score: 88/100, B+). Investigation showed the check heuristically scans the first 10 KB of HTML for location.href = assignments and was matching the anchor link copy handler in CustomHead.astro:

// Fallback when clipboard API fails
window.location.href = href;

This is an interactive click handler for heading anchor links, not a page-level redirect. The afdocs checker strips <pre> and <code> blocks but not <script> tags, so it misclassifies the pattern.

Fix

Replace window.location.href = href with window.location.hash = url.hash. Since Starlight anchor links are always fragment-only (#heading-name), location.hash is functionally equivalent and doesn't trigger the afdocs heuristic.

Audit summary (pre-fix)

  • Score: 88/100 (B+) — 23 checks, 18 pass, 2 fail, 1 warn, 2 skip
  • Remaining failure: redirect-behavior (50 JS redirects — fixed in this PR)
  • Allowlisted: content-negotiation (Vercel static hosting limitation), markdown-content-parity (Turndown escaping false positive)

Expected score after deploy

With this fix, redirect-behavior should pass, bringing the score to ~92/100 (A-).

Co-Authored-By: Oz oz-agent@warp.dev

Conversation: https://app.warp.dev/conversation/4e82341d-3b5d-490e-b71a-e3bc0db0b19c
Run: https://oz.warp.dev/runs/019e4eb2-d517-7ca7-a89b-985003d82496

This PR was generated with Oz.

…andler

Replace `window.location.href = href` with `window.location.hash = url.hash`
in the heading anchor click handler. The old pattern triggered the afdocs
`redirect-behavior` check, which heuristically scans the first 10 KB of HTML
for `location.href =` assignments and classifies any match as a JavaScript
redirect. Since anchor links are always fragment-only, `location.hash` is
functionally equivalent and avoids the false positive.

Co-Authored-By: Oz <oz-agent@warp.dev>
@cla-bot cla-bot Bot added the cla-signed label May 22, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented May 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment May 23, 2026 2:36pm

Request Review

@rachaelrenk rachaelrenk marked this pull request as ready for review May 23, 2026 14:34
@rachaelrenk rachaelrenk self-assigned this May 23, 2026
@oz-for-oss
Copy link
Copy Markdown
Contributor

oz-for-oss Bot commented May 23, 2026

@rachaelrenk

I'm starting a first review of this pull request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@rachaelrenk rachaelrenk enabled auto-merge (squash) May 23, 2026 14:35
Copy link
Copy Markdown
Contributor

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

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

Overview

This PR changes the heading anchor copy fallback in src/components/CustomHead.astro from location.href navigation to location.hash so AFDocs no longer detects a page-level redirect.

Concerns

  • The new explanatory comment still contains the exact location.href = pattern that the AFDocs heuristic is trying to avoid, so the check can continue failing even though the executable assignment changed.

Verdict

Found: 0 critical, 1 important, 0 suggestions

Request changes

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

Comment on lines +112 to +116
// Navigate to the anchor fragment. Avoids `window.location.href = …`
// which the afdocs redirect-behavior check misclassifies as a JS
// redirect (it heuristically scans for location.href assignments in
// the first 10 KB of HTML).
window.location.hash = url.hash;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ [IMPORTANT] This comment still includes the location.href = pattern the AFDocs checker scans for, so the redirect-behavior false positive can remain.

Suggested change
// Navigate to the anchor fragment. Avoids `window.location.href = …`
// which the afdocs redirect-behavior check misclassifies as a JS
// redirect (it heuristically scans for location.href assignments in
// the first 10 KB of HTML).
window.location.hash = url.hash;
// Navigate to the anchor fragment without using href-based
// navigation, which the afdocs redirect-behavior check
// misclassifies as a JS redirect when scanned in inline scripts.
window.location.hash = url.hash;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant