@netacea/netaceaintegrationbase 2.0.52 → 2.0.53

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 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
  /**
@@ -323,6 +327,7 @@ interface WebLog {
323
327
  ProtectorLatencyMs?: number;
324
328
  ProtectorStatus?: number;
325
329
  NetaceaUserIdCookieStatus?: number;
330
+ HeaderHash?: string;
326
331
  }
327
332
  interface V2WebLog {
328
333
  '@timestamp': string;
@@ -615,4 +620,18 @@ declare const lib: {
615
620
  };
616
621
  };
617
622
 
618
- export { type APICallResponse, type CheckCookieResponse, type ComposeResultResponse, type CookiesAttributes, type FindBestMitigationResponse, 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 };
623
+ type CryptoAlgorithm = 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512';
624
+ interface CryptoLike {
625
+ subtle: {
626
+ digest: (algorithm: CryptoAlgorithm, data: ArrayBuffer | ArrayBufferView) => Promise<ArrayBuffer>;
627
+ };
628
+ }
629
+ declare class HashGenerator {
630
+ crypto: CryptoLike;
631
+ constructor(crypto: CryptoLike);
632
+ hashString(algorithm: CryptoAlgorithm, data: string[], sort?: boolean): Promise<string>;
633
+ static filterHeaderNames(headerNames: string[]): string[];
634
+ hashHeaders(headerNames: string[], sort?: boolean): Promise<string>;
635
+ }
636
+
637
+ 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
- export { NetaceaCookieV3IssueReason, NetaceaIngestType, NetaceaLogVersion, NetaceaMitigationType, checkMitataCookie, checkNetaceaCookieV3, configureMitataExpiry, cookieIsNetaceaV3Format, correctTimeout, createMitataCookie, createNetaceaCookieV3, defaultInvalidResponse, dictionary, generateId, hexSha256, ingestIgnoredIpValue, lib, matchMitataCookie, matchNetaceaCookieV3, objectIsNetaceaCookieV3, safeParseInt, warmupCookie };
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.52",
3
+ "version": "2.0.53",
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.70"
27
+ "@netacea/kinesisingest": "^1.5.71"
28
28
  },
29
- "gitHead": "80732378d96f2330deec92daa70ad0effa4e066a"
29
+ "gitHead": "1739319709fac76e0ecdf122b24adcfd47db6a85"
30
30
  }