Has anyone resolved these CSP errors on a NextJS app?
I run into these errors when I navigate to Internet Identity on my local application.
:4943/?canisterId=rdmx6-jaaaa-aaaaa-aaadq-cai#authorize:1 Refused to load the stylesheet 'https://gilroy-web-fonts.s3.amazonaws.com/web-fonts/gilroy.css' because it violates the following Content Security Policy directive: "style-src-elem 'self' 'unsafe-inline'".
Refused to load the stylesheet 'https://gilroy-web-fonts.s3.amazonaws.com/web-fonts/gilroy.css' because it violates the following Content Security Policy directive: "style-src-elem 'self' 'unsafe-inline'".
Here is my II component on NextJS:
import { AuthClient } from "@dfinity/auth-client";
import { HttpAgent } from "@dfinity/agent";
export default function IIButton() {
async function InternetIdentityLogin() {
let authClient = await AuthClient.create();
await new Promise((resolve) => {
authClient.login({
identityProvider:
process.env.DFX_NETWORK === "ic"
? "https://identity.ic0.app"
: `http://127.0.0.1:4943/?canisterId=rdmx6-jaaaa-aaaaa-aaadq-cai`
});
});
const identity = authClient.getIdentity();
const agent = new HttpAgent({ identity });
}
return (
<div className="w-1/2 mb-4">
<button onClick={async () => await InternetIdentityLogin()} className="btn btn-primary">Login</button>
</div>
);
};
I attempted to update the next.config.js
file to this but to no avail.
const cspHeader = `
default-src 'self' fonts.googleapis.com;
script-src 'self' 'unsafe-eval' 'unsafe-inline';
style-src 'self' fonts.googleapis.com gilroy-web-fonts.s3.amazonaws.com;
style-src-elem 'self' fonts.googleapis.com gilroy-web-fonts.s3.amazonaws.com;
img-src 'self' blob: data:;
font-src 'self';
object-src 'none';
base-uri 'self';
form-action 'self';
frame-ancestors 'none';
block-all-mixed-content;
upgrade-insecure-requests;
`
module.exports = {
async headers() {
return [
{
source: '/(.*)',
headers: [
{
key: 'Content-Security-Policy',
value: cspHeader.replace(/\n/g, ''),
},
],
},
]
},
}
I also tried to create a similar middleware.ts
as suggested in the documentation provided by NextJS.