From 77f0b67f24f0329173e1b0f915c486cb59a8a355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Thu, 20 Aug 2026 19:47:20 +0200 Subject: [PATCH 01/16] fix(comark): escape attribute values in HTML serialization Attribute values were interpolated into key="value" with no escaping, so a double quote in any attribute value (raw HTML, component props, fence info strings, image alt text) terminated the attribute early and injected attacker-chosen attributes such as onmouseover handlers into the rendered HTML. This bypassed comark/plugins/security, which sanitizes the AST but cannot prevent quote breakout at serialization. - Escape &, ", < and > in all attribute values emitted by htmlAttributes() - Serialize object values as entity-escaped JSON (backslash escaping is not valid inside HTML attribute values) - Drop attribute names outside the safe HTML name charset - Update SPEC expectations that encoded the broken output --- .../SPEC/COMARK/codeblock-multiple-meta.md | 2 +- .../COMARK/component-block-props-types.md | 2 +- .../SPEC/COMARK/component-yaml-props.md | 2 +- .../src/internal/stringify/attributes.ts | 32 +++++++--- packages/comark/test/html-escape.test.ts | 61 +++++++++++++++++++ 5 files changed, 89 insertions(+), 10 deletions(-) create mode 100644 packages/comark/test/html-escape.test.ts diff --git a/packages/comark/SPEC/COMARK/codeblock-multiple-meta.md b/packages/comark/SPEC/COMARK/codeblock-multiple-meta.md index 4016d5c5..4860adbf 100644 --- a/packages/comark/SPEC/COMARK/codeblock-multiple-meta.md +++ b/packages/comark/SPEC/COMARK/codeblock-multiple-meta.md @@ -35,7 +35,7 @@ def greet(name): ## HTML ```html -
def greet(name):
+
def greet(name):
     return f"Hello, {name}!"
``` diff --git a/packages/comark/SPEC/COMARK/component-block-props-types.md b/packages/comark/SPEC/COMARK/component-block-props-types.md index d445a18c..7345909a 100644 --- a/packages/comark/SPEC/COMARK/component-block-props-types.md +++ b/packages/comark/SPEC/COMARK/component-block-props-types.md @@ -50,7 +50,7 @@ Component content ## HTML ```html -