-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from IslamZaoui/dev
merge dev into main
- Loading branch information
Showing
20 changed files
with
263 additions
and
4,511 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
node_modules | ||
dist | ||
.vercel | ||
.vercel | ||
bun.lockb | ||
.turbo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,19 +2,20 @@ | |
"name": "monorepo", | ||
"private": true, | ||
"scripts": { | ||
"build": "pnpm run -r build", | ||
"dev": "pnpm run -r --parallel --stream dev", | ||
"release": "pnpm run -r build && changeset publish", | ||
"lint": "prettier --check \"**/*.{json,md}\" && pnpm run -r lint", | ||
"format": "prettier --write \"**/*.{json,md}\" && pnpm run -r format" | ||
"build": "turbo run build", | ||
"dev": "turbo run dev", | ||
"release": "turbo run build && changeset publish", | ||
"lint": "prettier --check \"**/*.{json,md}\" && turbo run lint", | ||
"format": "prettier --write \"**/*.{json,md}\" && turbo run format" | ||
}, | ||
"workspaces": [ | ||
"packages/*", | ||
"apps/*" | ||
], | ||
"devDependencies": { | ||
"@changesets/cli": "catalog:default", | ||
"prettier": "catalog:default" | ||
"@changesets/cli": "^2.27.8", | ||
"prettier": "^3.1.1", | ||
"turbo": "^2.1.2" | ||
}, | ||
"packageManager": "[email protected]" | ||
"packageManager": "[email protected]" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,3 @@ | ||
import { Handle } from '@sveltejs/kit'; | ||
import { Config } from './types'; | ||
import { normalizeCspValue, normalizeHeaderValue } from './utils'; | ||
import { rules } from './headers'; | ||
|
||
/** | ||
* sets HTTP response security headers based on the provided configuration. | ||
* | ||
* @param {Config} [config] - Configuration object for secure headers. | ||
* @param {Object} [config.headers] - Custom headers to set. | ||
* @param {boolean} [config.debug] - Enables debug logging if true. | ||
* @param {Object} [config.csp] - Content Security Policy directives. | ||
* @returns {Object} An object containing the handle function to process requests. | ||
*/ | ||
export const securityHeaders = ( | ||
config: Config = { | ||
headers: { | ||
...rules.defaultHeaders, | ||
}, | ||
debug: false, | ||
csp: undefined, | ||
}, | ||
) => { | ||
const headers = new Map<string, string>(); | ||
|
||
if (config?.headers) { | ||
Object.entries(config.headers).forEach(([key, value]) => { | ||
value && headers.set(key, normalizeHeaderValue(value)); | ||
}); | ||
} | ||
|
||
if (config?.csp) { | ||
const cspDirectives = Object.entries(config.csp.directives) | ||
.map(([key, value]) => `${key} ${normalizeCspValue(value)}`) | ||
.join('; '); | ||
headers.set('Content-Security-Policy', cspDirectives); | ||
} | ||
|
||
const handle: Handle = async ({ event, resolve }) => { | ||
if (config?.debug) { | ||
console.log( | ||
'[DEBUG] securekit Headers:', | ||
JSON.stringify(Object.fromEntries(headers), null, 2), | ||
); | ||
} | ||
|
||
const response = await resolve(event); | ||
|
||
headers.forEach((value, key) => { | ||
response.headers.set(key, value); | ||
}); | ||
|
||
return response; | ||
}; | ||
|
||
return { handle }; | ||
}; | ||
|
||
export { rules } from './headers'; | ||
export { securityHeaders } from './securityHeaders'; | ||
export { default as rules } from './constants/rules'; | ||
export * from './types'; |
Oops, something went wrong.