Skip to content

Commit

Permalink
Fix Content-Security-Policy (#1532)
Browse files Browse the repository at this point in the history
* Add test for CDN in use by Swagger UI

Signed-off-by: Marvin A. Ruder <[email protected]>
  • Loading branch information
marvinruder authored Aug 28, 2024
1 parent ef08833 commit 4432267
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/backend/src/server.live.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ tests.push({
testName: "provides Swagger UI",
testFunction: async () => {
const res = await app.request("/api-docs");
const body = await res.text();
expect(res.status).toBe(200);
expect(res.headers.get("content-type")).toMatch("text/html");
expect(body).toContain("https://cdn.jsdelivr.net/npm/swagger-ui-dist/");
},
});
6 changes: 3 additions & 3 deletions packages/backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ app.use("/api-docs", async (c, next) => {
"Content-Security-Policy",
csp
.replace("img-src ", "img-src blob: ")
.replace("script-src ", "script-src https://unpkg.com/swagger-ui-dist/ 'unsafe-inline' ")
.replace("style-src ", "style-src https://unpkg.com/swagger-ui-dist/ ")
.replace("style-src-elem ", "style-src-elem https://unpkg.com/swagger-ui-dist/ "),
.replace("script-src ", "script-src https://cdn.jsdelivr.net/npm/swagger-ui-dist/ 'unsafe-inline' ")
.replace("style-src ", "style-src https://cdn.jsdelivr.net/npm/swagger-ui-dist/ ")
.replace("style-src-elem ", "style-src-elem https://cdn.jsdelivr.net/npm/swagger-ui-dist/ "),
);
c.res.headers.set("Cross-Origin-Embedder-Policy", "unsafe-none");
c.res.headers.set("Cross-Origin-Resource-Policy", "cross-origin");
Expand Down

0 comments on commit 4432267

Please sign in to comment.