@netacea/akamai 5.0.76 → 5.0.77
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/CHANGELOG.md +8 -0
- package/dist/package.json +3 -3
- package/dist/src/AkamaiV2.js +7 -17
- package/dist/src/AkamaiV2.js.map +1 -1
- package/dist/src/helpers/addHeadersToRequest.d.ts +4 -0
- package/dist/src/helpers/addHeadersToRequest.js +24 -0
- package/dist/src/helpers/addHeadersToRequest.js.map +1 -0
- package/dist/src/helpers/check.d.ts +3 -0
- package/dist/src/helpers/check.js +33 -0
- package/dist/src/helpers/check.js.map +1 -0
- package/dist/src/helpers/composeResult.d.ts +3 -0
- package/dist/src/helpers/composeResult.js +31 -0
- package/dist/src/helpers/composeResult.js.map +1 -0
- package/dist/src/helpers/createMitata.d.ts +1 -2
- package/dist/src/helpers/createMitata.js +2 -2
- package/dist/src/helpers/createMitata.js.map +1 -1
- package/dist/src/helpers/getMitHeaders.d.ts +3 -0
- package/dist/src/helpers/getMitHeaders.js +27 -0
- package/dist/src/helpers/getMitHeaders.js.map +1 -0
- package/dist/src/helpers/getMitigationResponse.d.ts +4 -0
- package/dist/src/helpers/getMitigationResponse.js +24 -0
- package/dist/src/helpers/getMitigationResponse.js.map +1 -0
- package/dist/src/helpers/handleMitResult.d.ts +3 -0
- package/dist/src/helpers/handleMitResult.js +31 -0
- package/dist/src/helpers/handleMitResult.js.map +1 -0
- package/dist/src/helpers/inject.d.ts +4 -0
- package/dist/src/helpers/inject.js +15 -0
- package/dist/src/helpers/inject.js.map +1 -0
- package/dist/src/helpers/mitigate.d.ts +3 -0
- package/dist/src/helpers/mitigate.js +29 -0
- package/dist/src/helpers/mitigate.js.map +1 -0
- package/dist/src/helpers/processCaptcha.d.ts +3 -0
- package/dist/src/helpers/processCaptcha.js +7 -0
- package/dist/src/helpers/processCaptcha.js.map +1 -0
- package/dist/src/helpers/processIngest.d.ts +3 -0
- package/dist/src/helpers/processIngest.js +32 -0
- package/dist/src/helpers/processIngest.js.map +1 -0
- package/dist/src/helpers/processMitigateRequest.d.ts +6 -0
- package/dist/src/helpers/processMitigateRequest.js +10 -0
- package/dist/src/helpers/processMitigateRequest.js.map +1 -0
- package/dist/src/helpers/runMitigation.d.ts +4 -0
- package/dist/src/helpers/runMitigation.js +30 -0
- package/dist/src/helpers/runMitigation.js.map +1 -0
- package/dist/src/mitigation/makeCaptchaApiCall.d.ts +3 -0
- package/dist/src/mitigation/makeCaptchaApiCall.js +29 -0
- package/dist/src/mitigation/makeCaptchaApiCall.js.map +1 -0
- package/dist/src/mitigation/makeMitigateApiCall.d.ts +3 -0
- package/dist/src/mitigation/makeMitigateApiCall.js +37 -0
- package/dist/src/mitigation/makeMitigateApiCall.js.map +1 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 5.0.77 (2024-01-26)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @netacea/akamai
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## 5.0.76 (2024-01-23)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @netacea/akamai
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netacea/akamai",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.77",
|
|
4
4
|
"description": "Netacea Akamai CDN Integration",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"license": "ISC",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@netacea/netaceaintegrationbase": "^1.16.
|
|
23
|
+
"@netacea/netaceaintegrationbase": "^1.16.83",
|
|
24
24
|
"buffer": "^6.0.3",
|
|
25
25
|
"jssha": "^3.3.0"
|
|
26
26
|
},
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"tslib": "^2.0.3",
|
|
68
68
|
"typescript": "^4.0.3"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "3a4f7a265c6ab6623ce193fe964da6b33a4f4b6d"
|
|
71
71
|
}
|
package/dist/src/AkamaiV2.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import AkamaiLegacyWorker from './AkamaiV1';
|
|
2
1
|
import { httpRequest } from 'http-request';
|
|
3
2
|
import { logger } from 'log';
|
|
4
3
|
import ConfigLoader from './ConfigLoader';
|
|
@@ -12,6 +11,7 @@ import { CachedEncryption } from './CachedEncryption';
|
|
|
12
11
|
import { handleCaptchaPost } from './captchaPost';
|
|
13
12
|
import { removeNetaceaHeaders } from './helpers/removeNetaceaHeaders';
|
|
14
13
|
import { routeRequestToNetaceaProxy } from './helpers/routeRequestToNetaceaProxy';
|
|
14
|
+
import { handleMitResult } from './helpers/handleMitResult';
|
|
15
15
|
export default class Akamai {
|
|
16
16
|
constructor(defaultConfig) {
|
|
17
17
|
this.configLoader = new ConfigLoader(defaultConfig);
|
|
@@ -30,38 +30,28 @@ export default class Akamai {
|
|
|
30
30
|
}
|
|
31
31
|
if (isUrlCaptchaGet(request.path, request.method, config.netaceaCaptchaPath)) {
|
|
32
32
|
await handleCaptchaGet(this.defaultDeps, config, request);
|
|
33
|
-
return await logToDataStream(this.defaultDeps, config, request);
|
|
34
33
|
}
|
|
35
34
|
else if (isUrlCaptchaPost(request.path, request.method)) {
|
|
36
35
|
await verifyCaptcha(this.defaultDeps, config, request);
|
|
37
|
-
return await logToDataStream(this.defaultDeps, config, request);
|
|
38
36
|
}
|
|
39
37
|
else if (isUrlCaptchaAssetsGet(request.path, request.method, config.useCaptchaRelAssets)) {
|
|
40
38
|
routeRequestToNetaceaProxy(request);
|
|
41
|
-
return await logToDataStream(this.defaultDeps, config, request);
|
|
42
39
|
}
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
else {
|
|
41
|
+
await handleMitResult(this.defaultDeps, config, request);
|
|
42
|
+
}
|
|
43
|
+
await logToDataStream(this.defaultDeps, config, request);
|
|
45
44
|
}
|
|
46
45
|
async responseHandler(request, response) {
|
|
47
46
|
const config = this.configLoader.loadConfig(request);
|
|
48
47
|
if (isUrlCaptchaPost(request.path, request.method)) {
|
|
49
48
|
await handleCaptchaPost(this.defaultDeps, config, request, response);
|
|
50
|
-
removeNetaceaHeaders(response);
|
|
51
|
-
await ingestIfHttpIngestType(this.defaultDeps, config, request, response);
|
|
52
|
-
return;
|
|
53
49
|
}
|
|
54
50
|
else if (!isUrlCaptchaAssetsGet(request.path, request.method, config.useCaptchaRelAssets)) {
|
|
55
51
|
await setNetaceaCookie(this.defaultDeps, config, request, response);
|
|
56
|
-
removeNetaceaHeaders(response);
|
|
57
|
-
await ingestIfHttpIngestType(this.defaultDeps, config, request, response);
|
|
58
|
-
return;
|
|
59
52
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
logger
|
|
63
|
-
});
|
|
64
|
-
return await legacyWorker.responseHandler(request, response);
|
|
53
|
+
removeNetaceaHeaders(response);
|
|
54
|
+
await ingestIfHttpIngestType(this.defaultDeps, config, request, response);
|
|
65
55
|
}
|
|
66
56
|
}
|
|
67
57
|
//# sourceMappingURL=AkamaiV2.js.map
|
package/dist/src/AkamaiV2.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AkamaiV2.js","sourceRoot":"","sources":["../../src/AkamaiV2.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AkamaiV2.js","sourceRoot":"","sources":["../../src/AkamaiV2.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAE,MAAM,EA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C,QAAQ,CAAC,CAAA;QAC9B,MAAM,sBAAsB,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;IAC3E,CAAC;CACF"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="akamai-edgeworkers" />
|
|
2
|
+
import type { InjectResponse } from '@netacea/netaceaintegrationbase';
|
|
3
|
+
import type { AkamaiMitigateResponse, AkamaiRuntimeDependencies, AkamaiWorkerConfig } from '../types';
|
|
4
|
+
export declare function addHeadersToRequest(deps: AkamaiRuntimeDependencies, config: Readonly<AkamaiWorkerConfig>, mitResult: AkamaiMitigateResponse | InjectResponse | undefined, request: EW.IngressClientRequest): Promise<void>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { NetaceaMitigationType, NetaceaIngestType } from '@netacea/netaceaintegrationbase';
|
|
2
|
+
import { readCookie } from './readCookie';
|
|
3
|
+
import { getMitHeaders } from './getMitHeaders';
|
|
4
|
+
export async function addHeadersToRequest(deps, config, mitResult, request) {
|
|
5
|
+
let injectHeaders = {};
|
|
6
|
+
if (mitResult?.setCookie !== undefined) {
|
|
7
|
+
const protoMitata = await readCookie(deps, config, mitResult.setCookie, '_proto-mitata');
|
|
8
|
+
if (protoMitata !== undefined) {
|
|
9
|
+
request.setVariable(config.protoMitataVariableName, protoMitata);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
if (config.mitigationType === NetaceaMitigationType.INJECT) {
|
|
13
|
+
const result = mitResult;
|
|
14
|
+
injectHeaders = result.injectHeaders ?? {};
|
|
15
|
+
}
|
|
16
|
+
let mitHeaders = {};
|
|
17
|
+
if (config.ingestType === NetaceaIngestType.ORIGIN) {
|
|
18
|
+
mitHeaders = await getMitHeaders(deps, config, request);
|
|
19
|
+
}
|
|
20
|
+
for (const [key, value] of Object.entries({ ...injectHeaders, ...mitHeaders })) {
|
|
21
|
+
request.addHeader(key, value);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=addHeadersToRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addHeadersToRequest.js","sourceRoot":"","sources":["../../../src/helpers/addHeadersToRequest.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAC1F,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/C,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,IAA+B,EAC/B,MAAoC,EACpC,SAA8D,EAC9D,OAAgC;IAEhC,IAAI,aAAa,GAAG,EAAE,CAAA;IACtB,IAAI,SAAS,EAAE,SAAS,KAAK,SAAS,EAAE;QAEtC,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,SAAS,EAAE,eAAe,CAAC,CAAA;QACxF,IAAI,WAAW,KAAK,SAAS,EAAE;YAC7B,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,uBAAuB,EAAE,WAAW,CAAC,CAAA;SACjE;KACF;IACD,IAAI,MAAM,CAAC,cAAc,KAAK,qBAAqB,CAAC,MAAM,EAAE;QAC1D,MAAM,MAAM,GAAG,SAA2B,CAAA;QAC1C,aAAa,GAAG,MAAM,CAAC,aAAa,IAAI,EAAE,CAAA;KAC3C;IACD,IAAI,UAAU,GAAG,EAAE,CAAA;IACnB,IAAI,MAAM,CAAC,UAAU,KAAK,iBAAiB,CAAC,MAAM,EAAE;QAClD,UAAU,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;KACxD;IACD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,EAAE,GAAG,aAAa,EAAE,GAAG,UAAU,EAAE,CAAC,EAAE;QAC9E,OAAO,CAAC,SAAS,CAAC,GAAG,EAAE,KAAY,CAAC,CAAA;KACrC;AACH,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ComposeResultResponse } from '@netacea/netaceaintegrationbase';
|
|
2
|
+
import type { AkamaiRuntimeDependencies, AkamaiWorkerConfig } from '../types';
|
|
3
|
+
export declare function check(deps: AkamaiRuntimeDependencies, config: Readonly<AkamaiWorkerConfig>, netaceaCookie: string | undefined, clientIP: string, userAgent: string, accept: string, host: string, captchaCookie?: string): Promise<ComposeResultResponse>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { retrieveCookieInfo } from './retrieveCookieInfo';
|
|
2
|
+
import { makeMitigateApiCall } from '../mitigation/makeMitigateApiCall';
|
|
3
|
+
import { composeResult } from './composeResult';
|
|
4
|
+
import { createProtoMitata } from './createProtoMitata';
|
|
5
|
+
export async function check(deps, config, netaceaCookie, clientIP, userAgent, accept, host, captchaCookie) {
|
|
6
|
+
let status, match, mitigate, captcha, body, setCookie, eventId;
|
|
7
|
+
if (config.secretKey === undefined) {
|
|
8
|
+
throw new Error('Secret key is required to mitigate');
|
|
9
|
+
}
|
|
10
|
+
const cookieInfo = await retrieveCookieInfo(netaceaCookie, clientIP, config.secretKey);
|
|
11
|
+
if (!cookieInfo.isPrimaryHashValid || cookieInfo.requiresReissue) {
|
|
12
|
+
const result = await makeMitigateApiCall(deps, config, cookieInfo.mitata?.userId, clientIP, userAgent, captchaCookie, accept, host);
|
|
13
|
+
status = result.status;
|
|
14
|
+
match = result.match;
|
|
15
|
+
mitigate = result.mitigate;
|
|
16
|
+
captcha = result.captcha;
|
|
17
|
+
body = result.body;
|
|
18
|
+
setCookie = [
|
|
19
|
+
await createProtoMitata(clientIP, cookieInfo.mitata?.userId, match, mitigate, captcha, result.mitataMaxAge)
|
|
20
|
+
];
|
|
21
|
+
eventId = result.eventId;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
status = -1;
|
|
25
|
+
match = cookieInfo.match;
|
|
26
|
+
mitigate = cookieInfo.mitigate;
|
|
27
|
+
captcha = cookieInfo.captcha;
|
|
28
|
+
body = undefined;
|
|
29
|
+
setCookie = [];
|
|
30
|
+
}
|
|
31
|
+
return composeResult(config, body, setCookie, status, match, mitigate, captcha, false, eventId);
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../../src/helpers/check.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAA;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAEvD,MAAM,CAAC,KAAK,UAAU,KAAK,CACzB,IAA+B,EAC/B,MAAoC,EACpC,aAAiC,EACjC,QAAgB,EAChB,SAAiB,EACjB,MAAc,EACd,IAAY,EACZ,aAAsB;IAEtB,IAAI,MAAc,EAAE,KAAa,EAAE,QAAgB,EAAE,OAAe,EAClE,IAAwB,EAAE,SAAmB,EAAE,OAA2B,CAAA;IAC5E,IAAI,MAAM,CAAC,SAAS,KAAK,SAAS,EAAE;QAClC,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAA;KACtD;IACD,MAAM,UAAU,GAAG,MAAM,kBAAkB,CAAC,aAAa,EAAE,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,CAAA;IACtF,IAAI,CAAC,UAAU,CAAC,kBAAkB,IAAI,UAAU,CAAC,eAAe,EAAE;QAEhE,MAAM,MAAM,GAAG,MAAM,mBAAmB,CACtC,IAAI,EACJ,MAAM,EACN,UAAU,CAAC,MAAM,EAAE,MAAM,EACzB,QAAQ,EACR,SAAS,EACT,aAAa,EACb,MAAM,EACN,IAAI,CACL,CAAA;QACD,MAAM,GAAG,MAAM,CAAC,MAAM,CAAA;QACtB,KAAK,GAAG,MAAM,CAAC,KAAK,CAAA;QACpB,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAA;QAC1B,OAAO,GAAG,MAAM,CAAC,OAAO,CAAA;QACxB,IAAI,GAAG,MAAM,CAAC,IAAI,CAAA;QAClB,SAAS,GAAG;YACV,MAAM,iBAAiB,CACrB,QAAQ,EACR,UAAU,CAAC,MAAM,EAAE,MAAM,EACzB,KAAK,EACL,QAAQ,EACR,OAAO,EACP,MAAM,CAAC,YAAY,CACpB;SACF,CAAA;QACD,OAAO,GAAG,MAAM,CAAC,OAAO,CAAA;KACzB;SAAM;QACL,MAAM,GAAG,CAAC,CAAC,CAAA;QACX,KAAK,GAAG,UAAU,CAAC,KAAK,CAAA;QACxB,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAA;QAC9B,OAAO,GAAG,UAAU,CAAC,OAAO,CAAA;QAC5B,IAAI,GAAG,SAAS,CAAA;QAChB,SAAS,GAAG,EAAE,CAAA;KACf;IACD,OAAO,aAAa,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;AACjG,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ComposeResultResponse } from '@netacea/netaceaintegrationbase';
|
|
2
|
+
import type { AkamaiWorkerConfig } from '../types';
|
|
3
|
+
export declare function composeResult(config: Readonly<AkamaiWorkerConfig>, body: string | undefined, setCookie: string[], status: number, match: number, mitigate: number, captcha: number, isCaptchaPost: boolean, eventId?: string): ComposeResultResponse;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { dictionary, NetaceaMitigationType } from '@netacea/netaceaintegrationbase';
|
|
2
|
+
import { findBestMitigation } from './findBestMitigation';
|
|
3
|
+
const { mitigationTypes } = dictionary;
|
|
4
|
+
export function composeResult(config, body, setCookie, status, match, mitigate, captcha, isCaptchaPost, eventId) {
|
|
5
|
+
const bestMitigation = findBestMitigation(config, match, mitigate, captcha, isCaptchaPost);
|
|
6
|
+
const result = {
|
|
7
|
+
body,
|
|
8
|
+
apiCallStatus: status,
|
|
9
|
+
setCookie,
|
|
10
|
+
sessionStatus: bestMitigation.sessionStatus,
|
|
11
|
+
mitigation: bestMitigation.mitigation,
|
|
12
|
+
mitigated: [
|
|
13
|
+
mitigationTypes.block,
|
|
14
|
+
mitigationTypes.captcha,
|
|
15
|
+
mitigationTypes.captchaPass
|
|
16
|
+
].includes(bestMitigation.mitigation)
|
|
17
|
+
};
|
|
18
|
+
if (config.mitigationType === NetaceaMitigationType.INJECT) {
|
|
19
|
+
const injectHeaders = {
|
|
20
|
+
'x-netacea-match': bestMitigation.parts.match.toString(),
|
|
21
|
+
'x-netacea-mitigate': bestMitigation.parts.mitigate.toString(),
|
|
22
|
+
'x-netacea-captcha': bestMitigation.parts.captcha.toString()
|
|
23
|
+
};
|
|
24
|
+
if (eventId !== undefined) {
|
|
25
|
+
injectHeaders['x-netacea-event-id'] = eventId;
|
|
26
|
+
}
|
|
27
|
+
result.injectHeaders = injectHeaders;
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=composeResult.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composeResult.js","sourceRoot":"","sources":["../../../src/helpers/composeResult.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAA;AACnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAEzD,MAAM,EAAE,eAAe,EAAE,GAAG,UAAU,CAAA;AAEtC,MAAM,UAAU,aAAa,CAC3B,MAAoC,EACpC,IAAwB,EACxB,SAAmB,EACnB,MAAc,EACd,KAAa,EACb,QAAgB,EAChB,OAAe,EACf,aAAsB,EACtB,OAAgB;IAEhB,MAAM,cAAc,GAAG,kBAAkB,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,CAAC,CAAA;IAC1F,MAAM,MAAM,GAA0B;QACpC,IAAI;QACJ,aAAa,EAAE,MAAM;QACrB,SAAS;QACT,aAAa,EAAE,cAAc,CAAC,aAAa;QAC3C,UAAU,EAAE,cAAc,CAAC,UAAU;QACrC,SAAS,EAAE;YACT,eAAe,CAAC,KAAK;YACrB,eAAe,CAAC,OAAO;YACvB,eAAe,CAAC,WAAW;SAC5B,CAAC,QAAQ,CAAC,cAAc,CAAC,UAAU,CAAC;KACtC,CAAA;IACD,IAAI,MAAM,CAAC,cAAc,KAAK,qBAAqB,CAAC,MAAM,EAAE;QAC1D,MAAM,aAAa,GAAkB;YACnC,iBAAiB,EAAE,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE;YACxD,oBAAoB,EAAE,cAAc,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE;YAC9D,mBAAmB,EAAE,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE;SAC7D,CAAA;QACD,IAAI,OAAO,KAAK,SAAS,EAAE;YACzB,aAAa,CAAC,oBAAoB,CAAC,GAAG,OAAO,CAAA;SAC9C;QACD,MAAM,CAAC,aAAa,GAAG,aAAa,CAAA;KACrC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -8,8 +8,7 @@ interface CreateMitataOptions {
|
|
|
8
8
|
captcha: number;
|
|
9
9
|
maxAge: number;
|
|
10
10
|
expiry?: number;
|
|
11
|
-
cookieId?: string;
|
|
12
11
|
issueReason?: NetaceaCookieV3IssueReason;
|
|
13
12
|
}
|
|
14
|
-
export declare function createMitata(deps: AkamaiRuntimeDependencies, config: Readonly<AkamaiWorkerConfig>, { clientIP, userId, match, mitigate, captcha,
|
|
13
|
+
export declare function createMitata(deps: AkamaiRuntimeDependencies, config: Readonly<AkamaiWorkerConfig>, { clientIP, userId, match, mitigate, captcha, issueReason, maxAge, expiry }: CreateMitataOptions): Promise<string>;
|
|
15
14
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NetaceaCookieV3IssueReason, NetaceaIngestType, createNetaceaCookieV3 } from '@netacea/netaceaintegrationbase';
|
|
2
2
|
import { buildCookieFromValues } from './buildCookieFromValues';
|
|
3
3
|
import { createLegacyMitataCookie, generateId } from '../mitataCookie';
|
|
4
|
-
export async function createMitata(deps, config, { clientIP, userId, match, mitigate, captcha,
|
|
4
|
+
export async function createMitata(deps, config, { clientIP, userId, match, mitigate, captcha, issueReason, maxAge = 86400, expiry = undefined }) {
|
|
5
5
|
const expirySeconds = config.netaceaCookieExpirySeconds;
|
|
6
6
|
const isCaptchaServe = [1, 3, 5].includes(captcha);
|
|
7
7
|
const expiryDelta = isCaptchaServe ? -expirySeconds : expirySeconds;
|
|
@@ -19,7 +19,7 @@ export async function createMitata(deps, config, { clientIP, userId, match, miti
|
|
|
19
19
|
mitigate,
|
|
20
20
|
captcha,
|
|
21
21
|
gracePeriod: expiryDelta,
|
|
22
|
-
cookieId:
|
|
22
|
+
cookieId: generateId(),
|
|
23
23
|
issueTimestamp: Math.floor(Date.now() / 1000),
|
|
24
24
|
issueReason: issueReason ?? NetaceaCookieV3IssueReason.NO_SESSION
|
|
25
25
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMitata.js","sourceRoot":"","sources":["../../../src/helpers/createMitata.ts"],"names":[],"mappings":"AACA,OAAO,EACL,0BAA0B,EAC1B,iBAAiB,EACjB,qBAAqB,EACtB,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,EAAE,wBAAwB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"createMitata.js","sourceRoot":"","sources":["../../../src/helpers/createMitata.ts"],"names":[],"mappings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c,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;YAC7C,WAAW,EAAE,WAAW,IAAI,0BAA0B,CAAC,UAAU;SAClE,CAAC,CAAA;KACH;SAAM;QACL,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACtD,WAAW,GAAG,MAAM,wBAAwB,CAC1C,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,MAAM,CAAC,SAAmB,EAC1B,UAAU,CACX,CAAA;KACF;IAED,OAAO,MAAM,qBAAqB,CAChC,IAAI,EACJ,MAAM,EACN,MAAM,CAAC,iBAA2B,EAClC,WAAW,EACX,MAAM,CACP,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/// <reference types="akamai-edgeworkers" />
|
|
2
|
+
import type { UpstreamMitHeaders, AkamaiRuntimeDependencies, AkamaiWorkerConfig } from '../types';
|
|
3
|
+
export declare function getMitHeaders(deps: AkamaiRuntimeDependencies, config: Readonly<AkamaiWorkerConfig>, request: EW.IngressClientRequest): Promise<UpstreamMitHeaders>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { getHeaderValueOrDefault } from './getHeaderValueOrDefault';
|
|
2
|
+
import { readCookie } from './readCookie';
|
|
3
|
+
import { matchCookie } from './matchCookie';
|
|
4
|
+
import { getProtoMitataFromRequestVar } from './getProtoMitataFromRequestVar';
|
|
5
|
+
import { findBestMitigation } from './findBestMitigation';
|
|
6
|
+
import { isUrlCaptchaPost } from '../netaceaPaths';
|
|
7
|
+
import * as pack from '../../package.json';
|
|
8
|
+
export async function getMitHeaders(deps, config, request) {
|
|
9
|
+
const cookieString = getHeaderValueOrDefault(request, 'cookie');
|
|
10
|
+
const mitataString = await readCookie(deps, config, cookieString, config.netaceaCookieName) ?? '';
|
|
11
|
+
const mitata = matchCookie(mitataString);
|
|
12
|
+
const protoMitata = getProtoMitataFromRequestVar(config, request);
|
|
13
|
+
const { match, mitigate, captcha, userId } = protoMitata ?? mitata ?? {
|
|
14
|
+
match: 0,
|
|
15
|
+
mitigate: 0,
|
|
16
|
+
captcha: 0,
|
|
17
|
+
userId: ''
|
|
18
|
+
};
|
|
19
|
+
const { sessionStatus } = findBestMitigation(config, match, mitigate, captcha, isUrlCaptchaPost(request.path, request.method));
|
|
20
|
+
return {
|
|
21
|
+
'X-Netacea-UserId': userId,
|
|
22
|
+
'X-Netacea-BC-Type': sessionStatus,
|
|
23
|
+
'X-Netacea-Integration-Type': pack.name.replace('@netacea/', ''),
|
|
24
|
+
'X-Netacea-Integration-Version': pack.version
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=getMitHeaders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMitHeaders.js","sourceRoot":"","sources":["../../../src/helpers/getMitHeaders.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAA;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAA;AAC7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAA;AAE1C,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,IAA+B,EAC/B,MAAoC,EACpC,OAAgC;IAGhC,MAAM,YAAY,GAAG,uBAAuB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;IAC/D,MAAM,YAAY,GAAG,MAAM,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,CAAC,iBAA2B,CAAC,IAAI,EAAE,CAAA;IAC3G,MAAM,MAAM,GAAG,WAAW,CAAC,YAAY,CAAC,CAAA;IAGxC,MAAM,WAAW,GAAG,4BAA4B,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAEjE,MAAM,EACJ,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EACjC,GAAG,WAAW,IAAI,MAAM,IAAI;QAC3B,KAAK,EAAE,CAAC;QACR,QAAQ,EAAE,CAAC;QACX,OAAO,EAAE,CAAC;QACV,MAAM,EAAE,EAAE;KACX,CAAA;IACD,MAAM,EAAE,aAAa,EAAE,GAAG,kBAAkB,CAC1C,MAAM,EACN,KAAK,EACL,QAAQ,EACR,OAAO,EACP,gBAAgB,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAC/C,CAAA;IACD,OAAO;QACL,kBAAkB,EAAE,MAAM;QAC1B,mBAAmB,EAAE,aAAa;QAClC,4BAA4B,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;QAChE,+BAA+B,EAAE,IAAI,CAAC,OAAO;KAC9C,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="akamai-edgeworkers" />
|
|
2
|
+
import type { ComposeResultResponse } from '@netacea/netaceaintegrationbase';
|
|
3
|
+
import type { AkamaiRuntimeDependencies, AkamaiWorkerConfig } from '../types';
|
|
4
|
+
export declare function getMitigationResponse(deps: AkamaiRuntimeDependencies, config: Readonly<AkamaiWorkerConfig>, request: EW.IngressClientRequest): Promise<ComposeResultResponse>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { getHeaderValueOrDefault } from './getHeaderValueOrDefault';
|
|
2
|
+
import { readCookie } from './readCookie';
|
|
3
|
+
import { getVariableOrDefault } from './getVariable';
|
|
4
|
+
import { processMitigateRequest } from './processMitigateRequest';
|
|
5
|
+
export async function getMitigationResponse(deps, config, request) {
|
|
6
|
+
const cookies = getHeaderValueOrDefault(request, 'cookie');
|
|
7
|
+
const netaceaCookie = await readCookie(deps, config, cookies, config.netaceaCookieName);
|
|
8
|
+
const mitataCaptcha = await readCookie(deps, config, cookies, config.netaceaCaptchaCookieName);
|
|
9
|
+
const clientIp = getVariableOrDefault(request, 'PMUSER_CLIENT_IP');
|
|
10
|
+
const userAgent = getHeaderValueOrDefault(request, 'user-agent');
|
|
11
|
+
const accept = getHeaderValueOrDefault(request, 'accept', 'text/html');
|
|
12
|
+
return await processMitigateRequest(deps, config, {
|
|
13
|
+
clientIp,
|
|
14
|
+
getBodyFn: async () => '',
|
|
15
|
+
method: request.method,
|
|
16
|
+
mitata: netaceaCookie,
|
|
17
|
+
mitataCaptcha,
|
|
18
|
+
url: request.path,
|
|
19
|
+
userAgent,
|
|
20
|
+
accept,
|
|
21
|
+
host: request.host
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=getMitigationResponse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMitigationResponse.js","sourceRoot":"","sources":["../../../src/helpers/getMitigationResponse.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAA;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AAEjE,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,IAA+B,EAC/B,MAAoC,EACpC,OAAgC;IAEhC,MAAM,OAAO,GAAG,uBAAuB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;IAC1D,MAAM,aAAa,GAAG,MAAM,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,iBAA2B,CAAC,CAAA;IACjG,MAAM,aAAa,GAAG,MAAM,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,wBAAkC,CAAC,CAAA;IACxG,MAAM,QAAQ,GAAG,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAA;IAClE,MAAM,SAAS,GAAG,uBAAuB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAA;IAChE,MAAM,MAAM,GAAG,uBAAuB,CAAC,OAAO,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAA;IACtE,OAAO,MAAM,sBAAsB,CACjC,IAAI,EACJ,MAAM,EACN;QACE,QAAQ;QACR,SAAS,EAAE,KAAK,IAAI,EAAE,CAAC,EAAE;QACzB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,MAAM,EAAE,aAAa;QACrB,aAAa;QACb,GAAG,EAAE,OAAO,CAAC,IAAI;QACjB,SAAS;QACT,MAAM;QACN,IAAI,EAAE,OAAO,CAAC,IAAI;KACnB,CACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/// <reference types="akamai-edgeworkers" />
|
|
2
|
+
import { AkamaiRuntimeDependencies, AkamaiWorkerConfig } from '../types';
|
|
3
|
+
export declare function handleMitResult(deps: AkamaiRuntimeDependencies, config: Readonly<AkamaiWorkerConfig>, request: EW.IngressClientRequest): Promise<void>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { runMitigation } from './runMitigation';
|
|
2
|
+
import { readCookie } from './readCookie';
|
|
3
|
+
import { isCaptchaJsonResponse } from './captchaContentNegotiation';
|
|
4
|
+
import { addHeadersToRequest } from './addHeadersToRequest';
|
|
5
|
+
export async function handleMitResult(deps, config, request) {
|
|
6
|
+
const mitResult = await runMitigation(deps, config, request);
|
|
7
|
+
if (mitResult === undefined) {
|
|
8
|
+
throw new Error('Mitigation Service response "mitResult" was undefined.');
|
|
9
|
+
}
|
|
10
|
+
const mitigationAction = mitResult.response?.mitigation;
|
|
11
|
+
if (mitigationAction === 'block' || mitigationAction === 'captcha') {
|
|
12
|
+
const status = mitResult.response?.status ?? 403;
|
|
13
|
+
const headers = {};
|
|
14
|
+
const protoMitataJson = await readCookie(deps, config, mitResult.setCookie, '_proto-mitata');
|
|
15
|
+
if (protoMitataJson !== undefined) {
|
|
16
|
+
request.setVariable(config.protoMitataVariableName, protoMitataJson);
|
|
17
|
+
}
|
|
18
|
+
const body = mitResult.response?.body ?? '';
|
|
19
|
+
if (isCaptchaJsonResponse(body)) {
|
|
20
|
+
headers['content-type'] = 'application/json';
|
|
21
|
+
}
|
|
22
|
+
if (mitigationAction === 'captcha' && config.netaceaCaptchaHeaderKey !== undefined) {
|
|
23
|
+
headers[config.netaceaCaptchaHeaderKey] = config.netaceaCaptchaHeaderValue;
|
|
24
|
+
}
|
|
25
|
+
request.respondWith(status, headers, body);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
await addHeadersToRequest(deps, config, mitResult, request);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=handleMitResult.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleMitResult.js","sourceRoot":"","sources":["../../../src/helpers/handleMitResult.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAA;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAE3D,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,IAA+B,EAC/B,MAAoC,EACpC,OAAgC;IAEhC,MAAM,SAAS,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;IAC5D,IAAI,SAAS,KAAK,SAAS,EAAE;QAC3B,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAA;KAC1E;IACD,MAAM,gBAAgB,GAAG,SAAS,CAAC,QAAQ,EAAE,UAAU,CAAA;IAEvD,IAAI,gBAAgB,KAAK,OAAO,IAAI,gBAAgB,KAAK,SAAS,EAAE;QAClE,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,CAAA;QAEhD,MAAM,OAAO,GAET,EAAE,CAAA;QACN,MAAM,eAAe,GAAG,MAAM,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,SAAS,EAAE,eAAe,CAAC,CAAA;QAC5F,IAAI,eAAe,KAAK,SAAS,EAAE;YACjC,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,uBAAuB,EAAE,eAAe,CAAC,CAAA;SACrE;QAED,MAAM,IAAI,GAAG,SAAS,CAAC,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAA;QAE3C,IAAI,qBAAqB,CAAC,IAAI,CAAC,EAAE;YAC/B,OAAO,CAAC,cAAc,CAAC,GAAG,kBAAkB,CAAA;SAC7C;QAED,IAAI,gBAAgB,KAAK,SAAS,IAAI,MAAM,CAAC,uBAAuB,KAAK,SAAS,EAAE;YAClF,OAAO,CAAC,MAAM,CAAC,uBAAuB,CAAC,GAAG,MAAM,CAAC,yBAAmC,CAAA;SACrF;QAGD,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA;KAC3C;SAAM;QACL,MAAM,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;KAC5D;AACH,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="akamai-edgeworkers" />
|
|
2
|
+
import type { InjectResponse } from '@netacea/netaceaintegrationbase';
|
|
3
|
+
import type { AkamaiRuntimeDependencies, AkamaiWorkerConfig } from '../types';
|
|
4
|
+
export declare function inject(deps: AkamaiRuntimeDependencies, config: Readonly<AkamaiWorkerConfig>, request: EW.IngressClientRequest): Promise<InjectResponse>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getMitigationResponse } from './getMitigationResponse';
|
|
2
|
+
export async function inject(deps, config, request) {
|
|
3
|
+
const result = await getMitigationResponse(deps, config, request);
|
|
4
|
+
const responseHeaders = {};
|
|
5
|
+
responseHeaders['set-cookie'] = result.setCookie.join('; ');
|
|
6
|
+
return {
|
|
7
|
+
injectHeaders: result.injectHeaders,
|
|
8
|
+
sessionStatus: result.sessionStatus,
|
|
9
|
+
setCookie: result.setCookie,
|
|
10
|
+
response: {
|
|
11
|
+
headers: responseHeaders
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=inject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject.js","sourceRoot":"","sources":["../../../src/helpers/inject.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAE/D,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,IAA+B,EAC/B,MAAoC,EACpC,OAAgC;IAEhC,MAAM,MAAM,GAAG,MAAM,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;IACjE,MAAM,eAAe,GAA2B,EAAE,CAAA;IAClD,eAAe,CAAC,YAAY,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC3D,OAAO;QACL,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,QAAQ,EAAE;YACR,OAAO,EAAE,eAAe;SACzB;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/// <reference types="akamai-edgeworkers" />
|
|
2
|
+
import type { AkamaiMitigateResponse, AkamaiRuntimeDependencies, AkamaiWorkerConfig } from '../types';
|
|
3
|
+
export declare function mitigate(deps: AkamaiRuntimeDependencies, config: Readonly<AkamaiWorkerConfig>, request: EW.IngressClientRequest): Promise<AkamaiMitigateResponse>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getMitigationResponse } from './getMitigationResponse';
|
|
2
|
+
export async function mitigate(deps, config, request) {
|
|
3
|
+
const result = await getMitigationResponse(deps, config, request);
|
|
4
|
+
const responseHeaders = {};
|
|
5
|
+
let body;
|
|
6
|
+
let status;
|
|
7
|
+
if (result.mitigated) {
|
|
8
|
+
status = 403;
|
|
9
|
+
if (result.mitigation === 'captcha') {
|
|
10
|
+
responseHeaders['content-type'] = 'text/html; charset=UTF-8';
|
|
11
|
+
body = result.body;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
body = 'Forbidden';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
response: {
|
|
19
|
+
body,
|
|
20
|
+
status,
|
|
21
|
+
statusText: status?.toString(),
|
|
22
|
+
headers: responseHeaders,
|
|
23
|
+
mitigation: result.mitigation
|
|
24
|
+
},
|
|
25
|
+
sessionStatus: result.sessionStatus,
|
|
26
|
+
setCookie: result.setCookie
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=mitigate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mitigate.js","sourceRoot":"","sources":["../../../src/helpers/mitigate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAE/D,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,IAA+B,EAC/B,MAAoC,EACpC,OAAgC;IAEhC,MAAM,MAAM,GAAG,MAAM,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;IACjE,MAAM,eAAe,GAA2B,EAAE,CAAA;IAClD,IAAI,IAAwB,CAAA;IAC5B,IAAI,MAA0B,CAAA;IAC9B,IAAI,MAAM,CAAC,SAAS,EAAE;QACpB,MAAM,GAAG,GAAG,CAAA;QACZ,IAAI,MAAM,CAAC,UAAU,KAAK,SAAS,EAAE;YACnC,eAAe,CAAC,cAAc,CAAC,GAAG,0BAA0B,CAAA;YAC5D,IAAI,GAAG,MAAM,CAAC,IAAI,CAAA;SACnB;aAAM;YAEL,IAAI,GAAG,WAAW,CAAA;SACnB;KACF;IAED,OAAO;QACL,QAAQ,EAAE;YACR,IAAI;YACJ,MAAM;YACN,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE;YAC9B,OAAO,EAAE,eAAe;YACxB,UAAU,EAAE,MAAM,CAAC,UAAU;SAC9B;QACD,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,SAAS,EAAE,MAAM,CAAC,SAAS;KAC5B,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ComposeResultResponse } from '@netacea/netaceaintegrationbase';
|
|
2
|
+
import type { AkamaiRuntimeDependencies, AkamaiWorkerConfig } from '../types';
|
|
3
|
+
export declare function processCaptcha(deps: AkamaiRuntimeDependencies, config: Readonly<AkamaiWorkerConfig>, netaceaCookie: string | undefined, clientIP: string, userAgent: string, captchaData: any): Promise<ComposeResultResponse>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { makeCaptchaApiCall } from '../mitigation/makeCaptchaApiCall';
|
|
2
|
+
import { composeResult } from './composeResult';
|
|
3
|
+
export async function processCaptcha(deps, config, netaceaCookie, clientIP, userAgent, captchaData) {
|
|
4
|
+
const { status, match, mitigate, captcha, body, setCookie } = await makeCaptchaApiCall(deps, config, netaceaCookie, clientIP, userAgent, captchaData);
|
|
5
|
+
return composeResult(config, body, setCookie, status, match, mitigate, captcha, true);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=processCaptcha.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processCaptcha.js","sourceRoot":"","sources":["../../../src/helpers/processCaptcha.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/C,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,IAA+B,EAC/B,MAAoC,EACpC,aAAiC,EACjC,QAAgB,EAChB,SAAiB,EACjB,WAAgB;IAEhB,MAAM,EACJ,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAClD,GAAG,MAAM,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,CAAC,CAAA;IAC3F,OAAO,aAAa,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA;AACvF,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { NetaceaResponseBase } from '@netacea/netaceaintegrationbase';
|
|
2
|
+
import type { AkamaiRuntimeDependencies, AkamaiWorkerConfig, RequestArgs } from '../types';
|
|
3
|
+
export declare function processIngest(deps: AkamaiRuntimeDependencies, config: Readonly<AkamaiWorkerConfig>, args: RequestArgs): Promise<NetaceaResponseBase>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ingestIgnoredIpValue } from '@netacea/netaceaintegrationbase';
|
|
2
|
+
import { readCookie } from './readCookie';
|
|
3
|
+
import { getHeaderValueOrDefault } from './getHeaderValueOrDefault';
|
|
4
|
+
import { retrieveCookieInfo } from './retrieveCookieInfo';
|
|
5
|
+
import { createProtoMitata } from './createProtoMitata';
|
|
6
|
+
export async function processIngest(deps, config, args) {
|
|
7
|
+
if (config.secretKey === undefined) {
|
|
8
|
+
throw new Error('Secret key is required for ingest');
|
|
9
|
+
}
|
|
10
|
+
const cookies = getHeaderValueOrDefault(args, 'cookie');
|
|
11
|
+
const netaceaCookie = await readCookie(deps, config, cookies, config.netaceaCookieName);
|
|
12
|
+
const cookieInfo = await retrieveCookieInfo(netaceaCookie, ingestIgnoredIpValue, config.secretKey);
|
|
13
|
+
if (!cookieInfo.isPrimaryHashValid) {
|
|
14
|
+
return await setIngestOnlyMitataCookie(undefined);
|
|
15
|
+
}
|
|
16
|
+
if (cookieInfo.requiresReissue) {
|
|
17
|
+
return await setIngestOnlyMitataCookie(cookieInfo.mitata?.userId);
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
sessionStatus: '',
|
|
21
|
+
setCookie: []
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
async function setIngestOnlyMitataCookie(userId) {
|
|
25
|
+
const ONE_DAY_IN_SECONDS = 86400;
|
|
26
|
+
const mitataCookie = await createProtoMitata(ingestIgnoredIpValue, userId, 0, 0, 0, ONE_DAY_IN_SECONDS);
|
|
27
|
+
return {
|
|
28
|
+
sessionStatus: '',
|
|
29
|
+
setCookie: [mitataCookie]
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=processIngest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processIngest.js","sourceRoot":"","sources":["../../../src/helpers/processIngest.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAA;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAA;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAEvD,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,IAA+B,EAC/B,MAAoC,EACpC,IAAiB;IAEjB,IAAI,MAAM,CAAC,SAAS,KAAK,SAAS,EAAE;QAClC,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAA;KACrD;IAED,MAAM,OAAO,GAAG,uBAAuB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;IACvD,MAAM,aAAa,GAAG,MAAM,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,iBAA2B,CAAC,CAAA;IAEjG,MAAM,UAAU,GAAG,MAAM,kBAAkB,CAAC,aAAa,EAAE,oBAAoB,EAAE,MAAM,CAAC,SAAS,CAAC,CAAA;IAClG,IAAI,CAAC,UAAU,CAAC,kBAAkB,EAAE;QAClC,OAAO,MAAM,yBAAyB,CAAC,SAAS,CAAC,CAAA;KAClD;IAED,IAAI,UAAU,CAAC,eAAe,EAAE;QAC9B,OAAO,MAAM,yBAAyB,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAClE;IAED,OAAO;QACL,aAAa,EAAE,EAAE;QACjB,SAAS,EAAE,EAAE;KACd,CAAA;AACH,CAAC;AAED,KAAK,UAAU,yBAAyB,CAAE,MAA0B;IAClE,MAAM,kBAAkB,GAAG,KAAK,CAAA;IAChC,MAAM,YAAY,GAAG,MAAM,iBAAiB,CAC1C,oBAAoB,EACpB,MAAM,EACN,CAAC,EAAE,CAAC,EAAE,CAAC,EACP,kBAAkB,CACnB,CAAA;IAED,OAAO;QACL,aAAa,EAAE,EAAE;QACjB,SAAS,EAAE,CAAC,YAAY,CAAC;KAC1B,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ProcessMitigateRequestArgs, ComposeResultResponse } from '@netacea/netaceaintegrationbase';
|
|
2
|
+
import type { AkamaiRuntimeDependencies, AkamaiWorkerConfig } from '../types';
|
|
3
|
+
export declare function processMitigateRequest(deps: AkamaiRuntimeDependencies, config: Readonly<AkamaiWorkerConfig>, args: ProcessMitigateRequestArgs & {
|
|
4
|
+
accept: string;
|
|
5
|
+
host: string;
|
|
6
|
+
}): Promise<ComposeResultResponse>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isUrlCaptchaPost } from '../netaceaPaths';
|
|
2
|
+
import { processCaptcha } from './processCaptcha';
|
|
3
|
+
import { check } from './check';
|
|
4
|
+
export async function processMitigateRequest(deps, config, args) {
|
|
5
|
+
const isCaptchaPost = isUrlCaptchaPost(args.url, args.method);
|
|
6
|
+
return await (isCaptchaPost
|
|
7
|
+
? processCaptcha(deps, config, args.mitata, args.clientIp, args.userAgent, await args.getBodyFn())
|
|
8
|
+
: check(deps, config, args.mitata, args.clientIp, args.userAgent, args.accept, args.host, args.mitataCaptcha));
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=processMitigateRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processMitigateRequest.js","sourceRoot":"","sources":["../../../src/helpers/processMitigateRequest.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,IAA+B,EAC/B,MAAoC,EACpC,IAAmE;IAEnE,MAAM,aAAa,GAAG,gBAAgB,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;IAC7D,OAAO,MAAM,CAAC,aAAa;QACzB,CAAC,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;QAClG,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,CAC9G,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="akamai-edgeworkers" />
|
|
2
|
+
import type { AkamaiRuntimeDependencies, AkamaiWorkerConfig, Response } from '../types';
|
|
3
|
+
import { NetaceaMitigationResponse } from '@netacea/netaceaintegrationbase';
|
|
4
|
+
export declare function runMitigation(deps: AkamaiRuntimeDependencies, config: Readonly<AkamaiWorkerConfig>, args: EW.IngressClientRequest): Promise<NetaceaMitigationResponse<Response>>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { NetaceaMitigationType } from '@netacea/netaceaintegrationbase';
|
|
2
|
+
import { mitigate } from './mitigate';
|
|
3
|
+
import { inject } from './inject';
|
|
4
|
+
import { processIngest } from './processIngest';
|
|
5
|
+
export async function runMitigation(deps, config, args) {
|
|
6
|
+
try {
|
|
7
|
+
switch (config.mitigationType) {
|
|
8
|
+
case NetaceaMitigationType.MITIGATE:
|
|
9
|
+
return await mitigate(deps, config, args);
|
|
10
|
+
case NetaceaMitigationType.INJECT:
|
|
11
|
+
return await inject(deps, config, args);
|
|
12
|
+
case NetaceaMitigationType.INGEST:
|
|
13
|
+
return await processIngest(deps, config, args);
|
|
14
|
+
default:
|
|
15
|
+
throw new Error(`Netacea Error: Mitigation type ${config.mitigationType} not recognised`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
console.error('Netacea FAILOPEN Error:', e);
|
|
20
|
+
return {
|
|
21
|
+
injectHeaders: {
|
|
22
|
+
'x-netacea-captcha': '0',
|
|
23
|
+
'x-netacea-match': '0',
|
|
24
|
+
'x-netacea-mitigate': '0'
|
|
25
|
+
},
|
|
26
|
+
sessionStatus: ''
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=runMitigation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runMitigation.js","sourceRoot":"","sources":["../../../src/helpers/runMitigation.ts"],"names":[],"mappings":"AACA,OAAO,EAA6B,qBAAqB,EAAE,MAAM,iCAAiC,CAAA;AAClG,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/C,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,IAA+B,EAC/B,MAAoC,EACpC,IAA6B;IAE7B,IAAI;QACF,QAAQ,MAAM,CAAC,cAAc,EAAE;YAC7B,KAAK,qBAAqB,CAAC,QAAQ;gBACjC,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;YAC3C,KAAK,qBAAqB,CAAC,MAAM;gBAC/B,OAAO,MAAM,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;YACzC,KAAK,qBAAqB,CAAC,MAAM;gBAC/B,OAAO,MAAM,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;YAChD;gBAEE,MAAM,IAAI,KAAK,CAAC,kCAAkC,MAAM,CAAC,cAAc,iBAAiB,CAAC,CAAA;SAC5F;KACF;IAAC,OAAO,CAAC,EAAE;QAEV,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,CAAC,CAAC,CAAA;QAC3C,OAAO;YACL,aAAa,EAAE;gBACb,mBAAmB,EAAE,GAAG;gBACxB,iBAAiB,EAAE,GAAG;gBACtB,oBAAoB,EAAE,GAAG;aAC1B;YACD,aAAa,EAAE,EAAE;SAClB,CAAA;KACF;AACH,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { MakeCaptchaApiCallResponse } from '@netacea/netaceaintegrationbase';
|
|
2
|
+
import type { AkamaiRuntimeDependencies, AkamaiWorkerConfig } from '../types';
|
|
3
|
+
export declare function makeCaptchaApiCall(deps: AkamaiRuntimeDependencies, config: Readonly<AkamaiWorkerConfig>, netaceaCookie: string | undefined, clientIP: string, userAgent: string, captchaData: any): Promise<MakeCaptchaApiCallResponse>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { matchCookie } from '../helpers/matchCookie';
|
|
2
|
+
import { makeRequest } from '../helpers/makeRequest';
|
|
3
|
+
import { getApiCallResponseFromResponse } from './getApiCallResponseFromResponse';
|
|
4
|
+
export async function makeCaptchaApiCall(deps, config, netaceaCookie, clientIP, userAgent, captchaData) {
|
|
5
|
+
const headers = {
|
|
6
|
+
'X-Netacea-API-Key': config.apiKey,
|
|
7
|
+
'X-Netacea-Client-IP': clientIP,
|
|
8
|
+
'user-agent': userAgent,
|
|
9
|
+
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
|
|
10
|
+
};
|
|
11
|
+
const cookie = matchCookie(netaceaCookie);
|
|
12
|
+
if (cookie !== undefined) {
|
|
13
|
+
headers['X-Netacea-UserId'] = cookie.userId;
|
|
14
|
+
}
|
|
15
|
+
if (config.captchaSiteKey !== undefined && config.captchaSecretKey !== undefined) {
|
|
16
|
+
headers['X-Netacea-Captcha-Site-Key'] = config.captchaSiteKey;
|
|
17
|
+
headers['X-Netacea-Captcha-Secret-Key'] = config.captchaSecretKey;
|
|
18
|
+
}
|
|
19
|
+
const res = await makeRequest(deps, config, {
|
|
20
|
+
host: config.mitigationServiceUrl,
|
|
21
|
+
path: '/AtaVerifyCaptcha',
|
|
22
|
+
headers,
|
|
23
|
+
method: 'POST',
|
|
24
|
+
body: captchaData,
|
|
25
|
+
timeout: config.timeout
|
|
26
|
+
});
|
|
27
|
+
return await getApiCallResponseFromResponse(deps, config, undefined, res, cookie?.userId, clientIP);
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=makeCaptchaApiCall.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeCaptchaApiCall.js","sourceRoot":"","sources":["../../../src/mitigation/makeCaptchaApiCall.ts"],"names":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
|
+
import type { MakeMitigateAPICallResponse } from '@netacea/netaceaintegrationbase';
|
|
2
|
+
import type { AkamaiRuntimeDependencies, AkamaiWorkerConfig } from '../types';
|
|
3
|
+
export declare function makeMitigateApiCall(deps: AkamaiRuntimeDependencies, config: Readonly<AkamaiWorkerConfig>, userId: string | undefined, clientIP: string, userAgent: string, captchaCookie: string | undefined, accept: string, host: string): Promise<MakeMitigateAPICallResponse>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { buildCookieHeader } from '../helpers/buildCookieHeader';
|
|
2
|
+
import { acceptHeaderToNetaceaContentType, mitSvcJsonResponseToUrlResponse } from '../helpers/captchaContentNegotiation';
|
|
3
|
+
import { makeRequest } from '../helpers/makeRequest';
|
|
4
|
+
import { getApiCallResponseFromResponse } from './getApiCallResponseFromResponse';
|
|
5
|
+
export async function makeMitigateApiCall(deps, config, userId, clientIP, userAgent, captchaCookie, accept, host) {
|
|
6
|
+
const headers = {
|
|
7
|
+
'X-Netacea-API-Key': config.apiKey,
|
|
8
|
+
'X-Netacea-Client-IP': clientIP,
|
|
9
|
+
'user-agent': userAgent,
|
|
10
|
+
'cookie': buildCookieHeader({
|
|
11
|
+
_mitatacaptcha: captchaCookie
|
|
12
|
+
})
|
|
13
|
+
};
|
|
14
|
+
if (userId !== undefined) {
|
|
15
|
+
headers['X-Netacea-UserId'] = userId;
|
|
16
|
+
}
|
|
17
|
+
if (config.captchaSiteKey !== undefined && config.captchaSecretKey !== undefined) {
|
|
18
|
+
headers['X-Netacea-Captcha-Site-Key'] = config.captchaSiteKey;
|
|
19
|
+
headers['X-Netacea-Captcha-Secret-Key'] = config.captchaSecretKey;
|
|
20
|
+
}
|
|
21
|
+
if (config.captchaContentNegotiation && config.netaceaCaptchaPath !== undefined) {
|
|
22
|
+
headers['X-Netacea-Captcha-Content-Type'] = acceptHeaderToNetaceaContentType(accept);
|
|
23
|
+
}
|
|
24
|
+
const isJsonRequest = headers['X-Netacea-Captcha-Content-Type'] === 'application/json';
|
|
25
|
+
const res = await makeRequest(deps, config, {
|
|
26
|
+
host: config.mitigationServiceUrl,
|
|
27
|
+
path: '/',
|
|
28
|
+
headers,
|
|
29
|
+
method: 'GET',
|
|
30
|
+
timeout: config.timeout
|
|
31
|
+
});
|
|
32
|
+
if (isJsonRequest && config.netaceaCaptchaPath !== undefined) {
|
|
33
|
+
res.body = mitSvcJsonResponseToUrlResponse(res.body, host, config.netaceaCaptchaPath);
|
|
34
|
+
}
|
|
35
|
+
return await getApiCallResponseFromResponse(deps, config, undefined, res, userId, clientIP);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=makeMitigateApiCall.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeMitigateApiCall.js","sourceRoot":"","sources":["../../../src/mitigation/makeMitigateApiCall.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAChE,OAAO,EAAE,gCAAgC,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAA;AACxH,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACpD,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAA;AAEjF,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,IAA+B,EAC/B,MAAoC,EACpC,MAA0B,EAC1B,QAAgB,EAChB,SAAiB,EACjB,aAAiC,EACjC,MAAc,EACd,IAAY;IAEZ,MAAM,OAAO,GAA8B;QACzC,mBAAmB,EAAE,MAAM,CAAC,MAAgB;QAC5C,qBAAqB,EAAE,QAAQ;QAC/B,YAAY,EAAE,SAAS;QACvB,QAAQ,EAAE,iBAAiB,CAAC;YAC1B,cAAc,EAAE,aAAa;SAC9B,CAAC;KACH,CAAA;IAED,IAAI,MAAM,KAAK,SAAS,EAAE;QACxB,OAAO,CAAC,kBAAkB,CAAC,GAAG,MAAM,CAAA;KACrC;IAED,IAAI,MAAM,CAAC,cAAc,KAAK,SAAS,IAAI,MAAM,CAAC,gBAAgB,KAAK,SAAS,EAAE;QAChF,OAAO,CAAC,4BAA4B,CAAC,GAAG,MAAM,CAAC,cAAc,CAAA;QAC7D,OAAO,CAAC,8BAA8B,CAAC,GAAG,MAAM,CAAC,gBAAgB,CAAA;KAClE;IAED,IAAI,MAAM,CAAC,yBAAyB,IAAI,MAAM,CAAC,kBAAkB,KAAK,SAAS,EAAE;QAC/E,OAAO,CAAC,gCAAgC,CAAC,GAAG,gCAAgC,CAAC,MAAM,CAAC,CAAA;KACrF;IAED,MAAM,aAAa,GAAG,OAAO,CAAC,gCAAgC,CAAC,KAAK,kBAAkB,CAAA;IACtF,MAAM,GAAG,GAAG,MAAM,WAAW,CAC3B,IAAI,EACJ,MAAM,EACN;QACE,IAAI,EAAE,MAAM,CAAC,oBAA8B;QAC3C,IAAI,EAAE,GAAG;QACT,OAAO;QACP,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,MAAM,CAAC,OAAO;KACxB,CACF,CAAA;IAED,IAAI,aAAa,IAAI,MAAM,CAAC,kBAAkB,KAAK,SAAS,EAAE;QAC5D,GAAG,CAAC,IAAI,GAAG,+BAA+B,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAA;KACtF;IAED,OAAO,MAAM,8BAA8B,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAA;AAC7F,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netacea/akamai",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.77",
|
|
4
4
|
"description": "Netacea Akamai CDN Integration",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"license": "ISC",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@netacea/netaceaintegrationbase": "^1.16.
|
|
23
|
+
"@netacea/netaceaintegrationbase": "^1.16.83",
|
|
24
24
|
"buffer": "^6.0.3",
|
|
25
25
|
"jssha": "^3.3.0"
|
|
26
26
|
},
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"tslib": "^2.0.3",
|
|
68
68
|
"typescript": "^4.0.3"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "3a4f7a265c6ab6623ce193fe964da6b33a4f4b6d"
|
|
71
71
|
}
|