node-env-resolver 6.5.2 → 6.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/README.md +186 -11
- package/dist/audit.d.ts +7 -8
- package/dist/audit.d.ts.map +1 -0
- package/dist/builder.cjs +1 -1
- package/dist/builder.d.ts +9 -12
- package/dist/builder.d.ts.map +1 -0
- package/dist/builder.js +1 -1
- package/dist/chunk-3TXO5AOZ.cjs +3 -0
- package/dist/chunk-4CLWNKB5.js +1 -0
- package/dist/chunk-4DUWYBNJ.cjs +6 -0
- package/dist/chunk-6NSX37SO.js +6 -0
- package/dist/chunk-BITH5LSH.js +3 -0
- package/dist/{chunk-DIJNUFGZ.cjs → chunk-G5HNCCR6.cjs} +3 -3
- package/dist/chunk-IP6POQCY.cjs +1 -0
- package/dist/{chunk-ZSM2NDX5.js → chunk-JVRRDD3Y.js} +3 -3
- package/dist/chunk-KHEBSYFP.js +9 -0
- package/dist/chunk-NHXSZY2U.cjs +9 -0
- package/dist/chunk-NKISCWWB.js +1 -0
- package/dist/chunk-UZ7HKTYL.cjs +1 -0
- package/dist/cli/bin.cjs +67 -27
- package/dist/cli/bin.d.ts +11 -0
- package/dist/cli/bin.d.ts.map +1 -0
- package/dist/cli/bin.js +67 -27
- package/dist/cli/scan.d.ts +24 -0
- package/dist/cli/scan.d.ts.map +1 -0
- package/dist/cli.d.ts +4 -7
- package/dist/cli.d.ts.map +1 -0
- package/dist/debug.d.ts +142 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +19 -61
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -1
- package/dist/inspect.d.ts +63 -0
- package/dist/inspect.d.ts.map +1 -0
- package/dist/process-env.d.ts +32 -0
- package/dist/process-env.d.ts.map +1 -0
- package/dist/provider-kit.cjs +2 -0
- package/dist/provider-kit.d.ts +49 -0
- package/dist/provider-kit.d.ts.map +1 -0
- package/dist/provider-kit.js +2 -0
- package/dist/providers.d.ts +49 -0
- package/dist/providers.d.ts.map +1 -0
- package/dist/references.d.ts +5 -0
- package/dist/references.d.ts.map +1 -0
- package/dist/resolver.cjs +1 -1
- package/dist/resolver.d.ts +16 -8
- package/dist/resolver.d.ts.map +1 -0
- package/dist/resolver.js +1 -1
- package/dist/resolvers.cjs +1 -1
- package/dist/resolvers.d.ts +13 -31
- package/dist/resolvers.d.ts.map +1 -0
- package/dist/resolvers.js +1 -1
- package/dist/runtime/index.cjs +1 -1
- package/dist/runtime/index.d.ts +8 -108
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +1 -1
- package/dist/runtime/patch-console.d.ts +23 -0
- package/dist/runtime/patch-console.d.ts.map +1 -0
- package/dist/runtime/redactor.d.ts +22 -0
- package/dist/runtime/redactor.d.ts.map +1 -0
- package/dist/runtime/response.d.ts +59 -0
- package/dist/runtime/response.d.ts.map +1 -0
- package/dist/security.d.ts +49 -0
- package/dist/security.d.ts.map +1 -0
- package/dist/sensitivity.d.ts +34 -0
- package/dist/sensitivity.d.ts.map +1 -0
- package/dist/types.d.ts +150 -1
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.cjs +1 -1
- package/dist/utils.d.ts +19 -21
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +1 -1
- package/dist/valibot.cjs +1 -1
- package/dist/valibot.d.ts +9 -11
- package/dist/valibot.d.ts.map +1 -0
- package/dist/valibot.js +1 -1
- package/dist/validation-types.d.ts +3 -4
- package/dist/validation-types.d.ts.map +1 -0
- package/dist/validators.cjs +2 -2
- package/dist/validators.d.ts +59 -44
- package/dist/validators.d.ts.map +1 -0
- package/dist/validators.js +2 -2
- package/dist/web.cjs +3 -3
- package/dist/web.d.ts +8 -10
- package/dist/web.d.ts.map +1 -0
- package/dist/web.js +3 -3
- package/dist/zod.cjs +1 -1
- package/dist/zod.d.ts +9 -11
- package/dist/zod.d.ts.map +1 -0
- package/dist/zod.js +1 -1
- package/package.json +15 -16
- package/dist/audit.d.cts +0 -52
- package/dist/builder.d.cts +0 -149
- package/dist/chunk-3EWCMDFP.js +0 -9
- package/dist/chunk-4QOKRJ3F.cjs +0 -1
- package/dist/chunk-DYFRO3NM.cjs +0 -9
- package/dist/chunk-K4NIC5T3.js +0 -9
- package/dist/chunk-WKIPEKF6.js +0 -1
- package/dist/chunk-WVMDTD6J.cjs +0 -9
- package/dist/cli/bin.d.cts +0 -1
- package/dist/cli.d.cts +0 -52
- package/dist/index.d.cts +0 -220
- package/dist/resolver.d.cts +0 -20
- package/dist/resolvers.d.cts +0 -190
- package/dist/runtime/index.d.cts +0 -161
- package/dist/types--RcOnfdl.d.cts +0 -284
- package/dist/types--RcOnfdl.d.ts +0 -284
- package/dist/types.d.cts +0 -1
- package/dist/utils.d.cts +0 -327
- package/dist/valibot.d.cts +0 -143
- package/dist/validation-types.d.cts +0 -29
- package/dist/validators.d.cts +0 -933
- package/dist/web.d.cts +0 -71
- package/dist/zod.d.cts +0 -122
package/dist/resolvers.d.ts
CHANGED
|
@@ -1,29 +1,12 @@
|
|
|
1
|
-
import { d as SyncResolver, a as Resolver } from './types--RcOnfdl.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Resolver that reads from process.env
|
|
5
|
-
* This is the default resolver used when no custom resolvers are provided
|
|
6
|
-
*
|
|
7
|
-
* @returns SyncResolver that loads environment variables from process.env
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* import { processEnv } from 'node-env-resolver';
|
|
12
|
-
*
|
|
13
|
-
* const resolver = processEnv();
|
|
14
|
-
* const env = resolver.loadSync(); // { PORT: '3000', NODE_ENV: 'development', ... }
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
declare function processEnv(): SyncResolver;
|
|
18
|
-
|
|
19
1
|
/**
|
|
20
2
|
* Built-in resolvers for environment variable resolution
|
|
21
3
|
*/
|
|
22
|
-
|
|
4
|
+
import type { Resolver, SyncResolver } from './types';
|
|
5
|
+
export { processEnv, fromObject } from './process-env';
|
|
23
6
|
/**
|
|
24
7
|
* Options for the dotenv resolver
|
|
25
8
|
*/
|
|
26
|
-
interface DotenvOptions {
|
|
9
|
+
export interface DotenvOptions {
|
|
27
10
|
/** Path to the .env file (default: '.env') */
|
|
28
11
|
path?: string;
|
|
29
12
|
/** Enable environment-specific file loading (default: false) */
|
|
@@ -54,7 +37,7 @@ interface DotenvOptions {
|
|
|
54
37
|
* // Loads: .env.defaults, .env, .env.local, .env.development, .env.development.local
|
|
55
38
|
* ```
|
|
56
39
|
*/
|
|
57
|
-
declare function dotenv(options?: string | DotenvOptions): SyncResolver;
|
|
40
|
+
export declare function dotenv(options?: string | DotenvOptions): SyncResolver;
|
|
58
41
|
/**
|
|
59
42
|
* Load configuration from package.json
|
|
60
43
|
* Reads version, name, and config fields by default
|
|
@@ -73,7 +56,7 @@ declare function dotenv(options?: string | DotenvOptions): SyncResolver;
|
|
|
73
56
|
* ]);
|
|
74
57
|
* ```
|
|
75
58
|
*/
|
|
76
|
-
declare function packageJson(options?: {
|
|
59
|
+
export declare function packageJson(options?: {
|
|
77
60
|
path?: string;
|
|
78
61
|
fields?: string[];
|
|
79
62
|
}): Resolver;
|
|
@@ -96,7 +79,7 @@ declare function packageJson(options?: {
|
|
|
96
79
|
* ]);
|
|
97
80
|
* ```
|
|
98
81
|
*/
|
|
99
|
-
declare function http(url: string, options?: RequestInit & {
|
|
82
|
+
export declare function http(url: string, options?: RequestInit & {
|
|
100
83
|
timeout?: number;
|
|
101
84
|
}): Resolver;
|
|
102
85
|
/**
|
|
@@ -115,7 +98,7 @@ declare function http(url: string, options?: RequestInit & {
|
|
|
115
98
|
* );
|
|
116
99
|
* ```
|
|
117
100
|
*/
|
|
118
|
-
declare function json(path?: string): Resolver;
|
|
101
|
+
export declare function json(path?: string): Resolver;
|
|
119
102
|
/**
|
|
120
103
|
* Load secrets from a directory (Docker secrets / Kubernetes mounted secrets)
|
|
121
104
|
* Each file in the directory becomes an environment variable (filename = key, content = value)
|
|
@@ -133,12 +116,12 @@ declare function json(path?: string): Resolver;
|
|
|
133
116
|
* );
|
|
134
117
|
* ```
|
|
135
118
|
*/
|
|
136
|
-
declare function secrets(path?: string): Resolver;
|
|
119
|
+
export declare function secrets(path?: string): Resolver;
|
|
137
120
|
/**
|
|
138
121
|
* YAML configuration file resolver interface
|
|
139
122
|
* Requires 'js-yaml' as a peer dependency (install separately for tree-shaking)
|
|
140
123
|
*/
|
|
141
|
-
interface YamlOptions {
|
|
124
|
+
export interface YamlOptions {
|
|
142
125
|
/** Path to the YAML file (default: 'config.yaml') */
|
|
143
126
|
path?: string;
|
|
144
127
|
}
|
|
@@ -159,12 +142,12 @@ interface YamlOptions {
|
|
|
159
142
|
* );
|
|
160
143
|
* ```
|
|
161
144
|
*/
|
|
162
|
-
declare function yaml(options?: string | YamlOptions): Resolver;
|
|
145
|
+
export declare function yaml(options?: string | YamlOptions): Resolver;
|
|
163
146
|
/**
|
|
164
147
|
* TOML configuration file resolver interface
|
|
165
148
|
* Requires 'smol-toml' as a peer dependency (install separately for tree-shaking)
|
|
166
149
|
*/
|
|
167
|
-
interface TomlOptions {
|
|
150
|
+
export interface TomlOptions {
|
|
168
151
|
/** Path to the TOML file (default: 'config.toml') */
|
|
169
152
|
path?: string;
|
|
170
153
|
}
|
|
@@ -185,6 +168,5 @@ interface TomlOptions {
|
|
|
185
168
|
* );
|
|
186
169
|
* ```
|
|
187
170
|
*/
|
|
188
|
-
declare function toml(options?: string | TomlOptions): Resolver;
|
|
189
|
-
|
|
190
|
-
export { type DotenvOptions, type TomlOptions, type YamlOptions, dotenv, http, json, packageJson, processEnv, secrets, toml, yaml };
|
|
171
|
+
export declare function toml(options?: string | TomlOptions): Resolver;
|
|
172
|
+
//# sourceMappingURL=resolvers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolvers.d.ts","sourceRoot":"","sources":["../src/resolvers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEtD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,8CAA8C;IAC9C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AA0DD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,aAAa,GAAG,YAAY,CAiFrE;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB,GAAG,QAAQ,CA4FX;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,IAAI,CAClB,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,WAAW,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3C,QAAQ,CAqDV;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,IAAI,CAAC,IAAI,GAAE,MAAsB,GAAG,QAAQ,CAoE3D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,OAAO,CAAC,IAAI,GAAE,MAAuB,GAAG,QAAQ,CAqE/D;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,qDAAqD;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,CAuG7D;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,qDAAqD;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,CAuG7D"}
|
package/dist/resolvers.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{a as dotenv,c as http,d as json,b as packageJson,e as secrets,g as toml,f as yaml}from'./chunk-
|
|
1
|
+
export{a as dotenv,c as http,d as json,b as packageJson,e as secrets,g as toml,f as yaml}from'./chunk-JVRRDD3Y.js';export{a as fromObject,b as processEnv}from'./chunk-4CLWNKB5.js';import'./chunk-I7AUKTXE.js';
|
package/dist/runtime/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';require('../chunk-D6WM53FN.cjs');var
|
|
1
|
+
'use strict';var chunkUZ7HKTYL_cjs=require('../chunk-UZ7HKTYL.cjs');require('../chunk-D6WM53FN.cjs');var v=chunkUZ7HKTYL_cjs.a,_=[/sk_live_[a-zA-Z0-9]{24,}/g,/sk_test_[a-zA-Z0-9]{24,}/g,/pk_live_[a-zA-Z0-9]{24,}/g,/pk_test_[a-zA-Z0-9]{24,}/g,/xox[baprs]-[a-zA-Z0-9-]+/g,/ghp_[a-zA-Z0-9]{36}/g,/gho_[a-zA-Z0-9]{36}/g,/ghu_[a-zA-Z0-9]{36}/g,/ghs_[a-zA-Z0-9]{36}/g,/ghr_[a-zA-Z0-9]{36}/g,/eyJ[a-zA-Z0-9_-]*\.eyJ[a-zA-Z0-9_-]*\.[a-zA-Z0-9_-]*/g,/postgres:\/\/[^@]+:[^@]+@/g,/mysql:\/\/[^@]+:[^@]+@/g,/mongodb(\+srv)?:\/\/[^@]+:[^@]+@/g,/redis:\/\/[^:]+:[^@]+@/g,/rediss:\/\/[^:]+:[^@]+@/g];function A(t){let r=t.length;return r<=4?"****":r<=8?`${t[0]}****${t[r-1]}`:r<=16?`${t.slice(0,2)}****${t.slice(-2)}`:`${t.slice(0,4)}...${t.slice(-4)}`}function h(t,r={}){let{sensitivePatterns:a=v,customPatterns:u=[],fallbackValue:i="[REDACTED]"}=r,c=[..._,...u],l=new Set(t.values());function p(e){return a.some(n=>n.test(e))}function w(e){let n=e;for(let[,o]of t)if(typeof o=="string"&&o.length>0){let d=o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");n=n.replace(new RegExp(d,"g"),i);}for(let o of c)n=n.replace(o,i);return n}function g(e,n=0,o=new WeakSet){if(n>10||e==null)return e;if(typeof e=="string")return w(e);if(typeof e=="number"||typeof e=="bigint")return l.has(String(e))?i:e;if(typeof e!="object")return e;if(o.has(e))return "[Circular]";if(o.add(e),Array.isArray(e))return e.map(s=>g(s,n+1,o));if(e instanceof Error){let s=new Error(w(e.message));return s.name=e.name,s.stack=e.stack?w(e.stack):void 0,s}if(e instanceof Date||e instanceof RegExp)return e;if(e instanceof Map)return new Map(Array.from(e.entries()).map(([s,f])=>[g(s,n+1,o),g(f,n+1,o)]));if(e instanceof Set)return new Set(Array.from(e.values()).map(s=>g(s,n+1,o)));let d={};for(let[s,f]of Object.entries(e))p(s)?d[s]=typeof f=="string"?i:"[REDACTED]":typeof f=="string"?d[s]=w(f):d[s]=g(f,n+1,o);return d}return {redactString:w,redactObject:g,maskValue:A,createFingerprint:e=>{let n=0;for(let o=0;o<e.length;o++){let d=e.charCodeAt(o);n=(n<<5)-n+d,n=n&n;}return `sha256:${Math.abs(n).toString(16).slice(0,8)}`},shouldRedactKey:p}}function y(t,r={}){let a=new Map,u=r.sensitiveKeys?.map(i=>new RegExp(i,"i"))??v;for(let[i,c]of Object.entries(t))chunkUZ7HKTYL_cjs.f(c)?chunkUZ7HKTYL_cjs.d(c).forEach((l,p)=>{a.set(p===0?i:`${i}#${p}`,l);}):typeof c=="string"&&u.some(l=>l.test(i))&&a.set(i,c);return a}var R="__nodeEnvResolverPatched";function S(t,r={}){let{enabled:a=true,methods:u=["log","debug","info","warn","error","trace"],redactStrings:i=true,redactObjects:c=true,...l}=r;if(!a)return ()=>{};let p=console;if(p[R])return ()=>{};let w=y(t),g=h(w,l),e={};for(let n of u)if(typeof console[n]=="function"){e[n]=console[n].bind(console);let o=e[n];console[n]=(...d)=>{let s=d.map(f=>typeof f=="string"&&i?g.redactString(f):(typeof f=="number"||typeof f=="bigint")&&i||typeof f=="object"&&c&&f!==null?g.redactObject(f):f);o(...s);};}return Object.defineProperty(p,R,{value:true,writable:true,enumerable:false,configurable:true}),()=>{for(let n of u)if(e[n]){let d=e[n].bind(console);console[n]=d;}try{delete p[R];}catch{}p[R]=false;}}function C(t,r={}){let a=y(t),u=h(a,r);return {redact:(...i)=>i.map(c=>typeof c=="string"?u.redactString(c):typeof c=="object"&&c!==null?u.redactObject(c):c),...u}}var x=["image/","video/","audio/","application/octet-stream","application/pdf"];function T(t,r){let a=t.toLowerCase();return !r.some(u=>a.includes(u.toLowerCase()))}function b(t,r,a){if(r===t)return t;if(a==="throw")throw new Error('Secret leak detected in HTTP response body. A sensitive value was found before it could be sent. Use mode: "redact" to automatically scrub, or mode: "warn" to log and continue.');return a==="warn"?(console.warn('[node-env-resolver] Potential secret leak detected in HTTP response. Set mode: "redact" to scrub automatically.'),t):r}function z(t,r={}){let{mode:a=process.env.NODE_ENV==="production"?"warn":"throw",ignoreContentTypes:u=x,maxBodySize:i=1024*1024,...c}=r,l=y(t),p=h(l,c);return function(g,e,n){let o=e.end.bind(e);e.end=function(...d){let s=d[0];if(s!=null&&(typeof s=="string"||Buffer.isBuffer(s))){let f=String(e.getHeader?.("content-type")??"");if(T(f,u)){let k=typeof s=="string"?s:s.toString("utf8");if(Buffer.byteLength(k)<=i)try{let m=p.redactString(k);d[0]=b(k,m,a);}catch(m){if(a==="throw")throw m;console.error("[node-env-resolver] Response scan error:",m);}}}return o(...d)},n();}}async function V(t,r,a={}){let{mode:u="warn",ignoreContentTypes:i=x,maxBodySize:c=1024*1024,...l}=a,p=t.headers.get("content-type")??"";if(!T(p,i))return t;let g=await t.clone().arrayBuffer();if(g.byteLength>c)return t;let e=new TextDecoder().decode(g),n=y(r),d=h(n,l).redactString(e);if(d===e)return t;if(u==="throw")throw new Error('Secret leak detected in HTTP response. Use mode: "redact" to scrub automatically.');return u==="warn"?(console.warn("[node-env-resolver] Potential secret leak detected in HTTP response."),t):new Response(d,{status:t.status,statusText:t.statusText,headers:t.headers})}function F(t,r,a={}){if(typeof t!="string"&&!Buffer.isBuffer(t))return {safe:true};let u=y(r),i=h(u,a),c=typeof t=="string"?t:t.toString("utf8"),l=i.redactString(c);return l!==c?{safe:false,redacted:l}:{safe:true}}function H(t,r={}){return r.console===false?()=>{}:S(t,r.console)}exports.createConsoleRedactor=C;exports.createRedactor=h;exports.createResponseMiddleware=z;exports.extractSensitiveValues=y;exports.patchGlobalConsole=S;exports.protect=H;exports.scanBodyForSecrets=F;exports.wrapFetchResponse=V;
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,106 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Redaction utilities for protecting secrets in logs and responses
|
|
3
|
-
*/
|
|
4
|
-
interface RedactorOptions {
|
|
5
|
-
sensitiveKeys?: string[];
|
|
6
|
-
sensitivePatterns?: RegExp[];
|
|
7
|
-
customPatterns?: RegExp[];
|
|
8
|
-
fallbackValue?: string;
|
|
9
|
-
}
|
|
10
|
-
declare function maskValue(value: string): string;
|
|
11
|
-
declare function createRedactor(sensitiveValues: Map<string, string>, options?: RedactorOptions): {
|
|
12
|
-
redactString: (str: string) => string;
|
|
13
|
-
redactObject: (obj: unknown, depth?: number, seen?: WeakSet<WeakKey>) => unknown;
|
|
14
|
-
maskValue: typeof maskValue;
|
|
15
|
-
createFingerprint: (value: string) => string;
|
|
16
|
-
shouldRedactKey: (key: string) => boolean;
|
|
17
|
-
};
|
|
18
|
-
declare function extractSensitiveValues(config: Record<string, unknown>, options?: {
|
|
19
|
-
sensitiveKeys?: string[];
|
|
20
|
-
}): Map<string, string>;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Patch global console methods to redact sensitive values
|
|
24
|
-
*
|
|
25
|
-
* Prevents accidental logging of secrets by intercepting console methods
|
|
26
|
-
* and redacting values matching sensitive patterns.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
interface ConsolePatchOptions extends RedactorOptions {
|
|
30
|
-
enabled?: boolean;
|
|
31
|
-
methods?: ('log' | 'debug' | 'info' | 'warn' | 'error' | 'trace')[];
|
|
32
|
-
redactStrings?: boolean;
|
|
33
|
-
redactObjects?: boolean;
|
|
34
|
-
}
|
|
35
|
-
declare function patchGlobalConsole(config: Record<string, unknown>, options?: ConsolePatchOptions): () => void;
|
|
36
|
-
declare function createConsoleRedactor(config: Record<string, unknown>, options?: ConsolePatchOptions): {
|
|
37
|
-
redactString: (str: string) => string;
|
|
38
|
-
redactObject: (obj: unknown, depth?: number, seen?: WeakSet<WeakKey>) => unknown;
|
|
39
|
-
maskValue: (value: string) => string;
|
|
40
|
-
createFingerprint: (value: string) => string;
|
|
41
|
-
shouldRedactKey: (key: string) => boolean;
|
|
42
|
-
redact: (...args: unknown[]) => unknown[];
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Response protection utilities for preventing secret leakage in HTTP responses
|
|
47
|
-
*
|
|
48
|
-
* Provides middleware for Node.js (Express/Connect/Hono) and a utility for
|
|
49
|
-
* Edge runtimes (Cloudflare Workers, Vercel Edge, etc.).
|
|
50
|
-
*
|
|
51
|
-
* @example Node.js / Express
|
|
52
|
-
* ```ts
|
|
53
|
-
* import express from 'express';
|
|
54
|
-
* import { createResponseMiddleware } from 'node-env-resolver/runtime';
|
|
55
|
-
*
|
|
56
|
-
* const app = express();
|
|
57
|
-
* app.use(createResponseMiddleware(config, { mode: 'throw' }));
|
|
58
|
-
* ```
|
|
59
|
-
*
|
|
60
|
-
* @example Edge runtime
|
|
61
|
-
* ```ts
|
|
62
|
-
* import { wrapFetchResponse } from 'node-env-resolver/runtime';
|
|
63
|
-
*
|
|
64
|
-
* export default {
|
|
65
|
-
* async fetch(req, env) {
|
|
66
|
-
* const response = await handler(req);
|
|
67
|
-
* return wrapFetchResponse(response, config, { mode: 'redact' });
|
|
68
|
-
* }
|
|
69
|
-
* }
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
|
|
73
|
-
interface ResponsePatchOptions extends RedactorOptions {
|
|
74
|
-
mode?: 'throw' | 'redact' | 'warn';
|
|
75
|
-
ignoreContentTypes?: string[];
|
|
76
|
-
maxBodySize?: number;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Express / Connect / Hono middleware that scans outgoing response bodies
|
|
80
|
-
* for sensitive values and redacts, warns, or throws depending on `mode`.
|
|
81
|
-
*
|
|
82
|
-
* Default mode: 'warn' in production, 'throw' in development.
|
|
83
|
-
*/
|
|
84
|
-
declare function createResponseMiddleware(config: Record<string, unknown>, options?: ResponsePatchOptions): (_req: unknown, res: {
|
|
85
|
-
end: (...args: unknown[]) => unknown;
|
|
86
|
-
write?: (...args: unknown[]) => unknown;
|
|
87
|
-
getHeader?: (name: string) => string | number | string[] | undefined;
|
|
88
|
-
}, next: () => void) => void;
|
|
89
|
-
/**
|
|
90
|
-
* Scan and optionally redact an Edge runtime `Response` object.
|
|
91
|
-
* Returns a new Response (original is consumed). Safe to use in
|
|
92
|
-
* Cloudflare Workers, Vercel Edge Functions, and Deno Deploy.
|
|
93
|
-
*/
|
|
94
|
-
declare function wrapFetchResponse(response: Response, config: Record<string, unknown>, options?: ResponsePatchOptions): Promise<Response>;
|
|
95
|
-
/**
|
|
96
|
-
* Utility to imperatively scan a response body for secrets.
|
|
97
|
-
* Useful when you need to check manually rather than via middleware.
|
|
98
|
-
*/
|
|
99
|
-
declare function scanBodyForSecrets(body: string | Buffer | unknown, config: Record<string, unknown>, options?: ResponsePatchOptions): {
|
|
100
|
-
safe: boolean;
|
|
101
|
-
redacted?: string;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
1
|
/**
|
|
105
2
|
* Runtime protection utilities for preventing secret leaks
|
|
106
3
|
*
|
|
@@ -128,8 +25,12 @@ declare function scanBodyForSecrets(body: string | Buffer | unknown, config: Rec
|
|
|
128
25
|
* app.use(createResponseMiddleware(config, { mode: 'redact' }));
|
|
129
26
|
* ```
|
|
130
27
|
*/
|
|
131
|
-
|
|
132
|
-
|
|
28
|
+
import { type ConsolePatchOptions } from './patch-console.js';
|
|
29
|
+
import type { ResponsePatchOptions } from './response.js';
|
|
30
|
+
export { patchGlobalConsole, createConsoleRedactor, type ConsolePatchOptions, } from './patch-console.js';
|
|
31
|
+
export { createResponseMiddleware, wrapFetchResponse, scanBodyForSecrets, type ResponsePatchOptions, } from './response.js';
|
|
32
|
+
export { createRedactor, extractSensitiveValues, type RedactorOptions, } from './redactor.js';
|
|
33
|
+
export interface ProtectOptions {
|
|
133
34
|
/** Options forwarded to patchGlobalConsole. Pass false to disable console patching. */
|
|
134
35
|
console?: ConsolePatchOptions | false;
|
|
135
36
|
/** Options forwarded to createResponseMiddleware. Response protection must still be
|
|
@@ -156,6 +57,5 @@ interface ProtectOptions {
|
|
|
156
57
|
* unprotect();
|
|
157
58
|
* ```
|
|
158
59
|
*/
|
|
159
|
-
declare function protect(config: Record<string, unknown>, options?: ProtectOptions): () => void;
|
|
160
|
-
|
|
161
|
-
export { type ConsolePatchOptions, type ProtectOptions, type RedactorOptions, type ResponsePatchOptions, createConsoleRedactor, createRedactor, createResponseMiddleware, extractSensitiveValues, patchGlobalConsole, protect, scanBodyForSecrets, wrapFetchResponse };
|
|
60
|
+
export declare function protect(config: Record<string, unknown>, options?: ProtectOptions): () => void;
|
|
61
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/runtime/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAsB,KAAK,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAE1D,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,KAAK,mBAAmB,GACzB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,kBAAkB,EAClB,KAAK,oBAAoB,GAC1B,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,KAAK,eAAe,GACrB,MAAM,eAAe,CAAC;AAEvB,MAAM,WAAW,cAAc;IAC7B,uFAAuF;IACvF,OAAO,CAAC,EAAE,mBAAmB,GAAG,KAAK,CAAC;IACtC;sEACkE;IAClE,SAAS,CAAC,EAAE,oBAAoB,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,OAAO,CACrB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,GAAE,cAAmB,GAC3B,MAAM,IAAI,CAKZ"}
|
package/dist/runtime/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import'../chunk-I7AUKTXE.js';var
|
|
1
|
+
import {a,f,d}from'../chunk-NKISCWWB.js';import'../chunk-I7AUKTXE.js';var v=a,_=[/sk_live_[a-zA-Z0-9]{24,}/g,/sk_test_[a-zA-Z0-9]{24,}/g,/pk_live_[a-zA-Z0-9]{24,}/g,/pk_test_[a-zA-Z0-9]{24,}/g,/xox[baprs]-[a-zA-Z0-9-]+/g,/ghp_[a-zA-Z0-9]{36}/g,/gho_[a-zA-Z0-9]{36}/g,/ghu_[a-zA-Z0-9]{36}/g,/ghs_[a-zA-Z0-9]{36}/g,/ghr_[a-zA-Z0-9]{36}/g,/eyJ[a-zA-Z0-9_-]*\.eyJ[a-zA-Z0-9_-]*\.[a-zA-Z0-9_-]*/g,/postgres:\/\/[^@]+:[^@]+@/g,/mysql:\/\/[^@]+:[^@]+@/g,/mongodb(\+srv)?:\/\/[^@]+:[^@]+@/g,/redis:\/\/[^:]+:[^@]+@/g,/rediss:\/\/[^:]+:[^@]+@/g];function A(t){let r=t.length;return r<=4?"****":r<=8?`${t[0]}****${t[r-1]}`:r<=16?`${t.slice(0,2)}****${t.slice(-2)}`:`${t.slice(0,4)}...${t.slice(-4)}`}function h(t,r={}){let{sensitivePatterns:a=v,customPatterns:u=[],fallbackValue:i="[REDACTED]"}=r,c=[..._,...u],l=new Set(t.values());function p(e){return a.some(n=>n.test(e))}function w(e){let n=e;for(let[,o]of t)if(typeof o=="string"&&o.length>0){let d=o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");n=n.replace(new RegExp(d,"g"),i);}for(let o of c)n=n.replace(o,i);return n}function g(e,n=0,o=new WeakSet){if(n>10||e==null)return e;if(typeof e=="string")return w(e);if(typeof e=="number"||typeof e=="bigint")return l.has(String(e))?i:e;if(typeof e!="object")return e;if(o.has(e))return "[Circular]";if(o.add(e),Array.isArray(e))return e.map(s=>g(s,n+1,o));if(e instanceof Error){let s=new Error(w(e.message));return s.name=e.name,s.stack=e.stack?w(e.stack):void 0,s}if(e instanceof Date||e instanceof RegExp)return e;if(e instanceof Map)return new Map(Array.from(e.entries()).map(([s,f])=>[g(s,n+1,o),g(f,n+1,o)]));if(e instanceof Set)return new Set(Array.from(e.values()).map(s=>g(s,n+1,o)));let d={};for(let[s,f]of Object.entries(e))p(s)?d[s]=typeof f=="string"?i:"[REDACTED]":typeof f=="string"?d[s]=w(f):d[s]=g(f,n+1,o);return d}return {redactString:w,redactObject:g,maskValue:A,createFingerprint:e=>{let n=0;for(let o=0;o<e.length;o++){let d=e.charCodeAt(o);n=(n<<5)-n+d,n=n&n;}return `sha256:${Math.abs(n).toString(16).slice(0,8)}`},shouldRedactKey:p}}function y(t,r={}){let a=new Map,u=r.sensitiveKeys?.map(i=>new RegExp(i,"i"))??v;for(let[i,c]of Object.entries(t))f(c)?d(c).forEach((l,p)=>{a.set(p===0?i:`${i}#${p}`,l);}):typeof c=="string"&&u.some(l=>l.test(i))&&a.set(i,c);return a}var R="__nodeEnvResolverPatched";function S(t,r={}){let{enabled:a=true,methods:u=["log","debug","info","warn","error","trace"],redactStrings:i=true,redactObjects:c=true,...l}=r;if(!a)return ()=>{};let p=console;if(p[R])return ()=>{};let w=y(t),g=h(w,l),e={};for(let n of u)if(typeof console[n]=="function"){e[n]=console[n].bind(console);let o=e[n];console[n]=(...d)=>{let s=d.map(f=>typeof f=="string"&&i?g.redactString(f):(typeof f=="number"||typeof f=="bigint")&&i||typeof f=="object"&&c&&f!==null?g.redactObject(f):f);o(...s);};}return Object.defineProperty(p,R,{value:true,writable:true,enumerable:false,configurable:true}),()=>{for(let n of u)if(e[n]){let d=e[n].bind(console);console[n]=d;}try{delete p[R];}catch{}p[R]=false;}}function C(t,r={}){let a=y(t),u=h(a,r);return {redact:(...i)=>i.map(c=>typeof c=="string"?u.redactString(c):typeof c=="object"&&c!==null?u.redactObject(c):c),...u}}var x=["image/","video/","audio/","application/octet-stream","application/pdf"];function T(t,r){let a=t.toLowerCase();return !r.some(u=>a.includes(u.toLowerCase()))}function b(t,r,a){if(r===t)return t;if(a==="throw")throw new Error('Secret leak detected in HTTP response body. A sensitive value was found before it could be sent. Use mode: "redact" to automatically scrub, or mode: "warn" to log and continue.');return a==="warn"?(console.warn('[node-env-resolver] Potential secret leak detected in HTTP response. Set mode: "redact" to scrub automatically.'),t):r}function z(t,r={}){let{mode:a=process.env.NODE_ENV==="production"?"warn":"throw",ignoreContentTypes:u=x,maxBodySize:i=1024*1024,...c}=r,l=y(t),p=h(l,c);return function(g,e,n){let o=e.end.bind(e);e.end=function(...d){let s=d[0];if(s!=null&&(typeof s=="string"||Buffer.isBuffer(s))){let f=String(e.getHeader?.("content-type")??"");if(T(f,u)){let k=typeof s=="string"?s:s.toString("utf8");if(Buffer.byteLength(k)<=i)try{let m=p.redactString(k);d[0]=b(k,m,a);}catch(m){if(a==="throw")throw m;console.error("[node-env-resolver] Response scan error:",m);}}}return o(...d)},n();}}async function V(t,r,a={}){let{mode:u="warn",ignoreContentTypes:i=x,maxBodySize:c=1024*1024,...l}=a,p=t.headers.get("content-type")??"";if(!T(p,i))return t;let g=await t.clone().arrayBuffer();if(g.byteLength>c)return t;let e=new TextDecoder().decode(g),n=y(r),d=h(n,l).redactString(e);if(d===e)return t;if(u==="throw")throw new Error('Secret leak detected in HTTP response. Use mode: "redact" to scrub automatically.');return u==="warn"?(console.warn("[node-env-resolver] Potential secret leak detected in HTTP response."),t):new Response(d,{status:t.status,statusText:t.statusText,headers:t.headers})}function F(t,r,a={}){if(typeof t!="string"&&!Buffer.isBuffer(t))return {safe:true};let u=y(r),i=h(u,a),c=typeof t=="string"?t:t.toString("utf8"),l=i.redactString(c);return l!==c?{safe:false,redacted:l}:{safe:true}}function H(t,r={}){return r.console===false?()=>{}:S(t,r.console)}export{C as createConsoleRedactor,h as createRedactor,z as createResponseMiddleware,y as extractSensitiveValues,S as patchGlobalConsole,H as protect,F as scanBodyForSecrets,V as wrapFetchResponse};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Patch global console methods to redact sensitive values
|
|
3
|
+
*
|
|
4
|
+
* Prevents accidental logging of secrets by intercepting console methods
|
|
5
|
+
* and redacting values matching sensitive patterns.
|
|
6
|
+
*/
|
|
7
|
+
import { type RedactorOptions } from './redactor.js';
|
|
8
|
+
export interface ConsolePatchOptions extends RedactorOptions {
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
methods?: ('log' | 'debug' | 'info' | 'warn' | 'error' | 'trace')[];
|
|
11
|
+
redactStrings?: boolean;
|
|
12
|
+
redactObjects?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function patchGlobalConsole(config: Record<string, unknown>, options?: ConsolePatchOptions): () => void;
|
|
15
|
+
export declare function createConsoleRedactor(config: Record<string, unknown>, options?: ConsolePatchOptions): {
|
|
16
|
+
redactString: (str: string) => string;
|
|
17
|
+
redactObject: (obj: unknown, depth?: number, seen?: WeakSet<object>) => unknown;
|
|
18
|
+
maskValue: (value: string) => string;
|
|
19
|
+
createFingerprint: (value: string) => string;
|
|
20
|
+
shouldRedactKey: (key: string) => boolean;
|
|
21
|
+
redact: (...args: unknown[]) => unknown[];
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=patch-console.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch-console.d.ts","sourceRoot":"","sources":["../../src/runtime/patch-console.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,eAAe,CAAC;AAEvB,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,CAAC,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC,EAAE,CAAC;IACpE,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAQD,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,GAAE,mBAAwB,GAChC,MAAM,IAAI,CA+EZ;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,GAAE,mBAAwB;;;;;;sBAMb,OAAO,EAAE;EAa9B"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redaction utilities for protecting secrets in logs and responses
|
|
3
|
+
*/
|
|
4
|
+
export interface RedactorOptions {
|
|
5
|
+
sensitiveKeys?: string[];
|
|
6
|
+
sensitivePatterns?: RegExp[];
|
|
7
|
+
customPatterns?: RegExp[];
|
|
8
|
+
fallbackValue?: string;
|
|
9
|
+
}
|
|
10
|
+
declare function maskValue(value: string): string;
|
|
11
|
+
export declare function createRedactor(sensitiveValues: Map<string, string>, options?: RedactorOptions): {
|
|
12
|
+
redactString: (str: string) => string;
|
|
13
|
+
redactObject: (obj: unknown, depth?: number, seen?: WeakSet<object>) => unknown;
|
|
14
|
+
maskValue: typeof maskValue;
|
|
15
|
+
createFingerprint: (value: string) => string;
|
|
16
|
+
shouldRedactKey: (key: string) => boolean;
|
|
17
|
+
};
|
|
18
|
+
export declare function extractSensitiveValues(config: Record<string, unknown>, options?: {
|
|
19
|
+
sensitiveKeys?: string[];
|
|
20
|
+
}): Map<string, string>;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=redactor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redactor.d.ts","sourceRoot":"","sources":["../../src/runtime/redactor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,MAAM,WAAW,eAAe;IAC9B,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAuBD,iBAAS,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMxC;AAED,wBAAgB,cAAc,CAC5B,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACpC,OAAO,GAAE,eAAoB;wBAeO,MAAM,KAAG,MAAM;wBAiBxB,OAAO,6CAAoC,OAAO;;+BAwDhD,MAAM;2BA7EL,MAAM,KAAG,OAAO;EAwF/C;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,GAAE;IAAE,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,GACzC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAkBrB"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response protection utilities for preventing secret leakage in HTTP responses
|
|
3
|
+
*
|
|
4
|
+
* Provides middleware for Node.js (Express/Connect/Hono) and a utility for
|
|
5
|
+
* Edge runtimes (Cloudflare Workers, Vercel Edge, etc.).
|
|
6
|
+
*
|
|
7
|
+
* @example Node.js / Express
|
|
8
|
+
* ```ts
|
|
9
|
+
* import express from 'express';
|
|
10
|
+
* import { createResponseMiddleware } from 'node-env-resolver/runtime';
|
|
11
|
+
*
|
|
12
|
+
* const app = express();
|
|
13
|
+
* app.use(createResponseMiddleware(config, { mode: 'throw' }));
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @example Edge runtime
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { wrapFetchResponse } from 'node-env-resolver/runtime';
|
|
19
|
+
*
|
|
20
|
+
* export default {
|
|
21
|
+
* async fetch(req, env) {
|
|
22
|
+
* const response = await handler(req);
|
|
23
|
+
* return wrapFetchResponse(response, config, { mode: 'redact' });
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
import { type RedactorOptions } from './redactor.js';
|
|
29
|
+
export interface ResponsePatchOptions extends RedactorOptions {
|
|
30
|
+
mode?: 'throw' | 'redact' | 'warn';
|
|
31
|
+
ignoreContentTypes?: string[];
|
|
32
|
+
maxBodySize?: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Express / Connect / Hono middleware that scans outgoing response bodies
|
|
36
|
+
* for sensitive values and redacts, warns, or throws depending on `mode`.
|
|
37
|
+
*
|
|
38
|
+
* Default mode: 'warn' in production, 'throw' in development.
|
|
39
|
+
*/
|
|
40
|
+
export declare function createResponseMiddleware(config: Record<string, unknown>, options?: ResponsePatchOptions): (_req: unknown, res: {
|
|
41
|
+
end: (...args: unknown[]) => unknown;
|
|
42
|
+
write?: (...args: unknown[]) => unknown;
|
|
43
|
+
getHeader?: (name: string) => string | number | string[] | undefined;
|
|
44
|
+
}, next: () => void) => void;
|
|
45
|
+
/**
|
|
46
|
+
* Scan and optionally redact an Edge runtime `Response` object.
|
|
47
|
+
* Returns a new Response (original is consumed). Safe to use in
|
|
48
|
+
* Cloudflare Workers, Vercel Edge Functions, and Deno Deploy.
|
|
49
|
+
*/
|
|
50
|
+
export declare function wrapFetchResponse(response: Response, config: Record<string, unknown>, options?: ResponsePatchOptions): Promise<Response>;
|
|
51
|
+
/**
|
|
52
|
+
* Utility to imperatively scan a response body for secrets.
|
|
53
|
+
* Useful when you need to check manually rather than via middleware.
|
|
54
|
+
*/
|
|
55
|
+
export declare function scanBodyForSecrets(body: string | Buffer | unknown, config: Record<string, unknown>, options?: ResponsePatchOptions): {
|
|
56
|
+
safe: boolean;
|
|
57
|
+
redacted?: string;
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/runtime/response.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,eAAe,CAAC;AAEvB,MAAM,WAAW,oBAAqB,SAAQ,eAAe;IAC3D,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;IACnC,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAyCD;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,GAAE,oBAAyB,UAa1B,OAAO,OACR;IACH,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;IACrC,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;IACxC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC;CACtE,QACK,MAAM,IAAI,KACf,IAAI,CA6BR;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,QAAQ,CAAC,CA6CnB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,EAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,GAAE,oBAAyB,GACjC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,CAetC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { PolicyOptions, ResolveOptions } from './types.js';
|
|
2
|
+
export interface StrictReferencePoliciesOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Variables that must come from secret managers (not dotenv/process.env fallbacks).
|
|
5
|
+
* Example: ['STRIPE_KEY', 'DATABASE_URL']
|
|
6
|
+
*/
|
|
7
|
+
sensitiveKeys: readonly string[];
|
|
8
|
+
/**
|
|
9
|
+
* Allowed resolver source(s) for sensitive keys.
|
|
10
|
+
* Matching accepts:
|
|
11
|
+
* - exact resolver/source name
|
|
12
|
+
* - source prefix before `(` (e.g. `aws-secrets(prod/app)` -> `aws-secrets`)
|
|
13
|
+
* - reference handler `resolvedVia` value
|
|
14
|
+
* Default: ['aws-secrets']
|
|
15
|
+
*/
|
|
16
|
+
secretSources?: readonly string[] | string;
|
|
17
|
+
/**
|
|
18
|
+
* Keep secure default in production: false blocks dotenv values.
|
|
19
|
+
* You can pass a whitelist array to allow specific non-secret vars from dotenv.
|
|
20
|
+
* Default: false
|
|
21
|
+
*/
|
|
22
|
+
allowDotenvInProduction?: PolicyOptions['allowDotenvInProduction'];
|
|
23
|
+
/**
|
|
24
|
+
* Optional base policy object to merge into.
|
|
25
|
+
*/
|
|
26
|
+
basePolicies?: PolicyOptions;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Build a strict production policy preset for reference-first deployments:
|
|
30
|
+
* - Blocks dotenv in production by default
|
|
31
|
+
* - Forces sensitive keys to come from reference-backed resolvers (e.g. aws-secrets)
|
|
32
|
+
*/
|
|
33
|
+
export declare function strictReferencePolicies(options: StrictReferencePoliciesOptions): PolicyOptions;
|
|
34
|
+
export interface StrictReferenceResolveOptions extends Omit<StrictReferencePoliciesOptions, 'basePolicies'> {
|
|
35
|
+
/**
|
|
36
|
+
* Optional extra resolve options to merge with this preset.
|
|
37
|
+
*/
|
|
38
|
+
baseOptions?: Partial<ResolveOptions>;
|
|
39
|
+
/**
|
|
40
|
+
* Audit should be enabled for incident response reconstruction.
|
|
41
|
+
* Default: true
|
|
42
|
+
*/
|
|
43
|
+
enableAudit?: boolean;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Resolve options preset for strict reference-first hardening.
|
|
47
|
+
*/
|
|
48
|
+
export declare function strictReferenceResolveOptions(options: StrictReferenceResolveOptions): Partial<ResolveOptions>;
|
|
49
|
+
//# sourceMappingURL=security.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../src/security.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEhE,MAAM,WAAW,8BAA8B;IAC7C;;;OAGG;IACH,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC;IAC3C;;;;OAIG;IACH,uBAAuB,CAAC,EAAE,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACnE;;OAEG;IACH,YAAY,CAAC,EAAE,aAAa,CAAC;CAC9B;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,8BAA8B,GACtC,aAAa,CAyBf;AAED,MAAM,WAAW,6BACf,SAAQ,IAAI,CAAC,8BAA8B,EAAE,cAAc,CAAC;IAC5D;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;IACtC;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,6BAA6B,GACrC,OAAO,CAAC,cAAc,CAAC,CAqBzB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for "is this value sensitive?".
|
|
3
|
+
*
|
|
4
|
+
* Explicit metadata wins: values produced by validators marked sensitive
|
|
5
|
+
* (secret(), file(), connection-string validators) are registered here when
|
|
6
|
+
* resolved. Key-name heuristics are only a fallback.
|
|
7
|
+
*/
|
|
8
|
+
/** Key-name heuristics used when no explicit metadata exists. */
|
|
9
|
+
export declare const DEFAULT_SENSITIVE_PATTERNS: readonly RegExp[];
|
|
10
|
+
export declare function isSensitiveKeyName(key: string, patterns?: readonly RegExp[]): boolean;
|
|
11
|
+
/** True when a validator/definition is explicitly marked sensitive. */
|
|
12
|
+
export declare function isSensitiveValidator(v: unknown): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* String forms of a value that must be treated as secret: the value itself
|
|
15
|
+
* (numbers stringified, objects as JSON) plus every primitive leaf
|
|
16
|
+
* of an object/array, so `json()` secrets are covered field by field.
|
|
17
|
+
*/
|
|
18
|
+
export declare function sensitiveForms(value: unknown, depth?: number): string[];
|
|
19
|
+
/** Register a resolved value (any type) as sensitive. */
|
|
20
|
+
export declare function markSensitiveValue(value: unknown): void;
|
|
21
|
+
/**
|
|
22
|
+
* True when `value` is a registered sensitive value, or is derived from one
|
|
23
|
+
* (contains it, e.g. a URL built by interpolation or withComputed()).
|
|
24
|
+
* Non-strings are compared by their string/JSON form.
|
|
25
|
+
*/
|
|
26
|
+
export declare function isSensitiveValue(value: unknown): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Keys whose values are secrets or derived from one (explicit metadata only).
|
|
29
|
+
* Used by framework adapters to keep secrets out of client bundles.
|
|
30
|
+
*/
|
|
31
|
+
export declare function findSensitiveKeys(values: Record<string, unknown>): string[];
|
|
32
|
+
/** Test helper: forget registered values. */
|
|
33
|
+
export declare function clearSensitiveValues(): void;
|
|
34
|
+
//# sourceMappingURL=sensitivity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sensitivity.d.ts","sourceRoot":"","sources":["../src/sensitivity.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,iEAAiE;AACjE,eAAO,MAAM,0BAA0B,EAAE,SAAS,MAAM,EAcvD,CAAC;AAEF,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,EACX,QAAQ,GAAE,SAAS,MAAM,EAA+B,GACvD,OAAO,CAET;AAED,uEAAuE;AACvE,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAMxD;AAaD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,SAAI,GAAG,MAAM,EAAE,CAclE;AAED,yDAAyD;AACzD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAGvD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAWxD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EAAE,CAI3E;AAED,6CAA6C;AAC7C,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C"}
|