feat(web): add ALLOW_INLINE_STYLES env var to opt-in inline CSS in Markdown rendering#34719
Conversation
578c09f to
d1f4e71
Compare
|
Hello, @s-kawamura-upgrade. The PR looks fine to me functionally, but CI is still failing on It’s likely worth checking the Web style/lint output first before merging. From the current diff, the most likely candidates are:
Also, this branch is currently out of date with |
8308da5 to
5ea248b
Compare
|
Thanks for the review, @WTW0313. I addressed both points:
The latest head now includes these fixes, and CI has been retriggered by the push. |
…rkdown rendering Add a deployment-level environment variable `ALLOW_INLINE_STYLES` (default: `false`) that allows self-hosted operators to opt-in to inline style attributes in Markdown rendering. This restores styled Jinja2 template support broken by the streamdown migration in v1.13.1 (langgenius#32971), following the same pattern as `ALLOW_UNSAFE_DATA_SCHEME`. When enabled, `style` is appended to the global attribute allowlist in `rehype-sanitize`, so all HTML elements may carry inline styles. Closes langgenius#34377 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5ea248b to
90ada72
Compare
|
Sorry for the extra update — after posting my previous comment, GitHub still showed "This branch is out-of-date with the base branch," so I rebased again onto the latest The branch should now be up to date. |
…rkdown rendering (langgenius#34719) Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Important
NEXT_PUBLIC_ALLOW_INLINE_STYLESenv var to opt-in inline CSS in Markdown rendering #34377) and discussion with maintainer (@WTW0313)NEXT_PUBLIC_ALLOW_INLINE_STYLESenv var to opt-in inline CSS in Markdown rendering #34377Summary
Add a deployment-level environment variable
ALLOW_INLINE_STYLES(default:false) that allows self-hosted operators to opt-in to inlinestyleattributes in Markdown rendering.The v1.13.1 streamdown migration (#32971) introduced
rehype-sanitizewith a whitelist-based schema that strips allstyleattributes. This broke existing production workflows using Jinja2 templates with styled HTML in Answer nodes.This PR follows the simplified implementation approach suggested by @WTW0313:
ALLOW_INLINE_STYLESis read directly from@/configinstreamdown-wrapper.tsxALLOW_UNSAFE_DATA_SCHEME— env schema, config export, entrypoint mapping, docker-compose wiringfalse) — self-hosted opt-in onlyentrypoint.sh,docker-compose.yaml,docker-compose-template.yaml,.env.exampleFiles changed (8 files, +25 lines)
web/env.tsexperimental__runtimeEnvmappingweb/config/index.tsALLOW_INLINE_STYLESweb/app/components/base/markdown/streamdown-wrapper.tsx'style'to sanitize schemaweb/docker/entrypoint.shALLOW_INLINE_STYLES→NEXT_PUBLIC_ALLOW_INLINE_STYLESdocker/docker-compose.yamlx-shared-envandwebservicedocker/docker-compose-template.yamlwebservicedocker/.env.exampleweb/.env.exampleCore change (
streamdown-wrapper.tsx)Tradeoff
false)url()for resource loading, which cannot execute JavaScriptScreenshots
Before (
ALLOW_INLINE_STYLES=false, default)All
styleattributes stripped — layout completely broken, rendered as plain text:After (
ALLOW_INLINE_STYLES=true)All
styleattributes preserved — card layout renders correctly:Verification
Tested on Dify 1.13.3 with Docker Compose (self-hosted):
ALLOW_INLINE_STYLES=false→ styles stripped ✅ALLOW_INLINE_STYLES=truein.env→docker compose restart→ styles preserved ✅Checklist
cd web && npx lint-staged(frontend) to appease the lint gods