@netacea/netaceaintegrationbase 2.0.52 → 2.0.54
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/index.cjs +43 -3
- package/dist/index.d.ts +23 -1
- package/dist/index.mjs +43 -4
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -122,7 +122,8 @@ const matchMap = {
|
|
|
122
122
|
6: 'organisation_',
|
|
123
123
|
7: 'asn_',
|
|
124
124
|
8: 'country_',
|
|
125
|
-
9: 'combination_'
|
|
125
|
+
9: 'combination_',
|
|
126
|
+
11: 'headerFP_' // b (base36)
|
|
126
127
|
};
|
|
127
128
|
const mitigateMap = {
|
|
128
129
|
0: '',
|
|
@@ -202,7 +203,7 @@ var dictionary = /*#__PURE__*/Object.freeze({
|
|
|
202
203
|
// & a new MITIGATE cookie will be set
|
|
203
204
|
const ingestIgnoredIpValue = 'ignored';
|
|
204
205
|
const BASE_62_CHARSET = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
|
|
205
|
-
const mitataCookieRegExp = /^(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/((\d)(\d)(\d))
|
|
206
|
+
const mitataCookieRegExp = /^(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/((\d|[a-z])(\d)(\d))$/i;
|
|
206
207
|
function matchMitataCookie(netaceaCookie) {
|
|
207
208
|
if (netaceaCookie === undefined) {
|
|
208
209
|
return undefined;
|
|
@@ -216,7 +217,7 @@ function matchMitataCookie(netaceaCookie) {
|
|
|
216
217
|
userId,
|
|
217
218
|
ipHash,
|
|
218
219
|
mitigationType,
|
|
219
|
-
match: parseInt(match),
|
|
220
|
+
match: parseInt(match, 36),
|
|
220
221
|
mitigate: parseInt(mitigate),
|
|
221
222
|
captcha: parseInt(captcha)
|
|
222
223
|
};
|
|
@@ -591,6 +592,45 @@ const lib = {
|
|
|
591
592
|
}
|
|
592
593
|
};
|
|
593
594
|
|
|
595
|
+
class HashGenerator {
|
|
596
|
+
constructor(crypto) {
|
|
597
|
+
this.crypto = crypto;
|
|
598
|
+
}
|
|
599
|
+
async hashString(algorithm, data, sort = false) {
|
|
600
|
+
const headers = sort ? [...data].sort() : [...data];
|
|
601
|
+
const dataEncoded = new TextEncoder().encode(headers.join(','));
|
|
602
|
+
const hashBuffer = await this.crypto.subtle.digest(algorithm, dataEncoded);
|
|
603
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
604
|
+
const hashHex = hashArray
|
|
605
|
+
.map(b => b.toString(16).padStart(2, '0'))
|
|
606
|
+
.join('')
|
|
607
|
+
.substring(0, 12);
|
|
608
|
+
return 'h' + (sort ? 's' : '') + `_${data.length}_${hashHex}`;
|
|
609
|
+
}
|
|
610
|
+
static filterHeaderNames(headerNames) {
|
|
611
|
+
const keys = headerNames
|
|
612
|
+
.filter(headerName => {
|
|
613
|
+
const lower = headerName.toLowerCase();
|
|
614
|
+
return !['', 'cookie', 'referer'].includes(lower) && lower.match(/^(x-netacea-|cloudfront-)/i) === null;
|
|
615
|
+
});
|
|
616
|
+
return keys;
|
|
617
|
+
}
|
|
618
|
+
async hashHeaders(headerNames, sort = false) {
|
|
619
|
+
const filteredHeaderNames = HashGenerator.filterHeaderNames(headerNames);
|
|
620
|
+
if (filteredHeaderNames.length === 0) {
|
|
621
|
+
return '';
|
|
622
|
+
}
|
|
623
|
+
try {
|
|
624
|
+
return await this.hashString('SHA-256', filteredHeaderNames, sort);
|
|
625
|
+
}
|
|
626
|
+
catch (e) {
|
|
627
|
+
console.error(e);
|
|
628
|
+
return '';
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
exports.HashGenerator = HashGenerator;
|
|
594
634
|
exports.checkMitataCookie = checkMitataCookie;
|
|
595
635
|
exports.checkNetaceaCookieV3 = checkNetaceaCookieV3;
|
|
596
636
|
exports.configureMitataExpiry = configureMitataExpiry;
|
package/dist/index.d.ts
CHANGED
|
@@ -98,6 +98,10 @@ interface MakeRequestArgs {
|
|
|
98
98
|
* Request timeout value in ms
|
|
99
99
|
*/
|
|
100
100
|
timeout?: number;
|
|
101
|
+
/**
|
|
102
|
+
* Request URL parameters
|
|
103
|
+
*/
|
|
104
|
+
params?: Record<string, string> | URLSearchParams;
|
|
101
105
|
}
|
|
102
106
|
interface MakeRequestResponse {
|
|
103
107
|
/**
|
|
@@ -302,6 +306,7 @@ interface IngestArgs {
|
|
|
302
306
|
mitigationLatency?: number;
|
|
303
307
|
mitigationStatus?: number;
|
|
304
308
|
netaceaCookieStatus?: number;
|
|
309
|
+
workerInstanceId?: string;
|
|
305
310
|
}
|
|
306
311
|
interface WebLog {
|
|
307
312
|
Request: string;
|
|
@@ -317,12 +322,14 @@ interface WebLog {
|
|
|
317
322
|
IntegrationType?: string;
|
|
318
323
|
IntegrationVersion?: string;
|
|
319
324
|
XForwardedFor?: string;
|
|
325
|
+
WorkerInstanceId?: string;
|
|
320
326
|
optional?: Record<string, unknown>;
|
|
321
327
|
ProtectionMode?: string;
|
|
322
328
|
RequestHost?: string;
|
|
323
329
|
ProtectorLatencyMs?: number;
|
|
324
330
|
ProtectorStatus?: number;
|
|
325
331
|
NetaceaUserIdCookieStatus?: number;
|
|
332
|
+
HeaderHash?: string;
|
|
326
333
|
}
|
|
327
334
|
interface V2WebLog {
|
|
328
335
|
'@timestamp': string;
|
|
@@ -350,6 +357,7 @@ interface V2WebLog {
|
|
|
350
357
|
user_agent: string;
|
|
351
358
|
user_id?: string;
|
|
352
359
|
x_forwarded_for?: string;
|
|
360
|
+
worker_instance_id?: string;
|
|
353
361
|
optional?: Record<string, unknown>;
|
|
354
362
|
}
|
|
355
363
|
interface NetaceaResponseBase {
|
|
@@ -615,4 +623,18 @@ declare const lib: {
|
|
|
615
623
|
};
|
|
616
624
|
};
|
|
617
625
|
|
|
618
|
-
|
|
626
|
+
type CryptoAlgorithm = 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512';
|
|
627
|
+
interface CryptoLike {
|
|
628
|
+
subtle: {
|
|
629
|
+
digest: (algorithm: CryptoAlgorithm, data: ArrayBuffer | ArrayBufferView) => Promise<ArrayBuffer>;
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
declare class HashGenerator {
|
|
633
|
+
crypto: CryptoLike;
|
|
634
|
+
constructor(crypto: CryptoLike);
|
|
635
|
+
hashString(algorithm: CryptoAlgorithm, data: string[], sort?: boolean): Promise<string>;
|
|
636
|
+
static filterHeaderNames(headerNames: string[]): string[];
|
|
637
|
+
hashHeaders(headerNames: string[], sort?: boolean): Promise<string>;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
export { type APICallResponse, type CheckCookieResponse, type ComposeResultResponse, type CookiesAttributes, type FindBestMitigationResponse, HashGenerator, type IngestArgs, type InjectHeaders, type InjectResponse, type MakeCaptchaApiCallResponse, type MakeMitigateAPICallResponse, type MakeRequestArgs, type MakeRequestResponse, type MitataCookie, type MitigateResponse, type NetaceaBaseArgs, type NetaceaCookieV3, NetaceaCookieV3IssueReason, type NetaceaCookieV3OptionalFeatures, NetaceaIngestType, NetaceaLogVersion, type NetaceaMitigationResponse, NetaceaMitigationType, type NetaceaParts, type NetaceaResponseBase, type NetaceaWorker, type ProcessMitigateRequestArgs, type SlicedCookieAttributes, type V2WebLog, type WebLog, checkMitataCookie, checkNetaceaCookieV3, configureMitataExpiry, cookieIsNetaceaV3Format, correctTimeout, createMitataCookie, createNetaceaCookieV3, defaultInvalidResponse, dictionary_d as dictionary, generateId, hexSha256, ingestIgnoredIpValue, lib, matchMitataCookie, matchNetaceaCookieV3, objectIsNetaceaCookieV3, safeParseInt, warmupCookie };
|
package/dist/index.mjs
CHANGED
|
@@ -120,7 +120,8 @@ const matchMap = {
|
|
|
120
120
|
6: 'organisation_',
|
|
121
121
|
7: 'asn_',
|
|
122
122
|
8: 'country_',
|
|
123
|
-
9: 'combination_'
|
|
123
|
+
9: 'combination_',
|
|
124
|
+
11: 'headerFP_' // b (base36)
|
|
124
125
|
};
|
|
125
126
|
const mitigateMap = {
|
|
126
127
|
0: '',
|
|
@@ -200,7 +201,7 @@ var dictionary = /*#__PURE__*/Object.freeze({
|
|
|
200
201
|
// & a new MITIGATE cookie will be set
|
|
201
202
|
const ingestIgnoredIpValue = 'ignored';
|
|
202
203
|
const BASE_62_CHARSET = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
|
|
203
|
-
const mitataCookieRegExp = /^(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/((\d)(\d)(\d))
|
|
204
|
+
const mitataCookieRegExp = /^(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/((\d|[a-z])(\d)(\d))$/i;
|
|
204
205
|
function matchMitataCookie(netaceaCookie) {
|
|
205
206
|
if (netaceaCookie === undefined) {
|
|
206
207
|
return undefined;
|
|
@@ -214,7 +215,7 @@ function matchMitataCookie(netaceaCookie) {
|
|
|
214
215
|
userId,
|
|
215
216
|
ipHash,
|
|
216
217
|
mitigationType,
|
|
217
|
-
match: parseInt(match),
|
|
218
|
+
match: parseInt(match, 36),
|
|
218
219
|
mitigate: parseInt(mitigate),
|
|
219
220
|
captcha: parseInt(captcha)
|
|
220
221
|
};
|
|
@@ -589,4 +590,42 @@ const lib = {
|
|
|
589
590
|
}
|
|
590
591
|
};
|
|
591
592
|
|
|
592
|
-
|
|
593
|
+
class HashGenerator {
|
|
594
|
+
constructor(crypto) {
|
|
595
|
+
this.crypto = crypto;
|
|
596
|
+
}
|
|
597
|
+
async hashString(algorithm, data, sort = false) {
|
|
598
|
+
const headers = sort ? [...data].sort() : [...data];
|
|
599
|
+
const dataEncoded = new TextEncoder().encode(headers.join(','));
|
|
600
|
+
const hashBuffer = await this.crypto.subtle.digest(algorithm, dataEncoded);
|
|
601
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
602
|
+
const hashHex = hashArray
|
|
603
|
+
.map(b => b.toString(16).padStart(2, '0'))
|
|
604
|
+
.join('')
|
|
605
|
+
.substring(0, 12);
|
|
606
|
+
return 'h' + (sort ? 's' : '') + `_${data.length}_${hashHex}`;
|
|
607
|
+
}
|
|
608
|
+
static filterHeaderNames(headerNames) {
|
|
609
|
+
const keys = headerNames
|
|
610
|
+
.filter(headerName => {
|
|
611
|
+
const lower = headerName.toLowerCase();
|
|
612
|
+
return !['', 'cookie', 'referer'].includes(lower) && lower.match(/^(x-netacea-|cloudfront-)/i) === null;
|
|
613
|
+
});
|
|
614
|
+
return keys;
|
|
615
|
+
}
|
|
616
|
+
async hashHeaders(headerNames, sort = false) {
|
|
617
|
+
const filteredHeaderNames = HashGenerator.filterHeaderNames(headerNames);
|
|
618
|
+
if (filteredHeaderNames.length === 0) {
|
|
619
|
+
return '';
|
|
620
|
+
}
|
|
621
|
+
try {
|
|
622
|
+
return await this.hashString('SHA-256', filteredHeaderNames, sort);
|
|
623
|
+
}
|
|
624
|
+
catch (e) {
|
|
625
|
+
console.error(e);
|
|
626
|
+
return '';
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
export { HashGenerator, NetaceaCookieV3IssueReason, NetaceaIngestType, NetaceaLogVersion, NetaceaMitigationType, checkMitataCookie, checkNetaceaCookieV3, configureMitataExpiry, cookieIsNetaceaV3Format, correctTimeout, createMitataCookie, createNetaceaCookieV3, defaultInvalidResponse, dictionary, generateId, hexSha256, ingestIgnoredIpValue, lib, matchMitataCookie, matchNetaceaCookieV3, objectIsNetaceaCookieV3, safeParseInt, warmupCookie };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netacea/netaceaintegrationbase",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.54",
|
|
4
4
|
"description": "Base package for Netacea CDN integrations.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"license": "UNLICENSED",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@netacea/kinesisingest": "^1.5.
|
|
27
|
+
"@netacea/kinesisingest": "^1.5.72"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "86f4865b9ce674da9b9a6e03cfa94fc1b9e384c1"
|
|
30
30
|
}
|