Skip to content

fix: respect tool's sanitize config when building paste sanitizer rules - #3018

Open
waterWang wants to merge 1 commit into
codex-team:nextfrom
waterWang:fix/paste-use-tool-sanitize-config-for-paste-tags
Open

fix: respect tool's sanitize config when building paste sanitizer rules#3018
waterWang wants to merge 1 commit into
codex-team:nextfrom
waterWang:fix/paste-use-tool-sanitize-config-for-paste-tags

Conversation

@waterWang

Copy link
Copy Markdown

Description

Fixes #2984

When pasting HTML content, the editor's paste module builds sanitizer configuration from pasteConfig.tags, but ignored the tool's static sanitize() configuration. This caused style attributes (and other explicitly allowed attributes) to be stripped from paste elements before reaching the tool's onPaste handler.

Root cause

There are two sanitization passes in the paste pipeline:

  1. processDataTransfer (first pass): builds per-tag sanitizer config from pasteConfig.tags only. When tags are specified as plain strings (e.g., [P, 'DIV', 'SPAN']), the sanitizationConfig is null, resulting in {} (all attributes stripped). The tool's sanitize() static rules were never consulted.

  2. processHTML (second pass): same issue — per-tag config was derived from pasteConfig only, and the customConfig used tool.baseSanitizeConfig (inline tools + tunes only) instead of tool.sanitizeConfig (which includes the tool's own rules).

Fix

Both sanitization passes now fall back to the tool's sanitizeConfig for a tag when no explicit pasteConfig sanitization is provided. The second pass also uses tool.sanitizeConfig instead of tool.baseSanitizeConfig.

Test Plan

  • A tool with pasteConfig: { tags: ['P'] } and sanitize: { p: { style: true } } now preserves style attributes on pasted <p> elements.
  • Existing behavior preserved for tools that specify explicit sanitization in pasteConfig.
  • Existing behavior preserved for tags without any sanitize rules (all attributes stripped).

When pasting HTML content, the editor's paste module builds sanitizer
configuration from pasteConfig.tags, but ignored the tool's static
sanitize() configuration. This caused style attributes (and other
allowed attributes) to be stripped from paste elements before reaching
the tool's onPaste handler.

Fix:
1. In processDataTransfer (first sanitization pass): when building the
   per-tag sanitizer config, fall back to the tool's sanitizeConfig
   for that tag if no explicit pasteConfig sanitization is provided.
2. In processHTML (second sanitization pass): same fallback logic, and
   use tool.sanitizeConfig (which includes the tool's own sanitize()
   rules) instead of tool.baseSanitizeConfig (which only includes
   inline tools and tunes config).

Fixes codex-team#2984

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the paste sanitization pipeline so that when a tool declares pasteConfig.tags without an explicit per-tag sanitization object, the paste sanitizer will fall back to the tool’s own sanitize rules instead of stripping all attributes before onPaste runs.

Changes:

  • In the first sanitization pass, fall back to the tool’s sanitize rules for a tag when pasteConfig.tags provides only tag names (no explicit sanitization object).
  • In the second sanitization pass, use the tool’s full sanitizeConfig (not just baseSanitizeConfig) and apply the same per-tag fallback logic.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +214 to +226
const sanitizationConfig = this.toolsTags[tag].sanitizationConfig;

if (sanitizationConfig !== null) {
result[tagLowerCase] = sanitizationConfig;
} else {
const toolSanitizeConfig = this.toolsTags[tag].tool.sanitizeConfig;

if (toolSanitizeConfig?.[tagLowerCase]) {
result[tagLowerCase] = toolSanitizeConfig[tagLowerCase];
} else {
result[tagLowerCase] = {};
}
}
}, {});

const customConfig = Object.assign({}, toolTags, tool.baseSanitizeConfig);
const customConfig = Object.assign({}, toolTags, tool.sanitizeConfig);
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.

pasteConfig ignores tool's sanitize rules - style attributes stripped before onPaste receives element

2 participants