Skip to content

Commit

Permalink
fix: add UNSAFE_INLINE to Dev CSP - script-src (#2)
Browse files Browse the repository at this point in the history
* fix: add `UNSAFE_INLINE` to Dev CSP

* chore: update `.prettierignore`
  • Loading branch information
atilafassina authored Oct 5, 2024
1 parent 482a45f commit 4acf88e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.all-contributorsrc
.husky/
coverage/
lib/
dist/
pnpm-lock.yaml
6 changes: 3 additions & 3 deletions src/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SELF, UNSAFE_EVAL, UNSAFE_INLINE } from "csp-header";
import { NONE, SELF, UNSAFE_EVAL, UNSAFE_INLINE } from "csp-header";
import { CSP, type HeaderNames } from "./types.js";

export const PROD_DEFAULT_CSP: CSP["value"] = {
Expand All @@ -15,12 +15,12 @@ export const PROD_DEFAULT_CSP: CSP["value"] = {
export const DEV_DEFAULT_CSP: CSP["value"] = {
"default-src": [SELF],
"frame-src": [SELF],
"script-src": [SELF, UNSAFE_EVAL],
"script-src": [SELF, UNSAFE_EVAL, UNSAFE_INLINE],
"style-src": [SELF],
"style-src-elem": [SELF, UNSAFE_INLINE],
"connect-src": [SELF, "ws://localhost:*"],
"img-src": [SELF],
"object-src": [],
"object-src": [NONE],
};

export const HEADER_NAMES: HeaderNames = {
Expand Down
24 changes: 11 additions & 13 deletions src/lib/permissions-policy.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
interface HardwarePermissions {
camera?: string;
microphone?: string;
geolocation?: string;
payment?: string;
camera?: string;
microphone?: string;
geolocation?: string;
payment?: string;
}

export function permissionsPolicy(perms: HardwarePermissions) {
const headerValue: string[] = [];
const headerValue: string[] = [];

for (const [key, value] of Object.entries(perms)) {
if (typeof value === "string") {
headerValue.push(`${key}=${value}`);
}
}
for (const [key, value] of Object.entries(perms)) {
if (typeof value === "string") {
headerValue.push(`${key}=${value}`);
}
}

// headerValue = ["camera=()", "microphone=()"]
return headerValue.join(", ");
// "camera=(), microfone=()"
return headerValue.join(", ");
}

0 comments on commit 4acf88e

Please sign in to comment.