@stnd/modules 0.6.45 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/headers/csp-report.js +30 -0
- package/headers/index.module.js +12 -2
- package/headers/middleware.js +14 -0
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @stnd/folios
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Auto-bumped @stnd/modules due to modified code.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
- @stnd/server@0.8.0
|
|
13
|
+
|
|
14
|
+
## 0.6.46
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
- @stnd/icon@0.7.0
|
|
20
|
+
- @stnd/layout@0.7.7
|
|
21
|
+
|
|
3
22
|
## 0.6.45
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { normaliseReports } from "@stnd/server/cspReports";
|
|
2
|
+
import Log from "@stnd/log";
|
|
3
|
+
|
|
4
|
+
export const prerender = false;
|
|
5
|
+
|
|
6
|
+
const log = Log({ scope: "CSP" });
|
|
7
|
+
const noContent = () =>
|
|
8
|
+
new Response(null, { status: 204, headers: { "Cache-Control": "no-store" } });
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* POST /api/csp-report — where browsers send content-security-policy violations
|
|
12
|
+
* (`report-uri` in the policy). Public by nature, so it only reduces the report
|
|
13
|
+
* to a few short fields and always answers 204.
|
|
14
|
+
*
|
|
15
|
+
* An app that wants the reports counted sets `locals.cspReports` from its own
|
|
16
|
+
* middleware: `{ record(reports, request): Promise<void> }` (it owns rate
|
|
17
|
+
* limiting and storage). Without one, each report is logged.
|
|
18
|
+
*/
|
|
19
|
+
export async function POST({ request, locals }) {
|
|
20
|
+
try {
|
|
21
|
+
const text = (await request.text()).slice(0, 8000);
|
|
22
|
+
const reports = normaliseReports(JSON.parse(text));
|
|
23
|
+
if (!reports.length) return noContent();
|
|
24
|
+
if (locals?.cspReports?.record) await locals.cspReports.record(reports, request);
|
|
25
|
+
else for (const r of reports) log.warn("CSP violation", r);
|
|
26
|
+
} catch {
|
|
27
|
+
/* a malformed report is not worth an error */
|
|
28
|
+
}
|
|
29
|
+
return noContent();
|
|
30
|
+
}
|
package/headers/index.module.js
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Security Headers core module
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* - Middleware: security headers (HSTS, nosniff, frame options, referrer and
|
|
5
|
+
* permissions policies, a content-security-policy) on every response.
|
|
6
|
+
* Policy lives in `@stnd/server/security`; an app extends it with
|
|
7
|
+
* `standard({ security: { csp: { extend: { "script-src": [...] } } } })`.
|
|
8
|
+
* - `/api/csp-report`: where the policy's violations are sent.
|
|
9
|
+
* - `/_headers`: the same basics as a Cloudflare headers file.
|
|
5
10
|
*/
|
|
6
11
|
export default {
|
|
7
12
|
id: "stnd-headers",
|
|
8
13
|
name: "Stnd :: Headers",
|
|
9
|
-
description: "
|
|
14
|
+
description: "Security headers on every response, and the CSP violation report endpoint.",
|
|
15
|
+
middleware: [{ entrypoint: "./middleware.js", order: -1000 }],
|
|
10
16
|
routes: [
|
|
11
17
|
{
|
|
12
18
|
path: "/_headers",
|
|
13
19
|
entrypoint: "./route.js",
|
|
14
20
|
},
|
|
21
|
+
{
|
|
22
|
+
path: "/api/csp-report",
|
|
23
|
+
entrypoint: "./csp-report.js",
|
|
24
|
+
},
|
|
15
25
|
],
|
|
16
26
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import config from "virtual:stnd/config";
|
|
2
|
+
import { withSecurityHeaders } from "@stnd/server/security";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Every response, whichever way it was produced (page, API, redirect, error),
|
|
6
|
+
* leaves with the framework's security headers. Registered with a very low
|
|
7
|
+
* `order` so it wraps the whole middleware chain.
|
|
8
|
+
*
|
|
9
|
+
* Configured with `standard({ security: { csp: {...}, hsts, frameOptions } })`.
|
|
10
|
+
*/
|
|
11
|
+
export async function onRequest(context, next) {
|
|
12
|
+
const response = await next();
|
|
13
|
+
return withSecurityHeaders(response, context.url, config.security || {});
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stnd/modules",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"svelte": "./stripe/views/CheckoutView.svelte",
|
|
6
6
|
"author": "Francis Fontaine",
|
|
@@ -18,9 +18,10 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@astrojs/sitemap": "^3.7.3",
|
|
20
20
|
"@stnd/client": "0.7.5",
|
|
21
|
-
"@stnd/icon": "0.
|
|
22
|
-
"@stnd/layout": "0.7.
|
|
21
|
+
"@stnd/icon": "0.7.0",
|
|
22
|
+
"@stnd/layout": "0.7.7",
|
|
23
23
|
"@stnd/log": "0.5.2",
|
|
24
|
+
"@stnd/server": "0.8.0",
|
|
24
25
|
"@stnd/styles": "0.13.0",
|
|
25
26
|
"@stnd/utils": "0.7.3"
|
|
26
27
|
},
|