@capixjs/plugin-helmet 0.1.0-alpha.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Capix Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # @capixjs/plugin-helmet
2
+
3
+ Security headers plugin for Capix. Sets Content-Security-Policy, X-Frame-Options, and other protective headers on all responses.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @capixjs/plugin-helmet
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { createServer } from '@capixjs/core';
15
+ import { restTransport } from '@capixjs/transport-rest';
16
+ import { helmetPlugin } from '@capixjs/plugin-helmet';
17
+
18
+ createServer({
19
+ capabilities: { ... },
20
+ plugins: [helmetPlugin()],
21
+ transports: [restTransport({ port: 3000 })],
22
+ }).start();
23
+ ```
24
+
25
+ ## Default headers
26
+
27
+ | Header | Default value |
28
+ |---|---|
29
+ | `Content-Security-Policy` | `default-src 'self'` |
30
+ | `X-Frame-Options` | `DENY` |
31
+ | `X-Content-Type-Options` | `nosniff` |
32
+ | `Referrer-Policy` | `no-referrer` |
33
+ | `X-Download-Options` | `noopen` |
34
+ | `X-DNS-Prefetch-Control` | `off` |
35
+ | `X-Permitted-Cross-Domain-Policies` | `none` |
36
+
37
+ ## Options
38
+
39
+ ```ts
40
+ helmetPlugin({
41
+ // Override or disable individual headers
42
+ contentSecurityPolicy: "default-src 'self'; img-src *",
43
+ contentSecurityPolicy: false, // disable this header
44
+ frameOptions: 'SAMEORIGIN',
45
+ frameOptions: false, // disable X-Frame-Options
46
+ })
47
+ ```
48
+
49
+ Passing `false` for any option omits that header entirely.
50
+
51
+ ## License
52
+
53
+ MIT
@@ -0,0 +1,29 @@
1
+ import type { RestTransportOptions } from '@capixjs/transport-rest';
2
+ export type HelmetOptions = {
3
+ /** Content-Security-Policy value (false to disable) */
4
+ readonly contentSecurityPolicy?: string | false;
5
+ /** X-Frame-Options value (false to disable, default: SAMEORIGIN) */
6
+ readonly frameOptions?: 'DENY' | 'SAMEORIGIN' | false;
7
+ /** Strict-Transport-Security value (false to disable) */
8
+ readonly hsts?: string | false;
9
+ /** X-Content-Type-Options (false to disable, default: nosniff) */
10
+ readonly noSniff?: boolean;
11
+ /** Referrer-Policy value (false to disable) */
12
+ readonly referrerPolicy?: string | false;
13
+ /** Permissions-Policy value (false to disable) */
14
+ readonly permissionsPolicy?: string | false;
15
+ };
16
+ /**
17
+ * Returns RestTransportOptions hooks that set common security headers.
18
+ * Merge the returned object with your restTransport options.
19
+ *
20
+ * @example
21
+ * restTransport({ port: 3000, ...helmet() })
22
+ */
23
+ export declare function helmet(options?: HelmetOptions): Pick<RestTransportOptions, 'hooks'>;
24
+ /**
25
+ * Merges multiple RestTransportOptions hook sets into one.
26
+ * Use when combining cors() + helmet() hooks.
27
+ */
28
+ export declare function mergeHooks(...hookSets: Array<Pick<RestTransportOptions, 'hooks'>>): Pick<RestTransportOptions, 'hooks'>;
29
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAEpE,MAAM,MAAM,aAAa,GAAG;IAC1B,uDAAuD;IACvD,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAChD,oEAAoE;IACpE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,YAAY,GAAG,KAAK,CAAC;IACtD,yDAAyD;IACzD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAC/B,kEAAkE;IAClE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,+CAA+C;IAC/C,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACzC,kDAAkD;IAClD,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;CAC7C,CAAC;AAWF;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,OAAO,GAAE,aAAkB,GAAG,IAAI,CAAC,oBAAoB,EAAE,OAAO,CAAC,CA2BvF;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,GAAG,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC,GACtD,IAAI,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAarC"}
package/dist/index.js ADDED
@@ -0,0 +1,62 @@
1
+ const DEFAULTS = {
2
+ contentSecurityPolicy: "default-src 'self'",
3
+ frameOptions: 'SAMEORIGIN',
4
+ hsts: 'max-age=31536000; includeSubDomains',
5
+ noSniff: true,
6
+ referrerPolicy: 'no-referrer',
7
+ permissionsPolicy: false,
8
+ };
9
+ /**
10
+ * Returns RestTransportOptions hooks that set common security headers.
11
+ * Merge the returned object with your restTransport options.
12
+ *
13
+ * @example
14
+ * restTransport({ port: 3000, ...helmet() })
15
+ */
16
+ export function helmet(options = {}) {
17
+ const merged = { ...DEFAULTS, ...options };
18
+ return {
19
+ hooks: {
20
+ onRequest: (_req, res) => {
21
+ if (merged.contentSecurityPolicy !== false) {
22
+ res.setHeader('Content-Security-Policy', merged.contentSecurityPolicy);
23
+ }
24
+ if (merged.frameOptions !== false) {
25
+ res.setHeader('X-Frame-Options', merged.frameOptions);
26
+ }
27
+ if (merged.hsts !== false) {
28
+ res.setHeader('Strict-Transport-Security', merged.hsts);
29
+ }
30
+ if (merged.noSniff) {
31
+ res.setHeader('X-Content-Type-Options', 'nosniff');
32
+ }
33
+ if (merged.referrerPolicy !== false) {
34
+ res.setHeader('Referrer-Policy', merged.referrerPolicy);
35
+ }
36
+ if (merged.permissionsPolicy !== false) {
37
+ res.setHeader('Permissions-Policy', merged.permissionsPolicy);
38
+ }
39
+ },
40
+ },
41
+ };
42
+ }
43
+ /**
44
+ * Merges multiple RestTransportOptions hook sets into one.
45
+ * Use when combining cors() + helmet() hooks.
46
+ */
47
+ export function mergeHooks(...hookSets) {
48
+ const fns = hookSets
49
+ .map((h) => h.hooks?.onRequest)
50
+ .filter((fn) => fn !== undefined);
51
+ if (fns.length === 0)
52
+ return {};
53
+ return {
54
+ hooks: {
55
+ onRequest: (req, res) => {
56
+ for (const fn of fns)
57
+ fn(req, res);
58
+ },
59
+ },
60
+ };
61
+ }
62
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkBA,MAAM,QAAQ,GAA4B;IACxC,qBAAqB,EAAE,oBAAoB;IAC3C,YAAY,EAAE,YAAY;IAC1B,IAAI,EAAE,qCAAqC;IAC3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,GAAG,QAAoD;IAEvD,MAAM,GAAG,GAAG,QAAQ;SACjB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,SAAS,CAAC;SAC9B,MAAM,CAAC,CAAC,EAAE,EAAgC,EAAE,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC;IAElE,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAChC,OAAO;QACL,KAAK,EAAE;YACL,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;gBACtB,KAAK,MAAM,EAAE,IAAI,GAAG;oBAAE,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;YACrC,CAAC;SACF;KACF,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@capixjs/plugin-helmet",
3
+ "version": "0.1.0-alpha.1",
4
+ "description": "Security headers plugin for Capix",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "LICENSE"
18
+ ],
19
+ "keywords": [
20
+ "capix",
21
+ "helmet",
22
+ "security",
23
+ "headers",
24
+ "csp",
25
+ "plugin",
26
+ "typescript"
27
+ ],
28
+ "engines": {
29
+ "node": ">=20"
30
+ },
31
+ "scripts": {
32
+ "build": "tsc",
33
+ "typecheck": "tsc --noEmit"
34
+ },
35
+ "peerDependencies": {
36
+ "@capixjs/transport-rest": ">=0.1.0-0"
37
+ },
38
+ "devDependencies": {
39
+ "@types/node": "^20.0.0",
40
+ "typescript": "^5.5.0",
41
+ "@capixjs/transport-rest": "workspace:*"
42
+ }
43
+ }