Repository navigation
fix: filter scheme-less www autolinks in safe outputs - #76708
Conversation
Apply the existing domain allowlist to GFM www autolinks, preserve allowed URL paths and code policy, and keep www redaction markers inert. Resolves githubnext/gh-aw-security#3375 Co-authored-by: Copilot App <[email protected]>
| // GFM links www. tokens after whitespace or emphasis/opening delimiters. | ||
| // Include backticks for allowed-only filtering, and skip existing URLs as a | ||
| // unit so www. text in an allowed URL's path is not mistaken for a new link. | ||
| const wwwUrlRegex = /(\]\(\s*)?((?:https:\/\/|[/\\]{2})[\w.-]+[^\s<>`]*)|(^|[\s*_~(`])(www\.[^\s<>`]+)/gi; |
| core.info("Redacted invalid scheme-less www URL"); | ||
| return prefix + "(redacted)" + suffix; | ||
| } | ||
| return prefix + applyDomainFilter(normalized, parsed.hostname) + suffix; |
There was a problem hiding this comment.
🟡 Changes recommended
Critical mismatches between sanitization and rendered Markdown allow disallowed external links to remain active, bypassing the hostname allowlist.
9 open issues
Normalize backslashes before checking URL userinfo · New Remove all parsed credentials from allowed URLs · New Recognize block, table, and footnote autolink positions · New Validate the full GFM autolink URL authority · New Filter unshielded text after Markdown span boundaries · New Limit protocol-relative URL shielding to link destinations · New Stop www. candidates at table-cell boundaries · New Stop www. matches at adjacent Markdown link boundaries · New Bound explicit-link scanning to avoid quadratic rescans · New
What changed in this PR
Extends gh-aw’s safe-output sanitizer to apply its domain allowlist to scheme-less www. autolinks recognized by GitHub-flavored Markdown.
Changes:
- Adds hostname normalization, userinfo handling, and filtering for
www.URL candidates. - Makes
www.prefixes inert in domain-redaction markers. - Adds 50 regression cases and documents code-region policy behavior.
| File | Description |
|---|---|
docs/src/content/docs/reference/safe-outputs.md |
Documents scheme-less autolink filtering and URL policies. |
actions/setup/js/sanitize_content_www.test.cjs |
Adds regression coverage for filtering, formatting, and publication output. |
actions/setup/js/sanitize_content_core.cjs |
Implements www. candidate scanning and domain-marker neutralization. |
Review effort: Max (auto)
| } | ||
| const url = candidate.slice(0, end); | ||
| const suffix = candidate.slice(end); | ||
| const normalized = stripUrlUserinfo(`https://${url}`).slice("https://".length); |
| core.info("Redacted invalid scheme-less www URL"); | ||
| return prefix + "(redacted)" + suffix; | ||
| } | ||
| return prefix + applyDomainFilter(normalized, parsed.hostname) + suffix; |
| // GFM links www. tokens after whitespace or emphasis/opening delimiters. | ||
| // Include backticks for allowed-only filtering, and skip existing URLs as a | ||
| // unit so www. text in an allowed URL's path is not mistaken for a new link. | ||
| const wwwUrlRegex = /(\]\(\s*)?((?:https:\/\/|[/\\]{2})[\w.-]+[^\s<>`]*)|(^|[\s*_~(`])(www\.[^\s<>`]+)/gi; |
| // GFM links www. tokens after whitespace or emphasis/opening delimiters. | ||
| // Include backticks for allowed-only filtering, and skip existing URLs as a | ||
| // unit so www. text in an allowed URL's path is not mistaken for a new link. | ||
| const wwwUrlRegex = /(\]\(\s*)?((?:https:\/\/|[/\\]{2})[\w.-]+[^\s<>`]*)|(^|[\s*_~(`])(www\.[^\s<>`]+)/gi; |
| // GFM links www. tokens after whitespace or emphasis/opening delimiters. | ||
| // Include backticks for allowed-only filtering, and skip existing URLs as a | ||
| // unit so www. text in an allowed URL's path is not mistaken for a new link. | ||
| const wwwUrlRegex = /(\]\(\s*)?((?:https:\/\/|[/\\]{2})[\w.-]+[^\s<>`]*)|(^|[\s*_~(`])(www\.[^\s<>`]+)/gi; |
| while ((match = wwwUrlRegex.exec(s))) { | ||
| parts.push(s.slice(position, match.index)); | ||
| const [full, destinationPrefix, explicitUrl, prefix, candidate] = match; | ||
| if (explicitUrl !== undefined) { |
| // GFM links www. tokens after whitespace or emphasis/opening delimiters. | ||
| // Include backticks for allowed-only filtering, and skip existing URLs as a | ||
| // unit so www. text in an allowed URL's path is not mistaken for a new link. | ||
| const wwwUrlRegex = /(\]\(\s*)?((?:https:\/\/|[/\\]{2})[\w.-]+[^\s<>`]*)|(^|[\s*_~(`])(www\.[^\s<>`]+)/gi; |
| // GFM links www. tokens after whitespace or emphasis/opening delimiters. | ||
| // Include backticks for allowed-only filtering, and skip existing URLs as a | ||
| // unit so www. text in an allowed URL's path is not mistaken for a new link. | ||
| const wwwUrlRegex = /(\]\(\s*)?((?:https:\/\/|[/\\]{2})[\w.-]+[^\s<>`]*)|(^|[\s*_~(`])(www\.[^\s<>`]+)/gi; |
| parts.push(full.slice(0, end)); | ||
| wwwUrlRegex.lastIndex = match.index + end; |
|
@copilot address all review feedback |
Co-authored-by: lpcox <[email protected]>
Addressed the review feedback in c121f45. The sanitizer now scans forward across Markdown boundaries, validates the complete rendered authority, removes credentials, and avoids logging scheme-less hostnames; targeted regressions and the repository validation gate pass. |
|
🎉 This pull request is included in a new release. Release: |


Summary
www.autolinks through the existing domain allowlist, including normalized hostnames and userinfo handling.www.hostnames inert instead of producing another live autolink; preserve allowed URL paths, adjacent Markdown links, punctuation, and the configured code-region policy.Resolves githubnext/gh-aw-security#3375
Validation
make agent-report-progresspassed (formatting, JavaScript lint/typecheck, build, and impacted tests).