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: make node_env checks safe by default #383

Merged
merged 4 commits into from
Jan 3, 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
4 changes: 2 additions & 2 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const ContentSecurityPolicy = `
};
frame-src 'self';
object-src 'none';
script-src 'self' ${env.NODE_ENV === 'production' ? '' : "'unsafe-eval'"};
script-src 'self' ${['test', 'development'].includes(env.NODE_ENV) ? "'unsafe-eval'" : ''};
style-src 'self' https: 'unsafe-inline';
connect-src 'self' https://browser-intake-datadoghq.com https://*.browser-intake-datadoghq.com https://vitals.vercel-insights.com/v1/vitals ${
// For POSTing presigned URLs to R2 storage.
Expand All @@ -25,7 +25,7 @@ const ContentSecurityPolicy = `
: ''
};
worker-src 'self' blob:;
${env.NODE_ENV === 'production' ? 'upgrade-insecure-requests' : ''}
${['test', 'development'].includes(env.NODE_ENV) ? '' : 'upgrade-insecure-requests'}
`

/**
Expand Down
6 changes: 3 additions & 3 deletions src/env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ if (!!process.env.SKIP_ENV_VALIDATION == false) {
// Otherwise it would just be returning `undefined` and be annoying to debug
if (!isServer && !prop.startsWith('NEXT_PUBLIC_'))
throw new Error(
process.env.NODE_ENV === 'production'
? '❌ Attempted to access a server-side environment variable on the client'
: `❌ Attempted to access server-side environment variable '${prop}' on the client`,
['test', 'development'].includes(env.NODE_ENV)
? `❌ Attempted to access server-side environment variable '${prop}' on the client`
: '❌ Attempted to access a server-side environment variable on the client',
)
return target[/** @type {keyof typeof target} */ (prop)]
},
Expand Down
2 changes: 1 addition & 1 deletion src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const MyApp = ((props: AppPropsWithAuthAndLayout) => {
<Stack spacing={0} minH="$100vh">
<VersionWrapper />
<ChildWithLayout {...props} />
{process.env.NODE_ENV !== 'production' && (
{['test', 'development'].includes(env.NODE_ENV) && (
<ReactQueryDevtools initialIsOpen={false} />
)}
</Stack>
Expand Down
2 changes: 1 addition & 1 deletion src/server/modules/auth/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export const sessionOptions: SessionOptions = {
cookieName: 'auth.session-token',
ttl: 60 * 60 * 24 * 7, // 7 days
cookieOptions: {
secure: env.NODE_ENV === 'production',
secure: env.NODE_ENV !== 'development' && env.NODE_ENV !== 'test',
},
}
2 changes: 1 addition & 1 deletion src/server/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ export const prisma: PrismaClient =
log: env.NODE_ENV === 'development' ? ['error', 'warn'] : ['error'],
})

if (env.NODE_ENV !== 'production') {
if (['test', 'development'].includes(env.NODE_ENV)) {
prismaGlobal.prisma = prisma
}
Loading