Skip to content

fix: use scoped DOMPurify instance to avoid mutating global#10873

Open
mixelburg wants to merge 1 commit into
swagger-api:masterfrom
mixelburg:fix/scoped-dompurify-instance
Open

fix: use scoped DOMPurify instance to avoid mutating global#10873
mixelburg wants to merge 1 commit into
swagger-api:masterfrom
mixelburg:fix/scoped-dompurify-instance

Conversation

@mixelburg
Copy link
Copy Markdown

Fixes #10871

Swagger UI currently calls DomPurify.addHook() on the global DOMPurify object at module scope. This leaks side effects to any host application sharing the same instance — notably, the beforeSanitizeElements hook overwrites rel on all elements with href, breaking stylesheet <link> elements (see backstage/backstage#34037).

This fix creates a scoped DOMPurify instance via DomPurify(window) so hooks are isolated and the global object is never modified. The SSR case falls back to the original DomPurify object when window is undefined. The sanitizer() export function also uses the scoped instance for consistency.

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.

🐛 Swagger UI mutates the global DOMPurify instance

1 participant