Skip to content

Add default trusted types policy #24455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ const config: Config = {
customFields: {
INSTRUMENTATION_KEY: process.env.INSTRUMENTATION_KEY,
},
scripts: [
{
src: "/trusted-types-policy.js",
async: false,
},
],
};

export default config;
2 changes: 1 addition & 1 deletion docs/static/staticwebapp.config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"globalHeaders": {
"cache-control": "must-revalidate, max-age=3600",
"Content-Security-Policy-Report-Only": "require-trusted-types-for 'script'; trusted-types dompurify ff#webpack; report-uri https://csp.microsoft.com/report/FluidFramework-WW"
"Content-Security-Policy-Report-Only": "require-trusted-types-for 'script'; trusted-types default dompurify ff#webpack; report-uri https://csp.microsoft.com/report/FluidFramework-WW"
},
"navigationFallback": {
"rewrite": "/api/fallback"
Expand Down
21 changes: 21 additions & 0 deletions docs/static/trusted-types-policy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/

if (
typeof window !== "undefined" &&
window.trustedTypes &&
typeof window.trustedTypes.createPolicy === "function"
) {
if (
typeof window.trustedTypes.getPolicy !== "function" ||
!window.trustedTypes.getPolicy("default")
) {
window.trustedTypes.createPolicy("default", {
createHTML: (input) => input,
createScript: (input) => input,
createScriptURL: (input) => input,
});
}
}
Loading