Repository navigation
Description
Description
Content Translation returns the translated content through wp_kses_post() (includes/Abilities/Content_Translation/Content_Translation.php, line 157). The system instruction asks the model to copy every HTML token byte for byte, but wp_kses_post() then changes markup that the editor wrote:
- Text color. When a text color is picked with no background, the block editor's Highlight format writes
<mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">(format-library.js, "transparentValue").safecss_filter_attr()does not allowrgb()orrgba(), so the style attribute is removed. A<mark>with no background shows the browser's yellow highlight, so the translated text gets a yellow background it did not have. - Links with other schemes. A link such as
skype:gardener?callloses its scheme, becauseskypeis not in the allowed protocols, and becomes the relative URLgardener?call.
Both survive in the original post for users with unfiltered_html. Only the translation changes them.
Expected: the translated markup keeps the formatting and links of the original.
Changing what this sanitizes affects HTML safety, so I would like your direction before opening a PR. Some options:
- Keep
wp_kses_post(), allowrgb()andrgba()while it runs (a scopedsafecss_filter_attr_allow_cssfilter), and allow the URL schemes already used in the content that was sent. - Compare the output with the input and only keep tags and attributes that were in the input.
- Leave it as is and document it.
Step-by-step reproduction instructions
- Enable the Content Translation experiment under Settings > AI, with a connected AI provider.
- In a paragraph, select a few words and set a text color with the Highlight option (Text tab), without a background color.
- Add a link to
skype:gardener?callin the same paragraph. - Use Generate Translation, choose a language under "Translate to" and click Translate.
- On the front end, the translated words have a yellow background, and the link points to
gardener?callon the site.
Screenshots, screen recording, code snippet
On develop (93eefdf) in wp-env, WordPress 7.1.4, Twenty Twenty-Five. POST /wp-abilities/v1/abilities/ai/content-translation/run (target es-es), with the OpenAI provider mocked through pre_http_request (the same way the plugin's e2e tests do) to return the markup it was sent, unchanged:
sent: Our garden has <mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">red tomatoes</mark> this week. Call <a href="skype:gardener?call">the gardener</a> or <a href="https://example.org/seeds">order seeds</a>.
returned: Our garden has <mark class="has-inline-color has-vivid-red-color">red tomatoes</mark> this week. Call <a href="gardener?call">the gardener</a> or <a href="https://example.org/seeds">order seeds</a>.
Both versions on one page, read with getComputedStyle() in Chrome 152:
before: mark background rgba(0, 0, 0, 0), color rgb(207, 46, 46); link skype:gardener?call
after: mark background rgb(255, 255, 0), color rgb(207, 46, 46); link http://localhost:8888/translation-proof/gardener?call
Environment info
- WordPress 7.1.4, PHP 8.3, MariaDB 12.3.3 (wp-env)
- AI plugin
developat 93eefdf - Theme: Twenty Twenty-Five
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except the AI plugin.
Yes. Only the AI plugin, the provider plugins it loads in wp-env, and a small test plugin that mocks the provider were active.
Please confirm which theme type you used for testing.
Block
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTriage
Activity
dkotter commentedon Nov 3, 2026
I'd personally be okay with option 3 here as I think there's already precedent (in other experiments) that not all formatting survives and it's up to the user to either add that back or not trigger functionality on that text.
That said, if there's an easy way to prevent this, I'm fine with moving forward with that, which I think is the first part of option 1 (which looks like you have #1269 opened to fix that). I'm not concerned with the URL schemes thing, unless this is something we get multiple reports on.
I would be interested in knowing if there's a particular reason why RGB attributes are allowed but
wp_kses_poststrips those, to make sure we're not introducing a security hole here by allowing those back in.ekamran commentedon Nov 3, 2026
I could not find a security reason specific to
rgb()orrgba(). Since r11689,safecss_filter_attr()rejects any value that contains(unless the function is on an allowlist. The main concern raised on #24157, open since 2013, was old IE's CSSexpression(), and nacin noted there "We may be able to work around rgb(a), at the very least." Core has since allowedurl()with a protocol check, gradients (includingrgb()inside them),var(),calc()and others, but not plain color functions.The same change is already moving upstream. Gutenberg merged #84213 on 30 October (Gutenberg 24.4), which allows
rgb(),rgba()and the other color functions through asafecss_filter_attr_allow_cssfilter. The Core backport is #66387, on the 7.3 milestone. #56391 is the older ticket for this exact case, thebackground-color:rgba(0, 0, 0, 0)that the Highlight format writes.#1269 is narrower than both. It only accepts
rgb()orrgba()whose contents are numbers,.,%, spaces, commas or/. The rest of the value still has to pass Core's own check, Core only runs this filter for properties on its allowlist, and the filter is only added while the translated content goes throughwp_kses_post().If #66387 lands in 7.3, the filter can be removed once 7.3 is the minimum supported version.