Skip to content

Handle quote-adjacent attributes in HTML sanitization - #77007

Merged
lpcox merged 4 commits into
mainfrom
copilot/handle-quote-adjacent-attributes
Nov 12, 2026
Merged

lpcox merged 4 commits into
mainfrom
copilot/handle-quote-adjacent-attributes

Conversation

Copilot AI commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Filtered attributes could survive when adjacent to a quoted value, while > inside quoted values could prematurely end tag scanning. Use quote-aware tag and attribute scanning so filtered attributes are removed consistently without matching text inside safe values.

  • Tag boundaries: Respect quoted > characters and use the same scanner for CDATA tags.
  • Attribute filtering: Strip adjacent title, data-*, style, and on* attributes while preserving safe attributes.
  • Malformed markup: Neutralize tags with unbalanced quotes instead of preserving or repairing them.
<img src="safe"title="example">
<!-- sanitized -->
<img src="safe">

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix handling of quote-adjacent attributes in HTML sanitizer Handle quote-adjacent attributes in HTML sanitization Nov 12, 2026
Copilot AI requested a review from lpcox November 12, 2026 01:23
Comment on lines +1348 to +1356
return replaceTagMarkup(s, (tagContent, match, malformed) => {
if (malformed) return `(${tagContent})`;
if (isHttpsAngleBracketAutolink(tagContent)) return match;

const tagNameMatch = tagContent.match(/^\/?\s*([A-Za-z][A-Za-z0-9]*)/);
if (tagNameMatch && allowedTags.includes(tagNameMatch[1].toLowerCase())) {
return `<${stripDangerousAttributes(tagContent)}>`;
}
return `(${tagContent})`; // Convert other tags to parentheses
return `(${tagContent})`;
if (!firstCharacter || !/[A-Za-z!]/.test(firstCharacter)) continue;

const boundary = findTagEnd(source, index);
if (boundary.end < 0) return written ? output + source.slice(written) : source;
@lpcox
lpcox marked this pull request as ready for review November 12, 2026 01:42
Copilot AI dynamic review requested due to automatic review settings November 12, 2026 01:42
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Test Quality Sentinel · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 7.2K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Specification Reviewer completed successfully!

Generated by PR Specification Reviewer for #77007

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Ponytail Reviewer

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Ponytail Reviewer · routed: gpt61 medium · ~4 AIC · ⌖ ~1 AIC · ◇ ~1 AIC · ⊞ 181 · ◷

Generated by Ponytail Reviewer for #77007

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.

Design Decision Gate 🏗️

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Design Decision Gate 🏗️ · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 8.5K · ◷

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer is reviewing this pull request using Matt Pocock's engineering skills...

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions github-actions Bot 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.

Reviewed head 02902f3 against safe-outputs specification v1.29.23, Section 9.2 Transformation T6 (unsafe XML tags MUST be converted to text), and security architecture NI-14/T-NI-009. REQUEST_CHANGES.

Blocking findings are already captured by the existing inline comments at sanitize_content_core.cjs lines 1271 and 1356: (1) when no unquoted tag terminator is found, replaceTagMarkup returns the remaining source unchanged, allowing raw/disallowed markup to bypass sanitization; (2) when a quoted > is treated as the fallback boundary, tagContent can include markup that is then parsed as part of an allowed tag, allowing disallowed tags hidden in quoted values to survive. Fix both paths and add regression tests. No specification update is appropriate: the PR behavior conflicts with existing mandatory sanitization requirements, and this review did not run tests per static-review policy.

Generated by PR Specification Reviewer for #77007 · copilot · gpt50 · ~2 AIC · ⌖ ~2 AIC · ⊞ 1.6K
Comment /review-specs to run again

@lpcox

lpcox commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

@copilot address all review feedback

@github-actions github-actions Bot 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.

Static review completed. I found no additional distinct issues beyond the two existing review comments: the quote-aware scanner can preserve disallowed markup embedded in quoted values, and an unterminated tag boundary can return the remaining suffix unchanged. The specialist pass produced no parseable JSONL findings, so its output was discarded. No tests were run per the static-review instructions.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~4 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again

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

Unresolved critical parsing flaws allow tags and attributes to bypass sanitization, while malformed-quote recovery can cause quadratic processing time.

7 open issues
What changed in this PR

Updates the shared safe-output HTML sanitizer to address #77006: filtering quote-adjacent attributes while preserving safe quoted values.

Changes:

  • Introduces quote-aware tag scanning for ordinary HTML and CDATA.
  • Replaces regex attribute stripping with token scanning and adds malformed-quote handling.
  • Adds exact-output regression cases for direct tag conversion and the full sanitization pipeline.
File Description
actions/​setup/​js/​sanitize_content_core.cjs Implements quote-aware tag boundaries and attribute filtering.
actions/​setup/​js/​sanitize_content_attributes.test.cjs Covers adjacent attributes, quoted > characters, malformed quotes, and CDATA.

Review effort: Max (auto)

return { end: index, malformed: false };
}
}
return quote && firstQuotedGreaterThan >= 0 ? { end: firstQuotedGreaterThan, malformed: true } : { end: -1, malformed: false };
Comment on lines 1236 to 1254
function findTagEnd(source, start) {
let quote = "";
let firstQuotedGreaterThan = -1;
for (let index = start + 1; index < source.length; index++) {
const character = source[index];
if (quote) {
if (character === quote) {
quote = "";
} else if (character === ">" && firstQuotedGreaterThan < 0) {
firstQuotedGreaterThan = index;
}
} else if (character === '"' || character === "'") {
quote = character;
} else if (character === ">") {
return { end: index, malformed: false };
}
}
return quote && firstQuotedGreaterThan >= 0 ? { end: firstQuotedGreaterThan, malformed: true } : { end: -1, malformed: false };
}
const firstCharacter = source[index + 1] === "/" ? source[index + 2] : source[index + 1];
if (!firstCharacter || !/[A-Za-z!]/.test(firstCharacter)) continue;

const boundary = findTagEnd(source, index);
const end = boundary.end + 1;
const match = source.slice(index, end);
const tagContent = source.slice(index + 1, boundary.end);
output += source.slice(written, index) + transform(tagContent, match, boundary.malformed);
attributeEnd = closingQuote < 0 ? tagContent.length : closingQuote + 1;
} else {
attributeEnd = valueStart;
while (attributeEnd < tagContent.length && !/[\s>"'`<]/.test(tagContent[attributeEnd])) {
if (malformed) return `(${tagContent})`;
if (isHttpsAngleBracketAutolink(tagContent)) return match;

const tagNameMatch = tagContent.match(/^\/?\s*([A-Za-z][A-Za-z0-9]*)/);
}
}

if (/^(?:on\w+|style|title|data-[\w-]+)$/i.test(attributeName)) {
Copilot AI and others added 2 commits November 12, 2026 02:18
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>

Copilot AI commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

@copilot address all review feedback

Addressed the sanitizer review findings in commits f7b45509 and 2e05c4b6. Sanitizer tests and the final repository validation gate pass.

const character = source[index];
nextGreaterThan[index] = character === ">" ? index : nextGreaterThan[index + 1];

normal[index] = character === ">" ? index + 1 : character === "=" ? expectValue[index + 1] : normal[index + 1];
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisher skill

@lpcox
lpcox merged commit 1da86bb into main Nov 12, 2026
31 of 32 checks passed
@lpcox
lpcox deleted the copilot/handle-quote-adjacent-attributes branch November 12, 2026 02:45
Copilot stopped work on behalf of pelikhan due to an error November 12, 2026 02:46
Copilot AI requested a review from pelikhan November 12, 2026 02:46
@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.

Handle quote-adjacent attributes consistently in safe-output HTML sanitization

5 participants