Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(security): add security headers #1786

Merged
merged 7 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tavla/app/components/PreviewCarousel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function PreviewCarousel({ boards }: { boards: TBoard[] }) {
data-theme={currentBoard.theme ?? 'dark'}
>
<div
style={{ display: 'flex' }}
className="flex"
aria-label="Eksempel på avgangstavler"
>
<div
Expand Down
81 changes: 80 additions & 1 deletion tavla/next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,37 @@
const { PHASE_DEVELOPMENT_SERVER } = require('next/constants')
const { withSentryConfig } = require("@sentry/nextjs");

const commonConnectSrc = [
"'self'",
"https://api.entur.io",
"https://tavla-api.entur.no",
"https://tavla-api.dev.entur.no"
]

if (process.env.NODE_ENV == 'development') {
commonConnectSrc.push("http://*.identitytoolkit.googleapis.com http://127.0.0.1:9099 ws://localhost:3000 http://127.0.0.1:3001")
}

const cspHeaderCommon = `
default-src 'self';
style-src 'self' 'unsafe-inline';
script-src 'self' 'unsafe-inline' 'unsafe-eval';
object-src 'none';
base-uri 'self';
form-action 'self';
`

const cspHeader = `
connect-src ${commonConnectSrc.join(' ')} https://ws.geonorge.no https://*.posthog.com https://*.googleapis.com https://www.google.com;
frame-ancestors 'none';
purusott marked this conversation as resolved.
Show resolved Hide resolved
${cspHeaderCommon}
`

const cspHeaderTavlevisning = `
connect-src ${commonConnectSrc.join(' ')};
${cspHeaderCommon}
`

/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'standalone',
Expand All @@ -21,11 +52,59 @@ const nextConfig = {
},
],
dangerouslyAllowSVG: true,
contentDispositionType: 'attachment',
contentDispositionType: 'attachment',
contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
},
async headers() {
return [
{
source: '/(.*)?',
headers: [
{
key: 'Strict-Transport-Security',
value: 'max-age=63072000; includeSubDomains; preload'
},
{
key: 'Content-Security-Policy',
value: cspHeader.replace(/\n/g, '')
},
{
key: 'X-Content-Type-Options',
value: 'nosniff'
},
{
key: 'Referrer-Policy',
value: 'strict-origin-when-cross-origin'
},
]
},
{
source: '/:id(\\w{20})',
headers: [
{
key: 'Strict-Transport-Security',
value: 'max-age=63072000; includeSubDomains; preload'
},
{
key: 'Content-Security-Policy',
value: cspHeaderTavlevisning.replace(/\n/g, ''),
},
{
key: 'X-Content-Type-Options',
value: 'nosniff'
},
{
key: 'Referrer-Policy',
value: 'strict-origin-when-cross-origin'
},
]
},
]
}
}



module.exports = async (phase, { defaultConfig }) => {
if (phase === PHASE_DEVELOPMENT_SERVER) {
nextConfig.images.remotePatterns.push({
Expand Down
6 changes: 1 addition & 5 deletions tavla/src/Board/scenarios/Board/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { StopPlaceTile } from '../StopPlaceTile'
import { QuayTile } from '../QuayTile'
import { Tile } from 'components/Tile'
import { defaultFontSize, getFontScale } from 'Board/scenarios/Board/utils'
import { CSSProperties } from 'react'

function BoardTile({ tileSpec }: { tileSpec: TTile }) {
switch (tileSpec.type) {
Expand All @@ -15,7 +14,7 @@ function BoardTile({ tileSpec }: { tileSpec: TTile }) {
}
}

function Board({ board, style }: { board: TBoard; style?: CSSProperties }) {
function Board({ board }: { board: TBoard }) {
if (!board.tiles || !board.tiles.length)
return (
<Tile className="flex items-center justify-center">
Expand All @@ -28,9 +27,6 @@ function Board({ board, style }: { board: TBoard; style?: CSSProperties }) {
className={`max-sm:overflow-y-scroll grid grid-cols-auto-fit-minmax gap-2.5 h-full overflow-hidden supports-[not(display:grid)]:flex supports-[not(display:grid)]:*:m-2.5 ${getFontScale(
board.meta?.fontSize || defaultFontSize(board),
)} `}
style={{
...style,
}}
>
{board.tiles.map((tile, index) => {
return <BoardTile key={index} tileSpec={tile} />
Expand Down
10 changes: 1 addition & 9 deletions tavla/src/Shared/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,18 @@ import TavlaLogoBlue from 'assets/logos/Tavla-blue.svg'
import Image from 'next/image'
import { TLogo, TTheme } from 'types/settings'
import { Clock } from 'components/Clock'
import classNames from 'classnames'

function Header({
theme,
className,
organizationLogo,
}: {
theme?: TTheme
className?: string
organizationLogo?: TLogo | null
}) {
const tavlaLogo = theme === 'light' ? TavlaLogoBlue : TavlaLogoWhite

return (
<div
className={classNames(
'flex flex-row justify-between items-center gap-em-3',
className,
)}
>
<div className="flex flex-row justify-between items-center gap-em-3">
<div className="relative w-full h-full">
<Image
src={organizationLogo ?? tavlaLogo}
Expand Down
26 changes: 0 additions & 26 deletions tavla/src/Shared/components/SecondaryLink.tsx

This file was deleted.