Skip to content

Commit

Permalink
Merge pull request #79 from jzakotnik/78-security-config
Browse files Browse the repository at this point in the history
security config
  • Loading branch information
jzakotnik authored Mar 26, 2024
2 parents 085a10b + 0af4ccd commit c45df2c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .env_example
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ COVERIMAGE_FILESTORAGE_PATH=/somepath
# Login Session Timeout for inactivity in seconds (e.g. 500)
LOGIN_SESSION_TIMEOUT=seconds

# Configure if content security policy is set on the http headers, if you don't want CSR header, use "insecure"
SECURITY_HEADERS=secure


# School name
SCHOOL_NAME="Mustermann Schule"
LOGO_LABEL="schullogo.jpg"
USERID_LABEL=userlabeltemplate.jpg
EXTENSION_DURATION_DAYS=22
NUMBER_BOOKS_OVERVIEW=100
14 changes: 8 additions & 6 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ export default withAuth(
`;

const requestHeaders = new Headers(req.headers);
requestHeaders.set("x-nonce", nonce);
requestHeaders.set(
"Content-Security-Policy",
// Replace newline characters and spaces
cspHeader.replace(/\s{2,}/g, " ").trim()
);
if (process.env.SECURITY_HEADERS != "insecure") {
requestHeaders.set("x-nonce", nonce);
requestHeaders.set(
"Content-Security-Policy",
// Replace newline characters and spaces
cspHeader.replace(/\s{2,}/g, " ").trim()
);
}
if (req.nextUrl.pathname == "/admin") {
////console.log("Admin page fetched");

Expand Down

0 comments on commit c45df2c

Please sign in to comment.