@holo-js/security 0.1.3 → 0.1.5
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/{chunk-3J5QRTPZ.mjs → chunk-EWQKJSFA.mjs} +8 -11
- package/dist/chunk-FUOZWKHK.mjs +79 -0
- package/dist/chunk-Q3A7RJ67.mjs +1171 -0
- package/dist/client.d.ts +6 -11
- package/dist/client.mjs +10 -37
- package/dist/contracts.d.ts +17 -10
- package/dist/contracts.mjs +1 -1
- package/dist/drivers/redis-adapter.d.ts +2 -0
- package/dist/drivers/redis-adapter.mjs +32 -3
- package/dist/index.d.ts +62 -10
- package/dist/index.mjs +44 -866
- package/dist/next/server.d.ts +16 -0
- package/dist/next/server.mjs +84 -0
- package/dist/nuxt/server.d.ts +11 -0
- package/dist/nuxt/server.mjs +109 -0
- package/dist/sveltekit/server.d.ts +37 -0
- package/dist/sveltekit/server.mjs +68 -0
- package/package.json +31 -6
package/dist/client.d.ts
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SecurityClientConfig } from './contracts.js';
|
|
2
2
|
import '@holo-js/config';
|
|
3
3
|
|
|
4
|
-
type RuntimeSecurityClientState = {
|
|
5
|
-
bindings?: SecurityClientConfig;
|
|
6
|
-
};
|
|
7
4
|
declare function getDefaultSecurityClientConfig(): SecurityClientConfig;
|
|
8
|
-
declare function
|
|
9
|
-
|
|
10
|
-
declare function configureSecurityClient(bindings?: SecurityClientBindings): void;
|
|
5
|
+
declare function readSecurityClientConfigFromCookies(cookieHeader: string | null | undefined): SecurityClientConfig | undefined;
|
|
6
|
+
|
|
11
7
|
declare function getSecurityClientConfig(): SecurityClientConfig;
|
|
12
|
-
declare function resetSecurityClient(): void;
|
|
13
8
|
declare const securityClientInternals: {
|
|
9
|
+
parseCookieHeader: (header: string | null | undefined) => Readonly<Record<string, string>>;
|
|
14
10
|
getDefaultSecurityClientConfig: typeof getDefaultSecurityClientConfig;
|
|
15
|
-
|
|
16
|
-
normalizeSecurityClientConfig: typeof normalizeSecurityClientConfig;
|
|
11
|
+
readSecurityClientConfigFromCookies: typeof readSecurityClientConfigFromCookies;
|
|
17
12
|
};
|
|
18
13
|
|
|
19
|
-
export {
|
|
14
|
+
export { SecurityClientConfig, getSecurityClientConfig, securityClientInternals };
|
package/dist/client.mjs
CHANGED
|
@@ -1,47 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getDefaultSecurityClientConfig,
|
|
3
|
+
readSecurityClientConfigFromCookies,
|
|
4
|
+
securityClientConfigInternals
|
|
5
|
+
} from "./chunk-FUOZWKHK.mjs";
|
|
6
|
+
|
|
1
7
|
// src/client.ts
|
|
2
|
-
import { normalizeSecurityConfig } from "@holo-js/config";
|
|
3
|
-
var DEFAULT_SECURITY_CONFIG = normalizeSecurityConfig({});
|
|
4
|
-
var DEFAULT_SECURITY_CLIENT_CONFIG = Object.freeze({
|
|
5
|
-
csrf: Object.freeze({
|
|
6
|
-
field: DEFAULT_SECURITY_CONFIG.csrf.field,
|
|
7
|
-
cookie: DEFAULT_SECURITY_CONFIG.csrf.cookie
|
|
8
|
-
})
|
|
9
|
-
});
|
|
10
|
-
function getDefaultSecurityClientConfig() {
|
|
11
|
-
return DEFAULT_SECURITY_CLIENT_CONFIG;
|
|
12
|
-
}
|
|
13
|
-
function getSecurityClientState() {
|
|
14
|
-
const runtime = globalThis;
|
|
15
|
-
runtime.__holoSecurityClient__ ??= {};
|
|
16
|
-
return runtime.__holoSecurityClient__;
|
|
17
|
-
}
|
|
18
|
-
function normalizeSecurityClientConfig(bindings) {
|
|
19
|
-
const defaults = getDefaultSecurityClientConfig();
|
|
20
|
-
const csrf = Object.freeze({
|
|
21
|
-
field: bindings?.config?.csrf?.field ?? defaults.csrf.field,
|
|
22
|
-
cookie: bindings?.config?.csrf?.cookie ?? defaults.csrf.cookie
|
|
23
|
-
});
|
|
24
|
-
return Object.freeze({
|
|
25
|
-
csrf
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
function configureSecurityClient(bindings) {
|
|
29
|
-
getSecurityClientState().bindings = bindings ? normalizeSecurityClientConfig(bindings) : void 0;
|
|
30
|
-
}
|
|
31
8
|
function getSecurityClientConfig() {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
function resetSecurityClient() {
|
|
35
|
-
getSecurityClientState().bindings = void 0;
|
|
9
|
+
const runtime = globalThis;
|
|
10
|
+
return readSecurityClientConfigFromCookies(runtime.document?.cookie) ?? getDefaultSecurityClientConfig();
|
|
36
11
|
}
|
|
37
12
|
var securityClientInternals = {
|
|
38
13
|
getDefaultSecurityClientConfig,
|
|
39
|
-
|
|
40
|
-
|
|
14
|
+
readSecurityClientConfigFromCookies,
|
|
15
|
+
...securityClientConfigInternals
|
|
41
16
|
};
|
|
42
17
|
export {
|
|
43
|
-
configureSecurityClient,
|
|
44
18
|
getSecurityClientConfig,
|
|
45
|
-
resetSecurityClient,
|
|
46
19
|
securityClientInternals
|
|
47
20
|
};
|
package/dist/contracts.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { HoloSecurityConfig, NormalizedHoloSecurityConfig, SecurityRateLimitFileConfig, SecurityRateLimitMemoryConfig, SecurityRateLimitRedisConfig, SecurityLimiterConfig, SecurityRateLimitKeyResolver } from '@holo-js/config';
|
|
2
|
-
export { HoloSecurityConfig, HoloSecurityCsrfConfig, HoloSecurityRateLimitConfig, NormalizedHoloSecurityConfig, NormalizedHoloSecurityCsrfConfig, NormalizedHoloSecurityRateLimitConfig, NormalizedSecurityLimiterConfig, SecurityLimiterConfig, SecurityRateLimitContext, SecurityRateLimitDriver, SecurityRateLimitFileConfig, SecurityRateLimitKeyResolver, SecurityRateLimitMemoryConfig, SecurityRateLimitRedisConfig } from '@holo-js/config';
|
|
1
|
+
import { HoloSecurityConfig, NormalizedHoloSecurityConfig, HoloCorsConfig, NormalizedHoloCorsConfig, SecurityRateLimitFileConfig, SecurityRateLimitMemoryConfig, SecurityRateLimitRedisConfig, SecurityLimiterConfig, SecurityRateLimitKeyResolver } from '@holo-js/config';
|
|
2
|
+
export { HoloCorsConfig, HoloSecurityConfig, HoloSecurityCsrfConfig, HoloSecurityRateLimitConfig, NormalizedHoloCorsConfig, NormalizedHoloSecurityConfig, NormalizedHoloSecurityCsrfConfig, NormalizedHoloSecurityRateLimitConfig, NormalizedSecurityLimiterConfig, SecurityLimiterConfig, SecurityRateLimitContext, SecurityRateLimitDriver, SecurityRateLimitFileConfig, SecurityRateLimitKeyResolver, SecurityRateLimitMemoryConfig, SecurityRateLimitRedisConfig } from '@holo-js/config';
|
|
3
3
|
|
|
4
4
|
interface SecurityRuntimeBindings {
|
|
5
5
|
readonly config: HoloSecurityConfig | NormalizedHoloSecurityConfig;
|
|
6
|
+
readonly cors?: HoloCorsConfig | NormalizedHoloCorsConfig;
|
|
6
7
|
readonly rateLimitStore?: SecurityRateLimitStore;
|
|
7
8
|
readonly csrfSigningKey?: string;
|
|
8
9
|
readonly defaultKeyResolver?: SecurityDefaultRateLimitKeyResolver;
|
|
9
10
|
}
|
|
10
11
|
interface SecurityRuntimeFacade {
|
|
11
12
|
readonly config: NormalizedHoloSecurityConfig;
|
|
13
|
+
readonly cors: NormalizedHoloCorsConfig;
|
|
12
14
|
readonly rateLimitStore?: SecurityRateLimitStore;
|
|
13
15
|
readonly csrfSigningKey?: string;
|
|
14
16
|
readonly defaultKeyResolver?: SecurityDefaultRateLimitKeyResolver;
|
|
@@ -19,15 +21,15 @@ interface SecurityClientConfig {
|
|
|
19
21
|
readonly cookie: string;
|
|
20
22
|
};
|
|
21
23
|
}
|
|
22
|
-
interface SecurityClientBindings {
|
|
23
|
-
readonly config?: {
|
|
24
|
-
readonly csrf?: Partial<SecurityClientConfig['csrf']>;
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
24
|
interface SecurityCsrfField {
|
|
28
25
|
readonly name: string;
|
|
29
26
|
readonly value: string;
|
|
30
27
|
}
|
|
28
|
+
interface SecurityCsrfInput {
|
|
29
|
+
readonly type: 'hidden';
|
|
30
|
+
readonly name: string;
|
|
31
|
+
readonly value: string;
|
|
32
|
+
}
|
|
31
33
|
interface SecurityProtectOptions {
|
|
32
34
|
readonly csrf?: boolean;
|
|
33
35
|
readonly throttle?: string;
|
|
@@ -45,9 +47,15 @@ interface SecurityClearRateLimitOptions {
|
|
|
45
47
|
interface SecurityCsrfFacade {
|
|
46
48
|
token(request: Request): Promise<string>;
|
|
47
49
|
field(request: Request): Promise<SecurityCsrfField>;
|
|
50
|
+
input(request: Request): Promise<SecurityCsrfInput>;
|
|
48
51
|
cookie(request: Request, token?: string): Promise<string>;
|
|
49
52
|
verify(request: Request): Promise<void>;
|
|
50
53
|
}
|
|
54
|
+
interface SecurityCorsFacade {
|
|
55
|
+
headers(request: Request): Headers;
|
|
56
|
+
preflight(request: Request): Response | null;
|
|
57
|
+
apply(request: Request, response?: Response): Response;
|
|
58
|
+
}
|
|
51
59
|
interface SecurityRateLimitBucketSnapshot {
|
|
52
60
|
readonly limiter: string;
|
|
53
61
|
readonly key: string;
|
|
@@ -112,7 +120,6 @@ declare class PendingSecurityLimiterDefinition<TValues extends Readonly<Record<s
|
|
|
112
120
|
define(): SecurityLimiterConfig<TValues>;
|
|
113
121
|
}
|
|
114
122
|
declare function normalizeLimiterAttempts(value: number, label: string): number;
|
|
115
|
-
declare function normalizeLimiterWindowSeconds(value: number, label: string): number;
|
|
116
123
|
declare const limit: Readonly<{
|
|
117
124
|
perMinute(maxAttempts: number): PendingSecurityLimiterDefinition<Readonly<Record<string, unknown>> | undefined>;
|
|
118
125
|
perHour(maxAttempts: number): PendingSecurityLimiterDefinition<Readonly<Record<string, unknown>> | undefined>;
|
|
@@ -121,6 +128,7 @@ declare function ip(request: Request, trustedProxy?: boolean): string;
|
|
|
121
128
|
declare function defineRateLimiter<TValues extends Readonly<Record<string, unknown>> | undefined = Readonly<Record<string, unknown>> | undefined>(definition: SecurityLimiterConfig<TValues>): SecurityLimiterConfig<TValues>;
|
|
122
129
|
declare function defineSecurityRuntimeBindings(bindings: SecurityRuntimeBindings): Readonly<{
|
|
123
130
|
config: NormalizedHoloSecurityConfig;
|
|
131
|
+
cors: NormalizedHoloCorsConfig;
|
|
124
132
|
rateLimitStore?: SecurityRateLimitStore;
|
|
125
133
|
csrfSigningKey?: string;
|
|
126
134
|
defaultKeyResolver?: SecurityDefaultRateLimitKeyResolver;
|
|
@@ -131,7 +139,6 @@ declare function createRedisRateLimitStoreConfig(config?: SecurityRateLimitRedis
|
|
|
131
139
|
declare const securityInternals: {
|
|
132
140
|
PendingSecurityLimiterDefinition: typeof PendingSecurityLimiterDefinition;
|
|
133
141
|
normalizeLimiterAttempts: typeof normalizeLimiterAttempts;
|
|
134
|
-
normalizeLimiterWindowSeconds: typeof normalizeLimiterWindowSeconds;
|
|
135
142
|
};
|
|
136
143
|
|
|
137
|
-
export { type SecurityClearRateLimitOptions, type
|
|
144
|
+
export { type SecurityClearRateLimitOptions, type SecurityClientConfig, type SecurityCorsFacade, SecurityCsrfError, type SecurityCsrfFacade, type SecurityCsrfField, type SecurityCsrfInput, type SecurityDefaultRateLimitKeyResolver, type SecurityProtectOptions, type SecurityRateLimitBucketSnapshot, type SecurityRateLimitCallOptions, SecurityRateLimitError, type SecurityRateLimitHitResult, type SecurityRateLimitRedisDriverAdapter, type SecurityRateLimitStore, type SecurityRateLimitStoreFactoryOptions, type SecurityRuntimeBindings, type SecurityRuntimeFacade, createFileRateLimitStoreConfig, createMemoryRateLimitStoreConfig, createRedisRateLimitStoreConfig, defineRateLimiter, defineSecurityRuntimeBindings, ip, limit, securityInternals };
|
package/dist/contracts.mjs
CHANGED
|
@@ -39,6 +39,8 @@ declare class RedisSecurityAdapter implements SecurityRateLimitRedisDriverAdapte
|
|
|
39
39
|
private qualifyKey;
|
|
40
40
|
private qualifyPattern;
|
|
41
41
|
private normalizeScanResponse;
|
|
42
|
+
private clearMatchingKeysForClient;
|
|
43
|
+
private clearMatchingKeysForCluster;
|
|
42
44
|
private clearMatchingKeys;
|
|
43
45
|
private parseOldestScore;
|
|
44
46
|
private getCommandValue;
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
import { randomUUID } from "crypto";
|
|
3
3
|
import Redis from "ioredis";
|
|
4
4
|
var REDIS_SCAN_COUNT = 100;
|
|
5
|
+
function isRedisClusterClientLike(client) {
|
|
6
|
+
return typeof client.nodes === "function";
|
|
7
|
+
}
|
|
5
8
|
function isRedisConnectionTarget(value) {
|
|
6
9
|
return value.startsWith("redis://") || value.startsWith("rediss://") || value.startsWith("unix://") || value.startsWith("/");
|
|
7
10
|
}
|
|
@@ -106,11 +109,11 @@ var RedisSecurityAdapter = class {
|
|
|
106
109
|
keys
|
|
107
110
|
};
|
|
108
111
|
}
|
|
109
|
-
async
|
|
112
|
+
async clearMatchingKeysForClient(client, pattern) {
|
|
110
113
|
let cursor = "0";
|
|
111
114
|
let cleared = 0;
|
|
112
115
|
do {
|
|
113
|
-
const page = this.normalizeScanResponse(await
|
|
116
|
+
const page = this.normalizeScanResponse(await client.scan(
|
|
114
117
|
cursor,
|
|
115
118
|
"MATCH",
|
|
116
119
|
pattern,
|
|
@@ -119,11 +122,37 @@ var RedisSecurityAdapter = class {
|
|
|
119
122
|
));
|
|
120
123
|
cursor = page.cursor;
|
|
121
124
|
if (page.keys.length > 0) {
|
|
122
|
-
cleared += await
|
|
125
|
+
cleared += await client.del(...page.keys);
|
|
123
126
|
}
|
|
124
127
|
} while (cursor !== "0");
|
|
125
128
|
return cleared;
|
|
126
129
|
}
|
|
130
|
+
async clearMatchingKeysForCluster(client, pattern) {
|
|
131
|
+
let cleared = 0;
|
|
132
|
+
for (const node of client.nodes("master")) {
|
|
133
|
+
let cursor = "0";
|
|
134
|
+
do {
|
|
135
|
+
const page = this.normalizeScanResponse(await node.scan(
|
|
136
|
+
cursor,
|
|
137
|
+
"MATCH",
|
|
138
|
+
pattern,
|
|
139
|
+
"COUNT",
|
|
140
|
+
REDIS_SCAN_COUNT
|
|
141
|
+
));
|
|
142
|
+
cursor = page.cursor;
|
|
143
|
+
for (const key of page.keys) {
|
|
144
|
+
cleared += await node.del(key);
|
|
145
|
+
}
|
|
146
|
+
} while (cursor !== "0");
|
|
147
|
+
}
|
|
148
|
+
return cleared;
|
|
149
|
+
}
|
|
150
|
+
async clearMatchingKeys(pattern) {
|
|
151
|
+
if (isRedisClusterClientLike(this.client)) {
|
|
152
|
+
return await this.clearMatchingKeysForCluster(this.client, pattern);
|
|
153
|
+
}
|
|
154
|
+
return await this.clearMatchingKeysForClient(this.client, pattern);
|
|
155
|
+
}
|
|
127
156
|
parseOldestScore(result) {
|
|
128
157
|
if (!Array.isArray(result) || result.length < 2) {
|
|
129
158
|
throw new Error("[@holo-js/security] Redis transaction failed to return the oldest rate-limit hit.");
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import * as _holo_js_config from '@holo-js/config';
|
|
2
|
-
import { NormalizedSecurityLimiterConfig, HoloSecurityConfig, NormalizedHoloSecurityConfig } from '@holo-js/config';
|
|
3
|
-
export { HoloSecurityConfig, HoloSecurityCsrfConfig, HoloSecurityRateLimitConfig, NormalizedHoloSecurityConfig, NormalizedHoloSecurityCsrfConfig, NormalizedHoloSecurityRateLimitConfig, NormalizedSecurityLimiterConfig, SecurityLimiterConfig, SecurityRateLimitContext, SecurityRateLimitDriver, SecurityRateLimitFileConfig, SecurityRateLimitKeyResolver, SecurityRateLimitMemoryConfig, SecurityRateLimitRedisConfig, defineSecurityConfig } from '@holo-js/config';
|
|
4
|
-
import { SecurityCsrfField, SecurityProtectOptions, SecurityClearRateLimitOptions, SecurityRateLimitCallOptions, SecurityRateLimitHitResult, SecurityRateLimitStore, SecurityRateLimitStoreFactoryOptions, SecurityRateLimitRedisDriverAdapter, SecurityRuntimeBindings, SecurityRuntimeFacade, ip } from './contracts.js';
|
|
5
|
-
export {
|
|
2
|
+
import { NormalizedHoloCorsConfig, NormalizedSecurityLimiterConfig, HoloSecurityConfig, NormalizedHoloSecurityConfig } from '@holo-js/config';
|
|
3
|
+
export { HoloCorsConfig, HoloSecurityConfig, HoloSecurityCsrfConfig, HoloSecurityRateLimitConfig, NormalizedHoloCorsConfig, NormalizedHoloSecurityConfig, NormalizedHoloSecurityCsrfConfig, NormalizedHoloSecurityRateLimitConfig, NormalizedSecurityLimiterConfig, SecurityLimiterConfig, SecurityRateLimitContext, SecurityRateLimitDriver, SecurityRateLimitFileConfig, SecurityRateLimitKeyResolver, SecurityRateLimitMemoryConfig, SecurityRateLimitRedisConfig, defineSecurityConfig } from '@holo-js/config';
|
|
4
|
+
import { SecurityCsrfField, SecurityCsrfInput, SecurityProtectOptions, SecurityClearRateLimitOptions, SecurityRateLimitCallOptions, SecurityRateLimitHitResult, SecurityRateLimitStore, SecurityRateLimitStoreFactoryOptions, SecurityRateLimitRedisDriverAdapter, SecurityRuntimeBindings, SecurityRuntimeFacade, ip } from './contracts.js';
|
|
5
|
+
export { SecurityClientConfig, SecurityCorsFacade, SecurityCsrfError, SecurityCsrfFacade, SecurityDefaultRateLimitKeyResolver, SecurityRateLimitBucketSnapshot, SecurityRateLimitError, createFileRateLimitStoreConfig, createMemoryRateLimitStoreConfig, createRedisRateLimitStoreConfig, defineRateLimiter, defineSecurityRuntimeBindings, limit, securityInternals } from './contracts.js';
|
|
6
6
|
|
|
7
7
|
declare function parseCookieHeader(header: string | null | undefined): Readonly<Record<string, string>>;
|
|
8
8
|
declare function serializeCookie(name: string, value: string, options?: {
|
|
9
9
|
readonly secure?: boolean;
|
|
10
10
|
}): string;
|
|
11
11
|
declare function isSafeMethod(method: string): boolean;
|
|
12
|
-
declare function matchesPathPattern(pathname: string, pattern: string): boolean;
|
|
12
|
+
declare function matchesPathPattern$1(pathname: string, pattern: string): boolean;
|
|
13
13
|
declare function isExcludedPath(request: Request): boolean;
|
|
14
|
+
declare function getForwardedProto(request: Request): string | undefined;
|
|
15
|
+
declare function isSecureRequest(request: Request): boolean;
|
|
14
16
|
declare function createCsrfToken(): string;
|
|
15
17
|
declare function getCsrfSigningKey(): string;
|
|
16
18
|
declare function encodeCsrfToken(nonce: string): string;
|
|
@@ -20,26 +22,34 @@ declare function decodeCsrfToken(token: string): {
|
|
|
20
22
|
} | null;
|
|
21
23
|
declare function isValidSignedCsrfToken(token: string): boolean;
|
|
22
24
|
declare function getCookieToken(request: Request): string | undefined;
|
|
23
|
-
declare function
|
|
25
|
+
declare function getHeaderToken(request: Request): string | undefined;
|
|
26
|
+
declare function isSameOriginRequest(request: Request): boolean;
|
|
27
|
+
declare function readFormToken(request: Request): Promise<string | undefined>;
|
|
24
28
|
declare function token(request: Request): Promise<string>;
|
|
25
29
|
declare function field(request: Request): Promise<SecurityCsrfField>;
|
|
30
|
+
declare function input(request: Request): Promise<SecurityCsrfInput>;
|
|
26
31
|
declare function cookie(request: Request, explicitToken?: string): Promise<string>;
|
|
27
32
|
declare function verify(request: Request): Promise<void>;
|
|
28
33
|
declare function protect(request: Request, options?: SecurityProtectOptions): Promise<void>;
|
|
29
34
|
declare const csrf: Readonly<{
|
|
30
35
|
token: typeof token;
|
|
31
36
|
field: typeof field;
|
|
37
|
+
input: typeof input;
|
|
32
38
|
cookie: typeof cookie;
|
|
33
39
|
verify: typeof verify;
|
|
34
40
|
}>;
|
|
35
41
|
declare const csrfInternals: {
|
|
36
42
|
createCsrfToken: typeof createCsrfToken;
|
|
37
43
|
generatedTokenCache: WeakMap<Request, string>;
|
|
44
|
+
getForwardedProto: typeof getForwardedProto;
|
|
38
45
|
getCookieToken: typeof getCookieToken;
|
|
39
|
-
|
|
46
|
+
getHeaderToken: typeof getHeaderToken;
|
|
47
|
+
isSecureRequest: typeof isSecureRequest;
|
|
48
|
+
isSameOriginRequest: typeof isSameOriginRequest;
|
|
49
|
+
readFormToken: typeof readFormToken;
|
|
40
50
|
isExcludedPath: typeof isExcludedPath;
|
|
41
51
|
isSafeMethod: typeof isSafeMethod;
|
|
42
|
-
matchesPathPattern: typeof matchesPathPattern;
|
|
52
|
+
matchesPathPattern: typeof matchesPathPattern$1;
|
|
43
53
|
parseCookieHeader: typeof parseCookieHeader;
|
|
44
54
|
serializeCookie: typeof serializeCookie;
|
|
45
55
|
decodeCsrfToken: typeof decodeCsrfToken;
|
|
@@ -48,6 +58,29 @@ declare const csrfInternals: {
|
|
|
48
58
|
isValidSignedCsrfToken: typeof isValidSignedCsrfToken;
|
|
49
59
|
};
|
|
50
60
|
|
|
61
|
+
declare function matchesPathPattern(pathname: string, pattern: string): boolean;
|
|
62
|
+
declare function normalizeDomain(value: string): string;
|
|
63
|
+
declare function isCorsPath(config: NormalizedHoloCorsConfig, request: Request): boolean;
|
|
64
|
+
declare function isStatefulOrigin(config: NormalizedHoloCorsConfig, origin: string): boolean;
|
|
65
|
+
declare function resolveAllowedOrigin(config: NormalizedHoloCorsConfig, origin: string | null): string | undefined;
|
|
66
|
+
declare function appendVary(headers: Headers, value: string): void;
|
|
67
|
+
declare function headers(request: Request): Headers;
|
|
68
|
+
declare function apply(request: Request, response?: Response): Response;
|
|
69
|
+
declare function preflight(request: Request): Response | null;
|
|
70
|
+
declare const cors: Readonly<{
|
|
71
|
+
headers: typeof headers;
|
|
72
|
+
preflight: typeof preflight;
|
|
73
|
+
apply: typeof apply;
|
|
74
|
+
}>;
|
|
75
|
+
declare const corsInternals: {
|
|
76
|
+
appendVary: typeof appendVary;
|
|
77
|
+
isCorsPath: typeof isCorsPath;
|
|
78
|
+
isStatefulOrigin: typeof isStatefulOrigin;
|
|
79
|
+
matchesPathPattern: typeof matchesPathPattern;
|
|
80
|
+
normalizeDomain: typeof normalizeDomain;
|
|
81
|
+
resolveAllowedOrigin: typeof resolveAllowedOrigin;
|
|
82
|
+
};
|
|
83
|
+
|
|
51
84
|
declare function encodeBucketPart(value: string): string;
|
|
52
85
|
declare function createLimiterPrefix(limiter: string): string;
|
|
53
86
|
declare function createBucketKey(limiter: string, key: string): string;
|
|
@@ -76,12 +109,16 @@ declare const securityStoreInternals: {
|
|
|
76
109
|
};
|
|
77
110
|
|
|
78
111
|
type FileRateLimitBucket = {
|
|
79
|
-
|
|
112
|
+
namespaceHash: string;
|
|
80
113
|
keyHash: string;
|
|
81
114
|
prefixHashes: readonly string[];
|
|
82
115
|
attempts: number;
|
|
83
116
|
expiresAt: Date;
|
|
84
117
|
};
|
|
118
|
+
type FileBucketLock = {
|
|
119
|
+
readonly ownerId: string;
|
|
120
|
+
readonly path: string;
|
|
121
|
+
};
|
|
85
122
|
interface FileRateLimitStoreOptions {
|
|
86
123
|
readonly now?: () => Date;
|
|
87
124
|
readonly lockRetryDelayMs?: number;
|
|
@@ -97,6 +134,12 @@ declare function writeBucket(path: string, bucket: FileRateLimitBucket): Promise
|
|
|
97
134
|
declare function deleteBucket(path: string): Promise<void>;
|
|
98
135
|
declare function getBucketLockPath(path: string): string;
|
|
99
136
|
declare function sleep(delayMs: number): Promise<void>;
|
|
137
|
+
declare function removeOwnedBucketLock(lock: FileBucketLock): Promise<void>;
|
|
138
|
+
declare function reclaimStaleBucketLock(lockPath: string, timeoutMs: number): Promise<boolean>;
|
|
139
|
+
declare function acquireBucketLock(lockPath: string, options: {
|
|
140
|
+
readonly retryDelayMs: number;
|
|
141
|
+
readonly timeoutMs: number;
|
|
142
|
+
}): Promise<FileBucketLock>;
|
|
100
143
|
declare function withBucketLock<TValue>(path: string, options: {
|
|
101
144
|
readonly retryDelayMs: number;
|
|
102
145
|
readonly timeoutMs: number;
|
|
@@ -116,6 +159,9 @@ declare const fileRateLimitDriverInternals: {
|
|
|
116
159
|
serializeBucket: typeof serializeBucket;
|
|
117
160
|
sleep: typeof sleep;
|
|
118
161
|
getBucketLockPath: typeof getBucketLockPath;
|
|
162
|
+
acquireBucketLock: typeof acquireBucketLock;
|
|
163
|
+
reclaimStaleBucketLock: typeof reclaimStaleBucketLock;
|
|
164
|
+
removeOwnedBucketLock: typeof removeOwnedBucketLock;
|
|
119
165
|
withBucketLock: typeof withBucketLock;
|
|
120
166
|
writeBucket: typeof writeBucket;
|
|
121
167
|
};
|
|
@@ -172,9 +218,15 @@ declare const security: Readonly<{
|
|
|
172
218
|
csrf: Readonly<{
|
|
173
219
|
token: typeof token;
|
|
174
220
|
field: typeof field;
|
|
221
|
+
input: typeof input;
|
|
175
222
|
cookie: typeof cookie;
|
|
176
223
|
verify: typeof verify;
|
|
177
224
|
}>;
|
|
225
|
+
cors: Readonly<{
|
|
226
|
+
headers: typeof headers;
|
|
227
|
+
preflight: typeof preflight;
|
|
228
|
+
apply: typeof apply;
|
|
229
|
+
}>;
|
|
178
230
|
protect: typeof protect;
|
|
179
231
|
defaultRateLimitKey: typeof defaultRateLimitKey;
|
|
180
232
|
rateLimit: typeof rateLimit;
|
|
@@ -196,4 +248,4 @@ declare const security: Readonly<{
|
|
|
196
248
|
ip: typeof ip;
|
|
197
249
|
}>;
|
|
198
250
|
|
|
199
|
-
export { SecurityClearRateLimitOptions, SecurityCsrfField, SecurityProtectOptions, SecurityRateLimitCallOptions, SecurityRateLimitHitResult, SecurityRateLimitRedisDriverAdapter, SecurityRateLimitStore, SecurityRateLimitStoreFactoryOptions, SecurityRuntimeBindings, SecurityRuntimeFacade, SecurityRuntimeNotConfiguredError, clearRateLimit, configureSecurityRuntime, cookie as createCsrfCookie, field as createCsrfField, token as createCsrfToken, createFileRateLimitStore, createMemoryRateLimitStore, createRateLimitStoreFromConfig, createRedisRateLimitStore, csrf, csrfInternals, security as default, defaultRateLimitKey, fileRateLimitDriverInternals, getSecurityRuntime, getSecurityRuntimeBindings, ip, memoryRateLimitDriverInternals, protect, rateLimit, rateLimitInternals, redisRateLimitDriverInternals, resetSecurityRuntime, securityRuntimeInternals, securityStoreInternals, verify as verifyCsrfRequest };
|
|
251
|
+
export { SecurityClearRateLimitOptions, SecurityCsrfField, SecurityCsrfInput, SecurityProtectOptions, SecurityRateLimitCallOptions, SecurityRateLimitHitResult, SecurityRateLimitRedisDriverAdapter, SecurityRateLimitStore, SecurityRateLimitStoreFactoryOptions, SecurityRuntimeBindings, SecurityRuntimeFacade, SecurityRuntimeNotConfiguredError, apply as applyCors, clearRateLimit, configureSecurityRuntime, cors, corsInternals, headers as createCorsHeaders, preflight as createCorsPreflightResponse, cookie as createCsrfCookie, field as createCsrfField, input as createCsrfInput, token as createCsrfToken, createFileRateLimitStore, createMemoryRateLimitStore, createRateLimitStoreFromConfig, createRedisRateLimitStore, csrf, csrfInternals, security as default, defaultRateLimitKey, fileRateLimitDriverInternals, getSecurityRuntime, getSecurityRuntimeBindings, ip, isSecureRequest, memoryRateLimitDriverInternals, protect, rateLimit, rateLimitInternals, redisRateLimitDriverInternals, resetSecurityRuntime, securityRuntimeInternals, securityStoreInternals, verify as verifyCsrfRequest };
|