πContent-Security-Policy
Add security to you application
Nonce
Trusted Types Policy
Custom policy name
Last updated
Was this helpful?
Was this helpful?
import React from "react";
import ReactDOM from "react-dom/client";
import { App } from "./App";
import { startReactDsfr } from "@codegouvfr/react-dsfr/spa";
const nonce = "123456789"; // you have to inject it on render
startReactDsfr({ defaultColorScheme: "system", nonce });
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
<App />
</React.StrictMode>
);import { DsfrHead } from "@codegouvfr/react-dsfr/next-appdir/DsfrHead";
import { DsfrProvider } from "@codegouvfr/react-dsfr/next-appdir/DsfrProvider";
import { getHtmlAttributes } from "@codegouvfr/react-dsfr/next-appdir/getHtmlAttributes";
import { StartDsfr } from "./StartDsfr";
import { defaultColorScheme } from "./defaultColorScheme";
import Link from "next/link";
import { headers } from "next/headers";
export default function RootLayout({ children }: { children: JSX.Element; }) {
const nonce = headers().get("x-nonce") ?? undefined;
//NOTE: The lang parameter is optional and defaults to "fr"
const lang = "fr";
return (
<html {...getHtmlAttributes({ defaultColorScheme, lang })} >
<head>
<StartDsfr />
<DsfrHead Link={Link} nonce={nonce} />
</head>
<body>
<DsfrProvider lang={lang}>
{children}
</DsfrProvider>
</body>
</html>
);
}"use client";
import { startReactDsfr } from "@codegouvfr/react-dsfr/next-appdir";
import { defaultColorScheme } from "./defaultColorScheme";
import Link from "next/link";
declare module "@codegouvfr/react-dsfr/next-appdir" {
interface RegisterLink {
Link: typeof Link;
}
}
startReactDsfr({ defaultColorScheme, Link, doCheckNonce: true });
export function StartDsfr(){
//Yes, leave null here.
return null;
}import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import { startReactDsfr } from "@codegouvfr/react-dsfr/spa";
const nonce = "123456789" // have to be dynamic and injected
startReactDsfr({ defaultColorScheme: "system", nonce });
const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement
);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);Content-Security-Policy:
require-trusted-types-for 'script';
trusted-types react-dsfr react-dsfr-asap;