Skip to content

Commit

Permalink
fet-1490: basic CSP
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Lysak committed Aug 11, 2024
1 parent 20cc129 commit cbc5c21
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"react-confetti": "6.0.1",
"react-dev-utils": "^12.0.1",
"react-dom": "^18.2.0",
"react-helmet": "^6.1.0",
"react-refresh": "^0.11.0",
"react-router-dom": "5.3.0",
"react-use": "17.3.1",
Expand Down
2 changes: 2 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Home from "./pages/Home";
import { useGetDelegates, useQueryString } from "./utils/hooks";
import { initWeb3Read, rpcUrl } from "./web3modal";
import { usePrevious } from "react-use";
import { Csp } from "./csp";

const PROJECT_ID = "02f438d1701ea8029113972850066224";

Expand Down Expand Up @@ -164,6 +165,7 @@ function App() {

return (
<>
<Csp />
<Header />
<AppContainerOuter>
<AppContainerMid>
Expand Down
24 changes: 24 additions & 0 deletions src/csp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Helmet } from "react-helmet";

const resources = [
"https://*.googletagmanager.com",
"plausible.io",
"static.cloudflareinsights.com",
"*.ens-app-v3.pages.dev",
"https://app.intercom.io",
"https://widget.intercom.io",
"https://js.intercomcdn.com",
].join(" ");

const content =
process.env.NODE_ENV === "production"
? `worker-src 'self'; script-src 'self' 'sha256-UyYcl+sKCF/ROFZPHBlozJrndwfNiC5KT5ZZfup/pPc=' ${resources} 'wasm-unsafe-eval';`
: "script-src 'self'";

export function Csp() {
return (
<Helmet>
<meta httpEquiv="Content-Security-Policy" content={content} />
</Helmet>
);
}

0 comments on commit cbc5c21

Please sign in to comment.