Skip to content

[system] Serialize InitColorSchemeScript configuration values - #49091

Draft
Janpot wants to merge 1 commit into
mui:masterfrom
Janpot:harden-init-color-scheme-script
Draft

[system] Serialize InitColorSchemeScript configuration values#49091
Janpot wants to merge 1 commit into
mui:masterfrom
Janpot:harden-init-color-scheme-script

Conversation

@Janpot

@Janpot Janpot commented Sep 4, 2026

Copy link
Copy Markdown
Member

buildInitColorSchemeScript interpolated its string configuration (storage keys, default mode/scheme names, attribute, and colorSchemeNode) directly into the inline SSR script. This treats every value as data instead: strings are serialized with JSON.stringify and </line-separator-escaped before embedding, colorSchemeNode is parsed into a document property-path or document.querySelector() form rather than evaluated as raw source, and attribute is constrained to the documented class / data-* forms.

No change for apps using the static defaults or any documented value. The only behavioral narrowing is that an undocumented raw-expression colorSchemeNode now falls back to document.documentElement.

buildInitColorSchemeScript embedded its string props (storage keys,
default mode/scheme names, attribute, and colorSchemeNode) straight into
the inline SSR script. An app that derives any of these from
tenant-controlled config could break out of the string or the <script>
element, so serialize every value with JSON.stringify (escaping <,
U+2028, U+2029) before embedding it.

Also constrain the two props that can carry executable payloads:
colorSchemeNode is parsed as a document property path or
document.querySelector() string rather than evaluated as raw source, and
attribute is restricted to the documented class/data forms so an
event-handler name like onclick can't be generated.
@code-infra-dashboard

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-49091--material-ui.netlify.app/
QR code for https://deploy-preview-49091--material-ui.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/material 🔺+735B(+0.14%) 🔺+303B(+0.20%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 🔺+724B(+1.05%) 🔺+305B(+1.24%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

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.

1 participant