@camstack/server 1.2.265 → 1.2.267
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/dist/api/static/frame-policy.js +28 -0
- package/dist/main.js +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FRAME_ANCESTORS_POLICY = void 0;
|
|
4
|
+
exports.isFramePolicyTarget = isFramePolicyTarget;
|
|
5
|
+
exports.registerFramePolicy = registerFramePolicy;
|
|
6
|
+
/** The one directive: frame me from my origin only. */
|
|
7
|
+
exports.FRAME_ANCESTORS_POLICY = "frame-ancestors 'self'";
|
|
8
|
+
const CSP_HEADER = 'content-security-policy';
|
|
9
|
+
/** Only a document can be framed; assets, JSON and streams are never one. */
|
|
10
|
+
function isFramePolicyTarget(contentType) {
|
|
11
|
+
return typeof contentType === 'string' && contentType.trim().toLowerCase().startsWith('text/html');
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Install the `onSend` hook on the hub's one Fastify instance. Replies that
|
|
15
|
+
* bypass Fastify's reply pipeline (`reply.raw`, `reply.hijack()` — the addon
|
|
16
|
+
* reverse proxy's streaming path) are not seen here; they carry no HTML
|
|
17
|
+
* shell of ours.
|
|
18
|
+
*/
|
|
19
|
+
function registerFramePolicy(fastify) {
|
|
20
|
+
fastify.addHook('onSend', async (_request, reply, payload) => {
|
|
21
|
+
if (!isFramePolicyTarget(reply.getHeader('content-type')))
|
|
22
|
+
return payload;
|
|
23
|
+
if (reply.getHeader(CSP_HEADER) !== undefined)
|
|
24
|
+
return payload;
|
|
25
|
+
reply.header(CSP_HEADER, exports.FRAME_ANCESTORS_POLICY);
|
|
26
|
+
return payload;
|
|
27
|
+
});
|
|
28
|
+
}
|
package/dist/main.js
CHANGED
|
@@ -67,6 +67,7 @@ const sse_no_compression_js_1 = require("./api/sse-no-compression.js");
|
|
|
67
67
|
const precompressed_asset_js_1 = require("./api/static/precompressed-asset.js");
|
|
68
68
|
const spa_static_1 = require("./api/static/spa-static");
|
|
69
69
|
const spa_mount_1 = require("./api/static/spa-mount");
|
|
70
|
+
const frame_policy_1 = require("./api/static/frame-policy");
|
|
70
71
|
const cap_providers_1 = require("./api/core/cap-providers");
|
|
71
72
|
const logging_settings_1 = require("./api/core/logging-settings");
|
|
72
73
|
const request_census_settings_1 = require("./api/core/request-census-settings");
|
|
@@ -326,6 +327,10 @@ async function bootstrap() {
|
|
|
326
327
|
app.enableCors();
|
|
327
328
|
const fastify = app.getHttpAdapter().getInstance();
|
|
328
329
|
await fastify.register(cookie_1.default);
|
|
330
|
+
// Every HTML document the hub serves may be framed by its own origin only
|
|
331
|
+
// (D425). Stamped here, on the one instance, so no shell-send site added
|
|
332
|
+
// later can ship without it.
|
|
333
|
+
(0, frame_policy_1.registerFramePolicy)(fastify);
|
|
329
334
|
// Gzip/Brotli compression for all responses (including static JS/CSS).
|
|
330
335
|
// Registered before @fastify/static so the compress plugin wraps the
|
|
331
336
|
// static send path — hashed admin-ui chunks go from ~2MB to ~600KB on
|