Skip to content

Commit

Permalink
Add nonces to adapter-cloudflare.
Browse files Browse the repository at this point in the history
  • Loading branch information
Karlinator committed Jan 8, 2022
1 parent 7e693d5 commit cf26271
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions packages/adapter-cloudflare/files/worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global ASSETS */
/* global ASSETS, GENERATE_NONCES */
import { init, render } from '../output/server/app.js';

init();
Expand All @@ -18,7 +18,8 @@ export default {
query: url.searchParams || '',
rawBody: await read(req),
headers: Object.fromEntries(req.headers),
method: req.method
method: req.method,
nonce: GENERATE_NONCES && btoa(crypto.getRandomValues(new Uint32Array(2)))
});

if (rendered) {
Expand Down
5 changes: 4 additions & 1 deletion packages/adapter-cloudflare/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export default function (options = {}) {
outfile: target_worker,
allowOverwrite: true,
format: 'esm',
bundle: true
bundle: true,
define: {
GENERATE_NONCES: config.kit.cspNonce.toString()
}
});
}
};
Expand Down

0 comments on commit cf26271

Please sign in to comment.