Skip to content

fix: filter scheme-less www autolinks in safe outputs - #76708

Merged
lpcox merged 2 commits into
mainfrom
lpcox-safe-output-www-autolinks
Nov 11, 2026
Merged

lpcox merged 2 commits into
mainfrom
lpcox-safe-output-www-autolinks

Conversation

@lpcox

@lpcox lpcox commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Route scheme-less GFM www. autolinks through the existing domain allowlist, including normalized hostnames and userinfo handling.
  • Keep redacted www. hostnames inert instead of producing another live autolink; preserve allowed URL paths, adjacent Markdown links, punctuation, and the configured code-region policy.
  • Add 50 focused regression cases and document the scheme-less autolink coverage.

Resolves githubnext/gh-aw-security#3375

Validation

  • make agent-report-progress passed (formatting, JavaScript lint/typecheck, build, and impacted tests).
  • Five directly related sanitizer/publication suites passed: 710 tests.
  • Verified synthetic before/after inputs through GitHub's actual GFM Markdown rendering API, including report-rendered publication output, adjacent links, emphasis, allowed domains, and balanced URL paths. The original input renders a disallowed link; sanitized output does not.
  • No Go or workflow sources changed; the repository gate skipped Go test bodies and workflow recompilation accordingly.

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]>
Copilot AI adaptive review requested due to automatic review settings November 11, 2026 01:21
// 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;

Copilot AI left a comment

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.

🟡 Changes recommended

Critical mismatches between sanitization and rendered Markdown allow disallowed external links to remain active, bypassing the hostname allowlist.

9 open issues
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;
Comment on lines +606 to +607
parts.push(full.slice(0, end));
wwwUrlRegex.lastIndex = match.index + end;
@lpcox

lpcox commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

@copilot address all review feedback

Copilot AI commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

@copilot address all review feedback

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.

@lpcox
lpcox merged commit 6b918e0 into main Nov 11, 2026
32 checks passed
@lpcox
lpcox deleted the lpcox-safe-output-www-autolinks branch November 11, 2026 02:11
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v1.2.3

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.

4 participants