fix: respect tool's sanitize config when building paste sanitizer rules - #3018
Open
waterWang wants to merge 1 commit into
Open
fix: respect tool's sanitize config when building paste sanitizer rules#3018waterWang wants to merge 1 commit into
waterWang wants to merge 1 commit into
Conversation
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
waterWang
requested review from
TatianaFomina,
gohabereg,
ilyamore88 and
neSpecc
as code owners
August 11, 2026 19:15
There was a problem hiding this comment.
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.tagsprovides only tag names (no explicit sanitization object). - In the second sanitization pass, use the tool’s full
sanitizeConfig(not justbaseSanitizeConfig) 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
processDataTransfer (first pass): builds per-tag sanitizer config from
pasteConfig.tagsonly. When tags are specified as plain strings (e.g.,[P, 'DIV', 'SPAN']), thesanitizationConfigis null, resulting in{}(all attributes stripped). The tool'ssanitize()static rules were never consulted.processHTML (second pass): same issue — per-tag config was derived from
pasteConfigonly, and thecustomConfigusedtool.baseSanitizeConfig(inline tools + tunes only) instead oftool.sanitizeConfig(which includes the tool's own rules).Fix
Both sanitization passes now fall back to the tool's
sanitizeConfigfor a tag when no explicit pasteConfig sanitization is provided. The second pass also usestool.sanitizeConfiginstead oftool.baseSanitizeConfig.Test Plan
pasteConfig: { tags: ['P'] }andsanitize: { p: { style: true } }now preservesstyleattributes on pasted<p>elements.