Skip to content

Commit

Permalink
nextjs improvements
Browse files Browse the repository at this point in the history
next.js integration now working correctly on vercel and with various security features enabled in all the modes app/pages, node/edge, page/api, etc

additional refactoring and cleanup of related code
  • Loading branch information
Theo Ephraim authored and theoephraim committed Jul 17, 2024
1 parent 8e6ce81 commit 16430aa
Show file tree
Hide file tree
Showing 34 changed files with 676 additions and 264 deletions.
7 changes: 7 additions & 0 deletions .changeset/proud-cats-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@dmno/nextjs-integration": patch
"@dmno/astro-integration": patch
"dmno": patch
---

nextjs integration with working security features, related refactoring to dmno and astro integration
1 change: 1 addition & 0 deletions example-repo/.dmno/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default defineDmnoService({
settings: {
interceptSensitiveLeakRequests: true,
redactSensitiveLogs: true,
enableLeakDetection: true,
},
schema: {
NODE_ENV: NodeEnvType,
Expand Down
6 changes: 6 additions & 0 deletions example-repo/packages/api/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,9 @@ router.get('/interceptor-demo', async (ctx) => {

ctx.body = results;
});

router.get('/leak-demo', async (ctx) => {
ctx.body = {
leaked: DMNO_CONFIG.SECRET_FOO,
};
});
2 changes: 1 addition & 1 deletion example-repo/packages/astro-web/astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ console.log('> secret value =', unredact(DMNO_CONFIG.SECRET_FOO));
// https://astro.build/config
export default defineConfig({
integrations: [
dmnoAstroIntegration(),
dmnoAstroIntegration() as any,
vue({ appEntrypoint: '/src/vue-app-config' }),
mdx(),
{
Expand Down
2 changes: 2 additions & 0 deletions example-repo/packages/nextjs-web/.dmno/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ export default defineDmnoService({
SECRET_STATIC: {
value: 'secret-static-default',
sensitive: true,
required: true,
},
SECRET_DYNAMIC: {
value: 'secret-dynamic-default',
dynamic: true,
sensitive: true,
required: true,
},


Expand Down
2 changes: 1 addition & 1 deletion example-repo/packages/nextjs-web/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ const nextConfig = {
// rest of user config...
};

export default dmnoNextConfigPlugin({ redactSensitiveLogs: true })(nextConfig);
export default dmnoNextConfigPlugin()(nextConfig);
2 changes: 1 addition & 1 deletion example-repo/packages/nextjs-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"dependencies": {
"@dmno/nextjs-integration": "link:../../../packages/integrations/nextjs",
"next": "14.2.2",
"next": "14.2.4",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
18 changes: 13 additions & 5 deletions example-repo/packages/nextjs-web/src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,24 @@

body {
color: rgb(var(--foreground-rgb));
background: linear-gradient(
to bottom,
background: linear-gradient(to bottom,
transparent,
rgb(var(--background-end-rgb))
)
rgb(var(--background-start-rgb));
rgb(var(--background-end-rgb))) rgb(var(--background-start-rgb));
}

@layer utilities {
.text-balance {
text-wrap: balance;
}
}


nav {
display: flex;
gap: 20px;
}

nav a:hover {
color: cyan;

}
24 changes: 24 additions & 0 deletions example-repo/packages/nextjs-web/src/app/intercept-test/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import '@dmno/nextjs-integration/inject';

console.log('server top of file', DMNO_CONFIG.SECRET_STATIC);

export default async function ServerPage() {
console.log('server handler fn --', DMNO_CONFIG.SECRET_STATIC);
console.log('server handler fn --', DMNO_CONFIG.SECRET_DYNAMIC);

const apiResp = await fetch('https://api.sampleapis.com/beers/ale', {
headers: {
// secret: DMNO_CONFIG.SECRET_STATIC,
'x-another': 'bloop',
},
});

return (
<main>
<h1>Leaked http interceptor test!</h1>

<p>This page should fail due to leaking a secret via an outbound http reqeust</p>

</main>
)
}
6 changes: 3 additions & 3 deletions example-repo/packages/nextjs-web/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ export default function RootLayout({
}>) {
return (
<html lang="en">

<body className={`${inter.className} p-6`}>
<h1>DMNO + nextjs example</h1>
<nav>
<a href="/client-page">client rendered page</a>
||||
<a href="/server-page">server rendered page</a>
||||

<a href="/api">json api endpoint</a>
<a href="/leak-test">Leak test</a>
<a href="/intercept-test">Http interceptor test</a>
</nav>
<hr className="my-4" />

Expand Down
18 changes: 18 additions & 0 deletions example-repo/packages/nextjs-web/src/app/leak-test/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import '@dmno/nextjs-integration/inject';

console.log('server top of file', DMNO_CONFIG.SECRET_STATIC);

export default function ServerPage() {
console.log('server handler fn --', DMNO_CONFIG.SECRET_STATIC);
console.log('server handler fn --', DMNO_CONFIG.SECRET_DYNAMIC);

return (
<main>
<h1>Leaked content test!</h1>

<p>This page should fail due to leaking a secret</p>

<p>{ DMNO_CONFIG.SECRET_STATIC }</p>
</main>
)
}
1 change: 0 additions & 1 deletion example-repo/packages/nextjs-web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"paths": {
"@/*": [ "./src/*" ]
},
"customConditions": [ "ts-src" ]
},
"include": [
"next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts",
Expand Down
90 changes: 45 additions & 45 deletions example-repo/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
],
"scripts": {
"clean": "rm -rf dist",
"build": "pnpm run build:injector && tsup",
"build": "pnpm run clean && pnpm run build:injector && tsup",
"build:injector": "tsup --config tsup.inject-standalone.config.ts",
"build:ifnodist": "[ -d \"./dist\" ] && echo 'dist exists' || pnpm build",
"build:tarball": "turbo build && pnpm pack --pack-destination \"../../../tmp-package-registry\"",
"dev": "pnpm run build:injector && tsup --watch",
"dev": "pnpm run clean && pnpm run build:injector && tsup --watch",
"lint": "eslint src --ext .ts,.cjs",
"lint:fix": "pnpm run lint --fix",
"test": "vitest"
Expand Down Expand Up @@ -65,6 +65,7 @@
"./injector-standalone": {
"ts-src": "./src/globals-injector/injector.ts",
"import": "./dist/globals-injector-standalone/injector.js",
"default": "./dist/globals-injector-standalone/injector.cjs",
"types": "./dist/globals-injector-standalone/injector.d.ts"
},
"./tsconfigs/*.json": "./tsconfigs/*",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/cli/lib/schema-scaffold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export function generateDmnoConfigInitialCode(opts: {
'',
'export default defineDmnoService({',
opts.isRoot && ' isRoot: true,',
opts.isRoot && ' settings: {\n redactSensitiveLogs: true,\n interceptSensitiveLeakRequests: true,\n },',
opts.isRoot && ' settings: {\n redactSensitiveLogs: true,\n interceptSensitiveLeakRequests: true,\n enableLeakDetection: true,\n },',
opts.serviceName
? ` name: '${opts.serviceName}',`
: (opts.isMonorepo ? ' // no name specified - inherit from package.json' : undefined),
Expand Down
Loading

0 comments on commit 16430aa

Please sign in to comment.