@netacea/f5 4.3.147 → 5.0.2
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.d.ts +18 -4
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -403,6 +403,11 @@ interface F5ConstructorArgs extends NetaceaBaseArgs {
|
|
|
403
403
|
* If the key is invalid, a warning will be logged and cookies will remain unencrypted.
|
|
404
404
|
*/
|
|
405
405
|
cookieEncryptionKey?: string;
|
|
406
|
+
/**
|
|
407
|
+
* Enable debug logging for header fingerprint computation.
|
|
408
|
+
* When true, logs header names and computed fingerprint in logfmt format.
|
|
409
|
+
*/
|
|
410
|
+
debugMode?: boolean;
|
|
406
411
|
}
|
|
407
412
|
interface F5Response {
|
|
408
413
|
body?: string;
|
|
@@ -419,6 +424,7 @@ interface F5MitigateArgs {
|
|
|
419
424
|
mitataCookie?: string;
|
|
420
425
|
mitataCaptchaCookie?: string;
|
|
421
426
|
body?: any;
|
|
427
|
+
headerFingerprint?: string;
|
|
422
428
|
}
|
|
423
429
|
interface F5IngestArgs {
|
|
424
430
|
ip: string;
|
|
@@ -432,6 +438,7 @@ interface F5IngestArgs {
|
|
|
432
438
|
requestTime: string;
|
|
433
439
|
mitataCookie?: string;
|
|
434
440
|
sessionStatus?: string;
|
|
441
|
+
headerFingerprint?: string;
|
|
435
442
|
}
|
|
436
443
|
type NetaceaF5InjectHeaders = [
|
|
437
444
|
string,
|
|
@@ -450,7 +457,8 @@ interface F5Res {
|
|
|
450
457
|
string,
|
|
451
458
|
boolean,
|
|
452
459
|
string,
|
|
453
|
-
NetaceaF5InjectHeaders
|
|
460
|
+
NetaceaF5InjectHeaders,
|
|
461
|
+
string
|
|
454
462
|
] | string) => void;
|
|
455
463
|
}
|
|
456
464
|
interface IlxServer {
|
|
@@ -499,7 +507,7 @@ declare abstract class NetaceaBase<RequestArgs = unknown, Response = unknown> im
|
|
|
499
507
|
private makeIngestApiCall;
|
|
500
508
|
private constructV1WebLog;
|
|
501
509
|
protected constructWebLog(args: IngestArgs): WebLog;
|
|
502
|
-
protected check(netaceaCookie: string | undefined, clientIP: string, userAgent: string, captchaCookie?: string): Promise<ComposeResultResponse>;
|
|
510
|
+
protected check(netaceaCookie: string | undefined, clientIP: string, userAgent: string, captchaCookie?: string, headerFingerprint?: string): Promise<ComposeResultResponse>;
|
|
503
511
|
protected createMitata(clientIP: string, userId: string | undefined, match: string, mitigate: string, captcha: string, maxAge?: number, expiry?: number | undefined): Promise<string>;
|
|
504
512
|
private processCaptcha;
|
|
505
513
|
private getMitataCaptchaFromHeaders;
|
|
@@ -511,7 +519,7 @@ declare abstract class NetaceaBase<RequestArgs = unknown, Response = unknown> im
|
|
|
511
519
|
protected findBestMitigation(match: string, mitigate: string, captcha: string, isCaptchaPost: boolean): FindBestMitigationResponse;
|
|
512
520
|
protected APIError(response: APICallResponse): Error;
|
|
513
521
|
protected isUrlCaptchaPost(url: string, method: string): boolean;
|
|
514
|
-
protected processMitigateRequest(args: ProcessMitigateRequestArgs): Promise<ComposeResultResponse>;
|
|
522
|
+
protected processMitigateRequest(args: ProcessMitigateRequestArgs, headerFingerprint?: string): Promise<ComposeResultResponse>;
|
|
515
523
|
protected setIngestOnlyMitataCookie(userId: string | undefined): Promise<NetaceaResponseBase>;
|
|
516
524
|
protected processIngest(args: RequestArgs): Promise<NetaceaResponseBase>;
|
|
517
525
|
protected encryptCookieValue(cookieValue: string): Promise<string>;
|
|
@@ -521,9 +529,13 @@ declare class F5 extends NetaceaBase<F5MitigateArgs | F5IngestArgs, F5Response>
|
|
|
521
529
|
private readonly httpsAgent;
|
|
522
530
|
private readonly mitataCookieName;
|
|
523
531
|
private readonly mitataCaptchaCookieName;
|
|
532
|
+
private readonly hashGenerator;
|
|
533
|
+
private readonly debugMode;
|
|
524
534
|
private readonly encryptionEnabled;
|
|
525
535
|
private readonly encryptionKeyBuffer;
|
|
536
|
+
private readonly mitigationHeaders;
|
|
526
537
|
constructor(args: F5ConstructorArgs);
|
|
538
|
+
private computeHeaderFingerprint;
|
|
527
539
|
/**
|
|
528
540
|
* Encrypts a cookie value using JWE A256GCM if encryption is enabled.
|
|
529
541
|
*/
|
|
@@ -538,7 +550,9 @@ declare class F5 extends NetaceaBase<F5MitigateArgs | F5IngestArgs, F5Response>
|
|
|
538
550
|
*/
|
|
539
551
|
protected createMitata(clientIP: string, userId: string | undefined, match: string, mitigate: string, captcha: string, maxAge?: number, expiry?: number | undefined): Promise<string>;
|
|
540
552
|
private getInjectHeaders;
|
|
553
|
+
registerPolicyHandler(ilx: IlxServer): void;
|
|
541
554
|
registerMitigateHandler(ilx: IlxServer): void;
|
|
555
|
+
private parseHeaderValues;
|
|
542
556
|
private getValueOrDefault;
|
|
543
557
|
private getArrayValueOrDefault;
|
|
544
558
|
private getMitataCookies;
|
|
@@ -548,7 +562,7 @@ declare class F5 extends NetaceaBase<F5MitigateArgs | F5IngestArgs, F5Response>
|
|
|
548
562
|
protected mitigate(args: F5MitigateArgs): Promise<MitigateResponse<F5Response>>;
|
|
549
563
|
protected inject(args: F5MitigateArgs): Promise<InjectResponse>;
|
|
550
564
|
private getMitigationResponse;
|
|
551
|
-
ingest({ ip, userAgent, status, method, path, protocol, referer, bytesSent, requestTime, mitataCookie, sessionStatus }: F5IngestArgs): Promise<any>;
|
|
565
|
+
ingest({ ip, userAgent, status, method, path, protocol, referer, bytesSent, requestTime, mitataCookie, sessionStatus, headerFingerprint }: F5IngestArgs): Promise<any>;
|
|
552
566
|
getCookieHeader(args: F5IngestArgs): string | undefined;
|
|
553
567
|
}
|
|
554
568
|
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(t,n,i){return n=a(n),function(t,r){if(r&&("object"==e(r)||"function"==typeof r))return r;if(void 0!==r)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(t)}(t,r()?Reflect.construct(n,i||[],a(t).constructor):n.apply(t,i))}function r(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(r=function(){return!!e})()}function a(e){return a=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},a(e)}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}function i(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */i=function(){return r};var t,r={},a=Object.prototype,n=a.hasOwnProperty,o=Object.defineProperty||function(e,t,r){e[t]=r.value},c="function"==typeof Symbol?Symbol:{},s=c.iterator||"@@iterator",u=c.asyncIterator||"@@asyncIterator",p=c.toStringTag||"@@toStringTag";function h(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{h({},"")}catch(t){h=function(e,t,r){return e[t]=r}}function l(e,t,r,a){var n=t&&t.prototype instanceof k?t:k,i=Object.create(n.prototype),c=new _(a||[]);return o(i,"_invoke",{value:N(e,r,c)}),i}function f(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}r.wrap=l;var d="suspendedStart",v="suspendedYield",y="executing",m="completed",g={};function k(){}function b(){}function x(){}var C={};h(C,s,(function(){return this}));var w=Object.getPrototypeOf,S=w&&w(w(j([])));S&&S!==a&&n.call(S,s)&&(C=S);var A=x.prototype=k.prototype=Object.create(C);function I(e){["next","throw","return"].forEach((function(t){h(e,t,(function(e){return this._invoke(t,e)}))}))}function E(t,r){function a(i,o,c,s){var u=f(t[i],t,o);if("throw"!==u.type){var p=u.arg,h=p.value;return h&&"object"==e(h)&&n.call(h,"__await")?r.resolve(h.__await).then((function(e){a("next",e,c,s)}),(function(e){a("throw",e,c,s)})):r.resolve(h).then((function(e){p.value=e,c(p)}),(function(e){return a("throw",e,c,s)}))}s(u.arg)}var i;o(this,"_invoke",{value:function(e,t){function n(){return new r((function(r,n){a(e,t,r,n)}))}return i=i?i.then(n,n):n()}})}function N(e,r,a){var n=d;return function(i,o){if(n===y)throw Error("Generator is already running");if(n===m){if("throw"===i)throw o;return{value:t,done:!0}}for(a.method=i,a.arg=o;;){var c=a.delegate;if(c){var s=T(c,a);if(s){if(s===g)continue;return s}}if("next"===a.method)a.sent=a._sent=a.arg;else if("throw"===a.method){if(n===d)throw n=m,a.arg;a.dispatchException(a.arg)}else"return"===a.method&&a.abrupt("return",a.arg);n=y;var u=f(e,r,a);if("normal"===u.type){if(n=a.done?m:v,u.arg===g)continue;return{value:u.arg,done:a.done}}"throw"===u.type&&(n=m,a.method="throw",a.arg=u.arg)}}}function T(e,r){var a=r.method,n=e.iterator[a];if(n===t)return r.delegate=null,"throw"===a&&e.iterator.return&&(r.method="return",r.arg=t,T(e,r),"throw"===r.method)||"return"!==a&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+a+"' method")),g;var i=f(n,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,g;var o=i.arg;return o?o.done?(r[e.resultName]=o.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,g):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,g)}function O(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function P(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function _(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(O,this),this.reset(!0)}function j(r){if(r||""===r){var a=r[s];if(a)return a.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var i=-1,o=function e(){for(;++i<r.length;)if(n.call(r,i))return e.value=r[i],e.done=!1,e;return e.value=t,e.done=!0,e};return o.next=o}}throw new TypeError(e(r)+" is not iterable")}return b.prototype=x,o(A,"constructor",{value:x,configurable:!0}),o(x,"constructor",{value:b,configurable:!0}),b.displayName=h(x,p,"GeneratorFunction"),r.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===b||"GeneratorFunction"===(t.displayName||t.name))},r.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,x):(e.__proto__=x,h(e,p,"GeneratorFunction")),e.prototype=Object.create(A),e},r.awrap=function(e){return{__await:e}},I(E.prototype),h(E.prototype,u,(function(){return this})),r.AsyncIterator=E,r.async=function(e,t,a,n,i){void 0===i&&(i=Promise);var o=new E(l(e,t,a,n),i);return r.isGeneratorFunction(t)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},I(A),h(A,p,"Generator"),h(A,s,(function(){return this})),h(A,"toString",(function(){return"[object Generator]"})),r.keys=function(e){var t=Object(e),r=[];for(var a in t)r.push(a);return r.reverse(),function e(){for(;r.length;){var a=r.pop();if(a in t)return e.value=a,e.done=!1,e}return e.done=!0,e}},r.values=j,_.prototype={constructor:_,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(P),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function a(a,n){return c.type="throw",c.arg=e,r.next=a,n&&(r.method="next",r.arg=t),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],c=o.completion;if("root"===o.tryLoc)return a("end");if(o.tryLoc<=this.prev){var s=n.call(o,"catchLoc"),u=n.call(o,"finallyLoc");if(s&&u){if(this.prev<o.catchLoc)return a(o.catchLoc,!0);if(this.prev<o.finallyLoc)return a(o.finallyLoc)}else if(s){if(this.prev<o.catchLoc)return a(o.catchLoc,!0)}else{if(!u)throw Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return a(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var i=a;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var o=i?i.completion:{};return o.type=e,o.arg=t,i?(this.method="next",this.next=i.finallyLoc,g):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),g},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),P(r),g}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var a=r.completion;if("throw"===a.type){var n=a.arg;P(r)}return n}}throw Error("illegal catch attempt")},delegateYield:function(e,r,a){return this.delegate={iterator:j(e),resultName:r,nextLoc:a},"next"===this.method&&(this.arg=t),g}},r}function o(e){return function(e){if(Array.isArray(e))return k(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||g(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,v(a.key),a)}}function u(e,t,r){return t&&s(e.prototype,t),r&&s(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function p(e,t,r,a,n,i,o){try{var c=e[i](o),s=c.value}catch(e){return void r(e)}c.done?t(s):Promise.resolve(s).then(a,n)}function h(e){return function(){var t=this,r=arguments;return new Promise((function(a,n){var i=e.apply(t,r);function o(e){p(i,a,n,o,c,"next",e)}function c(e){p(i,a,n,o,c,"throw",e)}o(void 0)}))}}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function f(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?l(Object(r),!0).forEach((function(t){d(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):l(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function d(e,t,r){return(t=v(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function v(t){var r=function(t,r){if("object"!=e(t)||!t)return t;var a=t[Symbol.toPrimitive];if(void 0!==a){var n=a.call(t,r||"default");if("object"!=e(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==e(r)?r:r+""}function y(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=g(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var a=0,n=function(){};return{s:n,n:function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}},e:function(e){throw e},f:n}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,o=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return o=e.done,e},e:function(e){c=!0,i=e},f:function(){try{o||null==r.return||r.return()}finally{if(c)throw i}}}}function m(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var a,n,i,o,c=[],s=!0,u=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;s=!1}else for(;!(s=(a=i.call(r)).done)&&(c.push(a.value),c.length!==t);s=!0);}catch(e){u=!0,n=e}finally{try{if(!s&&null!=r.return&&(o=r.return(),Object(o)!==o))return}finally{if(u)throw n}}return c}}(e,t)||g(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e,t){if(e){if("string"==typeof e)return k(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?k(e,t):void 0}}function k(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,a=Array(t);r<t;r++)a[r]=e[r];return a}var b=require("crypto"),x=require("buffer"),C=require("https"),w=require("aws4");function S(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var a=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,a.get?a:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var A,I,E,N=S(C);!function(e){e.ORIGIN="ORIGIN",e.HTTP="HTTP",e.KINESIS="KINESIS",e.NATIVE="NATIVE"}(A||(A={})),function(e){e.MITIGATE="MITIGATE",e.INJECT="INJECT",e.INGEST="INGEST"}(I||(I={})),function(e){e.CAPTCHA_GET="captcha_get",e.CAPTCHA_POST="captcha_post",e.EXPIRED_SESSION="expired_session",e.FORCED_REVALIDATION="forced_revalidation",e.INVALID_SESSION="invalid_session",e.IP_CHANGE="ip_change",e.NO_SESSION="no_session"}(E||(E={}));var T=3e3;var O="_/@#/",P={none:"",block:"block",captcha:"captcha",allow:"allow",captchaPass:"captchapass"},_={0:P.none,1:P.block,2:P.none,3:P.block,4:P.none},j={1:P.captcha,2:P.captchaPass,3:P.captcha,4:P.allow,5:P.captcha,6:P.allow,7:P.captcha,a:P.captcha,b:P.captchaPass,c:P.captcha,d:P.allow,e:P.captcha},K=Object.freeze({__proto__:null,COOKIEDELIMITER:O,bestMitigationCaptchaMap:j,bestMitigationMap:_,captchaMap:{0:"",1:"captcha_serve",2:"captcha_pass",3:"captcha_fail",4:"captcha_cookiepass",5:"captcha_cookiefail",6:"checkpoint_signal",7:"checkpoint_post",a:"checkpoint_serve",b:"checkpoint_pass",c:"checkpoint_fail",d:"checkpoint_cookiepass",e:"checkpoint_cookiefail"},captchaStatusCodes:{"":0,captchaServe:1,captchaPass:2,captchaFail:3,captchaCookiePass:4,captchaCookieFail:5,checkpointSignal:6,checkpointPost:7,checkpointServe:"a",checkpointPass:"b",checkpointFail:"c",checkpointCookiePass:"d",checkpointCookieFail:"e"},matchMap:{0:"",1:"ua_",2:"ip_",3:"visitor_",4:"datacenter_",5:"sev_",6:"organisation_",7:"asn_",8:"country_",9:"combination_",b:"headerFP_"},mitigateMap:{0:"",1:"blocked",2:"allow",3:"hardblocked",4:"flagged"},mitigationTypes:P,netaceaCookieV3KeyMap:{clientIP:"cip",userId:"uid",gracePeriod:"grp",cookieId:"cid",match:"mat",mitigate:"mit",captcha:"cap",issueTimestamp:"ist",issueReason:"isr"},netaceaCookieV3OptionalKeyMap:{checkAllPostRequests:"fCAPR"},netaceaHeaders:{match:"x-netacea-match",mitigate:"x-netacea-mitigate",captcha:"x-netacea-captcha",mitata:"x-netacea-mitata-value",mitataExpiry:"x-netacea-mitata-expiry",mitataCaptcha:"x-netacea-mitatacaptcha-value",mitataCaptchaExpiry:"x-netacea-mitatacaptcha-expiry",eventId:"x-netacea-event-id"},netaceaSettingsMap:{checkAllPostRequests:"checkAllPostRequests"}}),M="ignored",D="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""),R=/^(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/((\d|[a-z])(\d)(\d|[a-z]))$/i;function L(e){if(void 0!==e){var t=e.match(R);if(null!=t){var r=m(t,9);return{signature:r[1],expiry:r[2],userId:r[3],ipHash:r[4],mitigationType:r[5],match:r[6],mitigate:r[7],captcha:r[8]}}}}function V(e,t,r,a){var n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"000";void 0===t&&(t=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:16,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:D,r=b.randomBytes(e-1),a=Array.from(r).map((function(e){return t[e%t.length]})).join("");return"c".concat(a)}());var i=[r,t,H(e+"|"+String(r),a),n].join(O),o=H(i,a);return"".concat(o).concat(O).concat(i)}function H(e,t){var r=b.createHmac("sha256",t);return r.update(e),x.Buffer.from(r.digest("hex")).toString("base64")}function B(e,t,r){var a={mitata:void 0,requiresReissue:!1,isExpired:!1,shouldExpire:!1,isSameIP:!1,isPrimaryHashValid:!1,captcha:"0",match:"0",mitigate:"0"};if("string"!=typeof e||""===e)return a;var n=L(e);if(void 0!==n){var i=[n.expiry,n.userId,n.ipHash,n.mitigationType].join(O),o=Math.floor(Date.now()/1e3),c=parseInt(n.expiry)<o,s=["1","3","5","a","c","e"].includes(n.captcha),u="3"===n.mitigate,p=s||u,h=H(t+"|"+n.expiry,r),l=n.ipHash===h;return{mitata:n,requiresReissue:c||!l,isExpired:c,shouldExpire:p,isSameIP:l,isPrimaryHashValid:n.signature===H(i,r),match:n.match,mitigate:n.mitigate,captcha:n.captcha,userId:n.userId}}return a}function q(e,t){var r=e.split(";").map((function(e){return e.trim()})).filter((function(e){return e.toLowerCase().startsWith(t.toLowerCase())}))[0];return void 0!==r&&r.length>0?null==r?void 0:r.replace("".concat(t,"="),""):void 0}function G(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return"string"!=typeof e&&(e=e.join("; ")),""===e?"":U(e.split(";"),t).join("; ")}function U(e){if(arguments.length>1&&void 0!==arguments[1]&&arguments[1])return U(e.reverse()).reverse();var t,r=new Set,a=[],n=y(e);try{for(n.s();!(t=n.n()).done;){var i=t.value;if(""!==(i=i.trimStart()).trim()){var o=i.split("=")[0].toUpperCase();r.has(o)||(r.add(o),a.push(i))}}}catch(e){n.e(e)}finally{n.f()}return a}function z(e){var t,r,a=G([null!==(t=e.otherAttributes)&&void 0!==t?t:"","Max-Age=".concat(null!==(r=e.maxAgeAttribute)&&void 0!==r?r:86400),"Path=/"].join("; "));return"".concat(e.cookieName,"=").concat(e.cookieValue,"; ").concat(a)}var F={cookie:{attributes:Object.freeze({__proto__:null,configureCookiesDomain:function(e,t){var r=e=G(null!=e?e:"",!0),a=t=G(null!=t?t:"",!0);if(void 0!==e&&void 0!==t){var n=q(e,"Domain"),i=q(t,"Domain");void 0!==n&&void 0!==i?a=t.replace(i,n):void 0!==n&&void 0===i?a=t+(""!==t?"; Domain=".concat(n):"Domain=".concat(n)):void 0===n&&void 0!==i&&(r=e+(""!==e?"; Domain=".concat(i):"Domain=".concat(i)))}else if(void 0!==e&&void 0===t){var o=q(e,"Domain");void 0!==o&&(a="Domain=".concat(o))}else if(void 0===e&&void 0!==t){var c=q(t,"Domain");void 0!==c&&(r="Domain=".concat(c))}return{cookieAttributes:""!==r?r:void 0,captchaCookieAttributes:""!==a?a:void 0}},extractAndRemoveCookieAttr:function(e,t){var r=q(e,t);return void 0!==r?{extractedAttribute:r,cookieAttributes:e.replace(/ /g,"").replace("".concat(t,"=").concat(r),"").split(";").filter((function(e){return e.length>0})).join("; ")}:{extractedAttribute:void 0,cookieAttributes:e}},extractCookieAttr:q,removeDuplicateAttrs:G}),netaceaSession:Object.freeze({__proto__:null,createNetaceaCaptchaSetCookieString:function(e){var t;return z(f(f({},e),{},{cookieName:null!==(t=e.cookieName)&&void 0!==t?t:"_mitatacaptcha"}))},createNetaceaSetCookieString:function(e){var t;return z(f(f({},e),{},{cookieName:null!==(t=e.cookieName)&&void 0!==t?t:"_mitata"}))},createSetCookieString:z})}};function J(e){return e.toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function X(e){var t=(e+"===".slice(0,(4-e.length%4)%4)).replace(/-/g,"+").replace(/_/g,"/");return Buffer.from(t,"base64")}var W="eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0";function Y(e,t){var r=b.randomBytes(12),a=b.createCipheriv("aes-256-gcm",t,r),n=Buffer.from(W,"ascii");a.setAAD(n);var i=a.update(e,"utf8");i=Buffer.concat([i,a.final()]);var o=a.getAuthTag();return[W,"",J(r),J(i),J(o)].join(".")}function $(e,t){var r=e.split(".");if(5!==r.length)throw new Error("JWE should have 5 parts, got ".concat(r.length));var a=m(r,5),n=a[0],i=a[1],o=a[2],c=a[3],s=a[4];if(n!==W)throw new Error("Incorrect JWE header");if(""!==i)throw new Error("Expected empty encrypted key for direct encryption");var u=X(o),p=X(c),h=X(s);if(12!==u.length)throw new Error("IV must be ".concat(12," bytes, got ").concat(u.length));if(16!==h.length)throw new Error("Auth tag must be ".concat(16," bytes, got ").concat(h.length));var l=b.createDecipheriv("aes-256-gcm",t,u),f=Buffer.from(n,"ascii");l.setAAD(f),l.setAuthTag(h);var d=l.update(p);return(d=Buffer.concat([d,l.final()])).toString("utf8")}var Z={},Q={},ee={},te={};Object.defineProperty(te,"__esModule",{value:!0}),te.API_VERSION=te.REGION=te.PAYLOAD_TYPE=te.STATE=void 0,te.STATE={ACTIVE:"ACTIVE",UPDATING:"UPDATING",CREATING:"CREATING",DELETING:"DELETING"},te.PAYLOAD_TYPE="string",te.REGION="eu-west-1",te.API_VERSION="2013-12-02",Object.defineProperty(ee,"__esModule",{value:!0}),ee.signRequest=void 0;var re=w,ae=te;function ne(e,t){for(var r=[],a=0;a<e.length;a+=t){var n=e.slice(a,a+t);r.push({Data:Buffer.from(JSON.stringify(n)).toString("base64"),PartitionKey:Date.now().toString()})}return r}ee.signRequest=function(e,t,r){var a=e.accessKeyId,n=e.secretAccessKey,i={Records:ne(t,r),PartitionKey:Date.now().toString(),StreamName:e.streamName};return re.sign({service:"kinesis",body:JSON.stringify(i),headers:{"Content-Type":"application/x-amz-json-1.1","X-Amz-Target":"Kinesis_20131202.PutRecords"},region:ae.REGION},{accessKeyId:a,secretAccessKey:n})},Object.defineProperty(Q,"__esModule",{value:!0});var ie=ee;function oe(e){return ce.apply(this,arguments)}function ce(){return(ce=h(i().mark((function e(t){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,new Promise((function(e){setTimeout(e,t)}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var se=function(){return u((function e(t){var r=t.kinesisStreamName,a=t.kinesisAccessKey,n=t.kinesisSecretKey,i=t.maxLogAgeSeconds,o=t.logBatchSize,s=t.rampUpBatchSize,u=t.maxAwaitTimePerIngestCallMs;c(this,e),this.maxLogBatchSize=20,this.maxLogAgeSeconds=10,this.logBatchSize=20,this.logCache=[],this.intervalSet=!1,this.kinesisStreamName=r,this.kinesisAccessKey=a,this.kinesisSecretKey=n,this.maxAwaitTimePerIngestCallMs=u,void 0!==i&&i<this.maxLogAgeSeconds&&i>0&&(this.maxLogAgeSeconds=i),void 0!==o&&(this.maxLogBatchSize=o),this.logBatchSize=!0===s?1:this.maxLogBatchSize}),[{key:"putToKinesis",value:(t=h(i().mark((function e(t){var r,a,n,c;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(0!==this.logCache.length){e.next=1;break}return e.abrupt("return");case 1:return r=o(this.logCache),this.logCache=[],e.prev=2,a=(0,ie.signRequest)({streamName:this.kinesisStreamName,accessKeyId:this.kinesisAccessKey,secretAccessKey:this.kinesisSecretKey},r,this.logBatchSize),e.next=3,t({headers:a.headers,host:"https://".concat(a.hostname),method:a.method,path:a.path,body:a.body});case 3:this.logBatchSize!==this.maxLogBatchSize&&(this.logBatchSize=Math.min(this.maxLogBatchSize,2*this.logBatchSize)),e.next=5;break;case 4:e.prev=4,c=e.catch(2),(n=this.logCache).push.apply(n,o(r)),console.error(c);case 5:case"end":return e.stop()}}),e,this,[[2,4]])}))),function(e){return t.apply(this,arguments)})},{key:"ingest",value:(e=h(i().mark((function e(t,r){var a,n,o=this;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.logCache.push(t),!(this.logCache.length>=this.logBatchSize)){e.next=2;break}return(a=[]).push(this.putToKinesis(r)),void 0!==this.maxAwaitTimePerIngestCallMs&&a.push(oe(this.maxAwaitTimePerIngestCallMs)),e.next=1,Promise.race(a);case 1:e.next=3;break;case 2:if(this.intervalSet){e.next=3;break}if(this.intervalSet=!0,n=oe(1e3*this.maxLogAgeSeconds).then(h(i().mark((function e(){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,o.putToKinesis(r);case 1:o.intervalSet=!1;case 2:case"end":return e.stop()}}),e)})))).catch((function(){})),void 0!==this.maxAwaitTimePerIngestCallMs){e.next=3;break}return e.next=3,n;case 3:case"end":return e.stop()}}),e,this)}))),function(t,r){return e.apply(this,arguments)})}]);var e,t}();Q.default=se,Object.defineProperty(Z,"__esModule",{value:!0});var ue=Q,pe=Z.default=ue.default,he=F.cookie.attributes.configureCookiesDomain,le=F.cookie.netaceaSession,fe=le.createNetaceaSetCookieString,de=le.createNetaceaCaptchaSetCookieString,ve=function(){return u((function e(t){var r,a,n=t.apiKey,i=t.secretKey,o=t.timeout,s=void 0===o?3e3:o,u=t.mitigationServiceUrl,p=void 0===u?"https://mitigations.netacea.net":u,h=t.ingestServiceUrl,l=void 0===h?"https://ingest.netacea.net":h,v=t.mitigationType,y=void 0===v?I.INGEST:v,m=t.captchaSiteKey,g=t.captchaSecretKey,k=t.ingestType,b=void 0===k?A.HTTP:k,x=t.kinesis,C=t.mitataCookieExpirySeconds,w=t.netaceaCookieExpirySeconds,S=t.netaceaCookieName,E=t.netaceaCaptchaCookieName,N=t.netaceaCookieAttributes,O=t.netaceaCaptchaCookieAttributes;if(c(this,e),d(this,"mitataCookieExpirySeconds",void 0),d(this,"apiKey",void 0),d(this,"secretKey",void 0),d(this,"mitigationServiceUrl",void 0),d(this,"ingestServiceUrl",void 0),d(this,"timeout",void 0),d(this,"captchaSiteKey",void 0),d(this,"captchaSecretKey",void 0),d(this,"ingestType",void 0),d(this,"kinesis",void 0),d(this,"mitigationType",void 0),d(this,"encryptedCookies",[]),d(this,"netaceaCookieName",void 0),d(this,"netaceaCaptchaCookieName",void 0),d(this,"netaceaCookieAttributes",void 0),d(this,"netaceaCaptchaCookieAttributes",void 0),null==n)throw new Error("apiKey is a required parameter");this.apiKey=n,this.secretKey=i,this.mitigationServiceUrl=p,this.ingestServiceUrl=l,this.mitigationType=y,this.ingestType=null!=b?b:A.HTTP,this.ingestType===A.KINESIS&&(void 0===x?console.warn("NETACEA WARN: no kinesis args provided, when ingestType is ".concat(this.ingestType)):this.kinesis=new pe(f(f({},x),{},{apiKey:this.apiKey}))),void 0===m&&void 0===g||(this.captchaSiteKey=m,this.captchaSecretKey=g),this.timeout=function(e){return e<=0?T:e}(s),this.netaceaCookieName=me(S,"_mitata"),this.netaceaCaptchaCookieName=me(E,"_mitatacaptcha"),this.encryptedCookies=[this.netaceaCookieName,this.netaceaCaptchaCookieName],this.mitataCookieExpirySeconds=function(e,t){return void 0===t?e===I.INGEST?3600:60:t}(y,null!=w?w:C);var P=he(null!=N?N:"",null!=O?O:"");this.netaceaCookieAttributes=null!==(r=P.cookieAttributes)&&void 0!==r?r:"",this.netaceaCaptchaCookieAttributes=null!==(a=P.captchaCookieAttributes)&&void 0!==a?a:""}),[{key:"runMitigation",value:(C=h(i().mark((function e(t){var r,a,n,o,c;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.prev=0,o=this.mitigationType,e.next=o===I.MITIGATE?1:o===I.INJECT?3:o===I.INGEST?5:7;break;case 1:return e.next=2,this.mitigate(t);case 2:case 4:case 6:return e.abrupt("return",e.sent);case 3:return e.next=4,this.inject(t);case 5:return e.next=6,this.processIngest(t);case 7:throw new Error("Netacea Error: Mitigation type ".concat(this.mitigationType," not recognised"));case 8:e.next=10;break;case 9:return e.prev=9,c=e.catch(0),console.error("Netacea FAILOPEN Error:",c),r=t,a=this.isUrlCaptchaPost(r.url,r.method),n=this.mitigationType===I.MITIGATE,e.abrupt("return",{injectHeaders:{"x-netacea-captcha":"0","x-netacea-match":"0","x-netacea-mitigate":"0"},sessionStatus:n&&a?"error_open":""});case 10:case"end":return e.stop()}}),e,this,[[0,9]])}))),function(e){return C.apply(this,arguments)})},{key:"readCookie",value:(x=h(i().mark((function e(t,r){var a,n,o,c,s,u,p;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=r){e.next=1;break}return e.abrupt("return",void 0);case 1:if("string"!=typeof r){e.next=3;break}return e.next=2,this.readCookie(t,r.split(";"));case 2:return e.abrupt("return",e.sent);case 3:a="".concat(t,"="),n=y(r),e.prev=4,n.s();case 5:if((o=n.n()).done){e.next=11;break}if(c=o.value,!(s=c.split(";")[0].trimStart()).startsWith(a)){e.next=10;break}if(u=s.slice(a.length),!this.encryptedCookies.includes(t)){e.next=9;break}return e.prev=6,e.next=7,this.decryptCookieValue(u);case 7:return e.abrupt("return",e.sent);case 8:return e.prev=8,e.catch(6),e.abrupt("return",void 0);case 9:return e.abrupt("return",u);case 10:e.next=5;break;case 11:e.next=13;break;case 12:e.prev=12,p=e.catch(4),n.e(p);case 13:return e.prev=13,n.f(),e.finish(13);case 14:return e.abrupt("return",void 0);case 15:case"end":return e.stop()}}),e,this,[[4,12,13,14],[6,8]])}))),function(e,t){return x.apply(this,arguments)})},{key:"callIngest",value:(b=h(i().mark((function e(t){var r,a,n,o;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=this.constructWebLog(t),this.ingestType!==A.KINESIS){e.next=5;break}if(void 0!==this.kinesis){e.next=1;break}return console.error("Netacea Error: Unable to log as Kinesis has not been defined."),e.abrupt("return");case 1:return e.prev=1,e.next=2,this.kinesis.ingest(f(f({},r),{},{apiKey:this.apiKey}),this.makeRequest.bind(this));case 2:e.next=4;break;case 3:e.prev=3,o=e.catch(1),console.error("NETACEA Error: ",o.message);case 4:e.next=7;break;case 5:return a={"X-Netacea-API-Key":this.apiKey,"content-type":"application/json"},e.next=6,this.makeIngestApiCall(a,r);case 6:if(200===(n=e.sent).status){e.next=7;break}throw this.APIError(n);case 7:case"end":return e.stop()}}),e,this,[[1,3]])}))),function(e){return b.apply(this,arguments)})},{key:"makeIngestApiCall",value:(k=h(i().mark((function e(t,r){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,this.makeRequest({host:this.ingestServiceUrl,method:"POST",path:"/",headers:t,body:JSON.stringify(r),timeout:this.timeout});case 1:return e.abrupt("return",e.sent);case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return k.apply(this,arguments)})},{key:"constructV1WebLog",value:function(e){var t=e.ip,r=e.userAgent,a=e.status,n=e.method,i=e.path,o=e.protocol,c=e.referer,s=e.bytesSent,u=e.requestTime,p=e.mitataCookie,h=e.sessionStatus,l=e.integrationType,f=e.integrationVersion,d=(new Date).toUTCString();return{Request:"".concat(n," ").concat(i," ").concat(o),TimeLocal:d,RealIp:t,UserAgent:r,Status:a,RequestTime:null==u?void 0:u.toString(),BytesSent:null==s?void 0:s.toString(),Referer:""===c?"-":c,NetaceaUserIdCookie:null!=p?p:"",NetaceaMitigationApplied:null!=h?h:"",IntegrationType:null!=l?l:"",IntegrationVersion:null!=f?f:""}}},{key:"constructWebLog",value:function(e){return e.bytesSent=""===e.bytesSent?"0":e.bytesSent,this.constructV1WebLog(e)}},{key:"check",value:(g=h(i().mark((function e(t,r,a,n){var o,c,s,u,p,h,l,f,d,v,y,m;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0!==this.secretKey){e.next=1;break}throw new Error("Secret key is required to mitigate");case 1:if((f=B(t,r,this.secretKey)).isPrimaryHashValid&&!f.requiresReissue){e.next=4;break}return e.next=2,this.makeMitigateAPICall(null===(d=f.mitata)||void 0===d?void 0:d.userId,r,a,n);case 2:return y=e.sent,o=y.status,c=y.match,s=y.mitigate,u=y.captcha,p=y.body,e.next=3,this.createMitata(r,null===(v=f.mitata)||void 0===v?void 0:v.userId,c,s,u,y.mitataMaxAge);case 3:m=e.sent,h=[m],l=y.eventId,e.next=5;break;case 4:o=-1,c=f.match,s=f.mitigate,u=f.captcha,p=void 0,h=[];case 5:return e.abrupt("return",this.composeResult(p,h,o,c,s,u,!1,l));case 6:case"end":return e.stop()}}),e,this)}))),function(e,t,r,a){return g.apply(this,arguments)})},{key:"createMitata",value:(m=h(i().mark((function e(t,r,a,n,o){var c,s,u,p,h,l,f,d,v=arguments;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(c=v.length>5&&void 0!==v[5]?v[5]:86400,s=v.length>6&&void 0!==v[6]?v[6]:void 0,u=["1","3","5"].includes(o),p="3"===n,h=u||p?-60:this.mitataCookieExpirySeconds,l=null!=s?s:Math.floor(Date.now()/1e3)+h,void 0!==this.secretKey){e.next=1;break}throw new Error("Cannot build cookie without secret key.");case 1:return f=[a,n,o].join(""),d=V(t,r,l,this.secretKey,f),e.abrupt("return",fe({cookieName:this.netaceaCookieName,cookieValue:d,maxAgeAttribute:String(c),otherAttributes:this.netaceaCookieAttributes}));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,r,a,n){return m.apply(this,arguments)})},{key:"processCaptcha",value:(v=h(i().mark((function e(t,r,a,n){var o,c,s,u,p,h,l;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,this.makeCaptchaAPICall(t,r,a,n);case 1:return o=e.sent,c=o.status,s=o.match,u=o.mitigate,p=o.captcha,h=o.body,l=o.setCookie,e.abrupt("return",this.composeResult(h,l,c,s,u,p,!0));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,r,a){return v.apply(this,arguments)})},{key:"getMitataCaptchaFromHeaders",value:(l=h(i().mark((function e(t){var r,a,n;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!Object.prototype.hasOwnProperty.call(t,K.netaceaHeaders.mitataCaptcha)){e.next=3;break}if(r=t[K.netaceaHeaders.mitataCaptcha],Array.isArray(r)&&(r=r[0]),null!=r&&""!==r){e.next=1;break}return e.abrupt("return",void 0);case 1:return a=parseInt(t[K.netaceaHeaders.mitataCaptchaExpiry]),e.next=2,this.encryptCookieValue(r);case 2:return n=e.sent,e.abrupt("return",de({cookieName:this.netaceaCaptchaCookieName,cookieValue:n,maxAgeAttribute:String(isNaN(a)?86400:a),otherAttributes:this.netaceaCaptchaCookieAttributes}));case 3:return e.abrupt("return",void 0);case 4:case"end":return e.stop()}}),e,this)}))),function(e){return l.apply(this,arguments)})},{key:"makeCaptchaAPICall",value:(p=h(i().mark((function e(t,r,a,n){var o,c,s;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o={"X-Netacea-API-Key":this.apiKey,"X-Netacea-Client-IP":r,"user-agent":a,"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},void 0!==(c=L(t))&&(o["X-Netacea-UserId"]=c.userId),void 0!==this.captchaSiteKey&&void 0!==this.captchaSecretKey&&(o["X-Netacea-Captcha-Site-Key"]=this.captchaSiteKey,o["X-Netacea-Captcha-Secret-Key"]=this.captchaSecretKey),e.next=1,this.makeRequest({host:this.mitigationServiceUrl,path:"/AtaVerifyCaptcha",headers:o,method:"POST",body:n,timeout:this.timeout});case 1:return s=e.sent,e.next=2,this.getApiCallResponseFromResponse(s,null==c?void 0:c.userId,r);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,r,a){return p.apply(this,arguments)})},{key:"getApiCallResponseFromResponse",value:(s=h(i().mark((function e(t,r,a){var n,o,c,s,u,p,h,l,f,d,v,y,m,g;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(200===t.status){e.next=1;break}throw this.APIError(t);case 1:return h=null!==(n=null===(o=t.headers[K.netaceaHeaders.match])||void 0===o?void 0:o.toString())&&void 0!==n?n:"0",l=null!==(c=null===(s=t.headers[K.netaceaHeaders.mitigate])||void 0===s?void 0:s.toString())&&void 0!==c?c:"0",f=null!==(u=null===(p=t.headers[K.netaceaHeaders.captcha])||void 0===p?void 0:p.toString())&&void 0!==u?u:"0",d=parseInt(t.headers[K.netaceaHeaders.mitataExpiry]),isNaN(d)&&(d=86400),e.next=2,this.createMitata(a,r,h,l,f);case 2:return v=e.sent,e.next=3,this.getMitataCaptchaFromHeaders(t.headers);case 3:return y=e.sent,m=[v,y].filter((function(e){return void 0!==e})),g=t.headers[K.netaceaHeaders.eventId],e.abrupt("return",{status:t.status,match:h,mitigate:l,captcha:f,setCookie:m,body:t.body,eventId:g,mitataMaxAge:d});case 4:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return s.apply(this,arguments)})},{key:"buildCookieHeader",value:function(e){var t="",r="";for(var a in e){var n=e[a];void 0!==n&&(t="".concat(t).concat(r).concat(a,"=").concat(n),r="; ")}return t}},{key:"makeMitigateAPICall",value:(o=h(i().mark((function e(t,r,a,n){var o,c;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o={"X-Netacea-API-Key":this.apiKey,"X-Netacea-Client-IP":r,"user-agent":a,cookie:this.buildCookieHeader({_mitatacaptcha:n})},void 0!==t&&(o["X-Netacea-UserId"]=t),void 0!==this.captchaSiteKey&&void 0!==this.captchaSecretKey&&(o["X-Netacea-Captcha-Site-Key"]=this.captchaSiteKey,o["X-Netacea-Captcha-Secret-Key"]=this.captchaSecretKey),e.next=1,this.makeRequest({host:this.mitigationServiceUrl,path:"/",headers:o,method:"GET",timeout:this.timeout});case 1:return c=e.sent,e.next=2,this.getApiCallResponseFromResponse(c,t,r);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,r,a){return o.apply(this,arguments)})},{key:"composeResult",value:function(e,t,r,a,n,i,o,c){var s=this.findBestMitigation(a,n,i,o),u={body:e,apiCallStatus:r,setCookie:t,sessionStatus:s.sessionStatus,mitigation:s.mitigation,mitigated:[K.mitigationTypes.block,K.mitigationTypes.captcha,K.mitigationTypes.captchaPass].includes(s.mitigation)};if(this.mitigationType===I.INJECT){var p={"x-netacea-match":s.parts.match.toString(),"x-netacea-mitigate":s.parts.mitigate.toString(),"x-netacea-captcha":s.parts.captcha.toString()};void 0!==c&&(p["x-netacea-event-id"]=c),u.injectHeaders=p}return u}},{key:"findBestMitigation",value:function(e,t,r,a){var n,i,o="unknown";a||("2"===r?r="4":"3"===r&&(r="5"));var c=null!==(n=K.matchMap[e])&&void 0!==n?n:o+"_";c+=null!==(i=K.mitigateMap[t])&&void 0!==i?i:o;var s=K.bestMitigationMap[t];if("0"!==r){var u;c+=","+(null!==(u=K.captchaMap[r])&&void 0!==u?u:o);var p=K.bestMitigationCaptchaMap[r];void 0!==p&&(s=p)}return this.mitigationType===I.INJECT&&(s=K.mitigationTypes.none),{sessionStatus:c,mitigation:s,parts:{match:e,mitigate:t,captcha:r}}}},{key:"APIError",value:function(e){var t="Unknown error";switch(e.status){case 403:t="Invalid credentials";break;case 500:t="Server error";break;case 502:t="Bad Gateway";break;case 503:t="Service Unavailable";break;case 400:t="Invalid request"}return new Error("Error reaching Netacea API (".concat(t,"), status: ").concat(e.status))}},{key:"isUrlCaptchaPost",value:function(e,t){return e.includes("/AtaVerifyCaptcha")&&"post"===t.toLowerCase()}},{key:"processMitigateRequest",value:(n=h(i().mark((function e(t){var r,a,n,o,c,s;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.isUrlCaptchaPost(t.url,t.method)){e.next=2;break}return a=this,n=t.mitata,o=t.clientIp,c=t.userAgent,e.next=1,t.getBodyFn();case 1:s=e.sent,r=a.processCaptcha.call(a,n,o,c,s),e.next=3;break;case 2:r=this.check(t.mitata,t.clientIp,t.userAgent,t.mitataCaptcha);case 3:return e.next=4,r;case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"setIngestOnlyMitataCookie",value:(a=h(i().mark((function e(t){var r;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,this.createMitata(M,t,"0","0","0",86400);case 1:return r=e.sent,e.abrupt("return",{sessionStatus:"",setCookie:[r]});case 2:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"processIngest",value:(r=h(i().mark((function e(t){var r,a,n,o;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0!==this.secretKey){e.next=1;break}throw new Error("Secret key is required for ingest");case 1:return r=this.getCookieHeader(t),e.next=2,this.readCookie(this.netaceaCookieName,r);case 2:if(a=e.sent,(n=B(a,M,this.secretKey)).isPrimaryHashValid){e.next=4;break}return e.next=3,this.setIngestOnlyMitataCookie(void 0);case 3:case 5:return e.abrupt("return",e.sent);case 4:if(!n.requiresReissue){e.next=6;break}return e.next=5,this.setIngestOnlyMitataCookie(null===(o=n.mitata)||void 0===o?void 0:o.userId);case 6:return e.abrupt("return",{sessionStatus:"",setCookie:[]});case 7:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"encryptCookieValue",value:(t=h(i().mark((function e(t){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t);case 1:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})},{key:"decryptCookieValue",value:(e=h(i().mark((function e(t){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t);case 1:case"end":return e.stop()}}),e)}))),function(t){return e.apply(this,arguments)})}]);var e,t,r,a,n,o,s,p,l,v,m,g,k,b,x,C}(),ye=function(){function e(r){var a,n,i,o;if(c(this,e),d(o=t(this,e,[r]),"httpsAgent",void 0),d(o,"mitataCookieName",void 0),d(o,"mitataCaptchaCookieName",void 0),d(o,"encryptionEnabled",!1),d(o,"encryptionKeyBuffer",void 0),o.httpsAgent=new N.Agent({timeout:o.timeout,keepAlive:!0,maxSockets:null!==(a=r.maxSockets)&&void 0!==a?a:25}),o.mitataCookieName=null!==(n=r.netaceaCookieName)&&void 0!==n?n:"_mitata",o.mitataCaptchaCookieName=null!==(i=r.netaceaCaptchaCookieName)&&void 0!==i?i:"_mitatacaptcha",void 0!==r.cookieEncryptionKey){var s=function(e){if(null==e||""===e)return{valid:!1,error:"key is empty"};if(!/^[A-Za-z0-9_-]+$/.test(e))return{valid:!1,error:"key contains invalid base64url characters"};var t;try{t=X(e)}catch(e){return{valid:!1,error:"key is not valid base64url"}}return 32!==t.length?{valid:!1,error:"key must be ".concat(32," bytes (256 bits), got ").concat(t.length," bytes")}:{valid:!0,keyBuffer:t}}(r.cookieEncryptionKey);s.valid&&void 0!==s.keyBuffer?(o.encryptionKeyBuffer=s.keyBuffer,o.encryptionEnabled=!0):console.warn("NETACEA WARN: Invalid cookieEncryptionKey - ".concat(s.error,". Cookies will not be encrypted."))}return o}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&n(e,t)}(e,ve),u(e,[{key:"encryptCookieValue",value:(y=h(i().mark((function e(t){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.encryptionEnabled&&void 0!==this.encryptionKeyBuffer){e.next=1;break}return e.abrupt("return",t);case 1:return e.abrupt("return",Y(t,this.encryptionKeyBuffer));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return y.apply(this,arguments)})},{key:"decryptCookieValue",value:(v=h(i().mark((function e(t){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.encryptionEnabled&&void 0!==this.encryptionKeyBuffer){e.next=1;break}return e.abrupt("return",t);case 1:if(5===(r=t).split(".").length&&r.includes("..")){e.next=2;break}throw new Error("Cookie is not JWE encrypted");case 2:return e.abrupt("return",$(t,this.encryptionKeyBuffer));case 3:case"end":return e.stop()}var r}),e,this)}))),function(e){return v.apply(this,arguments)})},{key:"createMitata",value:(f=h(i().mark((function e(t,r,a,n,o){var c,s,u,p,h,l,f,d,v,y=arguments;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(c=y.length>5&&void 0!==y[5]?y[5]:86400,s=y.length>6&&void 0!==y[6]?y[6]:void 0,u=["1","3","5"].includes(o),p="3"===n,h=u||p?-60:this.mitataCookieExpirySeconds,l=null!=s?s:Math.floor(Date.now()/1e3)+h,void 0!==this.secretKey){e.next=1;break}throw new Error("Cannot build cookie without secret key.");case 1:return f=[a,n,o].join(""),d=V(t,r,l,this.secretKey,f),e.next=2,this.encryptCookieValue(d);case 2:return v=e.sent,e.abrupt("return",fe({cookieName:this.netaceaCookieName,cookieValue:v,maxAgeAttribute:String(c),otherAttributes:this.netaceaCookieAttributes}));case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,r,a,n){return f.apply(this,arguments)})},{key:"getInjectHeaders",value:function(e){if(this.mitigationType===I.INJECT){var t,r,a,n,i=e;if(void 0!==i.injectHeaders)return[null!==(t=i.injectHeaders["x-netacea-match"])&&void 0!==t?t:"0",null!==(r=i.injectHeaders["x-netacea-mitigate"])&&void 0!==r?r:"0",null!==(a=i.injectHeaders["x-netacea-captcha"])&&void 0!==a?a:"0",null!==(n=i.injectHeaders["x-netacea-event-id"])&&void 0!==n?n:""]}return[]}},{key:"registerMitigateHandler",value:function(e){var t=this;e.addMethod("handleRequest",function(){var e=h(i().mark((function e(r,a){var n,o,c,s,u,p,h,l,f,d,v,y,g,k,b,x,C,w,S;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.params(),o=m(n,5),c=o[0],s=o[1],u=o[2],p=o[3],h=o[4],l=6===n.length?t.getArrayValueOrDefault(n,5,void 0):void 0,e.prev=1,e.next=2,t.getMitataCookies(h);case 2:return f=e.sent,d=m(f,2),v=d[0],y=d[1],e.next=3,t.runMitigation({ip:c,method:u,url:p,mitataCaptchaCookie:y,mitataCookie:v,userAgent:s,body:l});case 3:if("error_open"!==(null==(g=e.sent)?void 0:g.sessionStatus)){e.next=4;break}return a.reply(["",500,[],"error_open",!0,"",[]]),e.abrupt("return");case 4:if(void 0!==g){e.next=5;break}return a.reply(["",0,[],"",!1,"",[]]),e.abrupt("return");case 5:k="",b=0,x=!1,C=t.getValueOrDefault(v,""),void 0!==g.setCookie&&g.setCookie.length>0&&void 0!==(w=g.setCookie.find((function(e){return e.includes("".concat(t.netaceaCookieName,"="))})))&&(C=w.split(";")[0].replace("".concat(t.netaceaCookieName,"="),"")),void 0!==g.response&&(b=g.response.apiCallStatus,k=t.getValueOrDefault(g.response.body,"Forbidden"),x=t.getValueOrDefault(g.response.mitigated,x)),a.reply([k,b,t.getValueOrDefault(g.setCookie,[]),g.sessionStatus,x,t.getValueOrDefault(C,""),t.getInjectHeaders(g)]),e.next=7;break;case 6:e.prev=6,S=e.catch(1),console.error("Could not reach Netacea mitigation API: ",S.message),a.reply(["",0,[],"",!1,"",[]]);case 7:case"end":return e.stop()}}),e,null,[[1,6]])})));return function(t,r){return e.apply(this,arguments)}}())}},{key:"getValueOrDefault",value:function(e,t){return null!=e?e:t}},{key:"getArrayValueOrDefault",value:function(e,t,r){var a;return null!==(a=e[t])&&void 0!==a?a:r}},{key:"getMitataCookies",value:(l=h(i().mark((function e(t){var r,a,n;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=null==t?void 0:t.split("; "),a=this.getCookie(this.mitataCookieName,r),n=this.getCookie(this.mitataCaptchaCookieName,r),void 0===a){e.next=4;break}return e.prev=1,e.next=2,this.decryptCookieValue(a);case 2:a=e.sent,e.next=4;break;case 3:e.prev=3,e.catch(1),a=void 0;case 4:if(void 0===n){e.next=8;break}return e.prev=5,e.next=6,this.decryptCookieValue(n);case 6:n=e.sent,e.next=8;break;case 7:e.prev=7,e.catch(5),n=void 0;case 8:return e.abrupt("return",[a,n]);case 9:case"end":return e.stop()}}),e,this,[[1,3],[5,7]])}))),function(e){return l.apply(this,arguments)})},{key:"getCookie",value:function(e,t){var r;return null==t||null===(r=t.find((function(t){return t.includes("".concat(e,"="))})))||void 0===r?void 0:r.replace("".concat(e,"="),"")}},{key:"registerIngestHandler",value:function(e){var t=this;e.addMethod("ingest",function(){var e=h(i().mark((function e(r,a){var n,o,c,s,u,p,h,l,f,d,v,y;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=r.params(),c=t.getArrayValueOrDefault(o,0,""),s=t.getArrayValueOrDefault(o,1,""),u=t.getArrayValueOrDefault(o,2,"-1"),p=t.getArrayValueOrDefault(o,3,""),h=t.getArrayValueOrDefault(o,4,""),l=t.getArrayValueOrDefault(o,5,""),f=t.getArrayValueOrDefault(o,6,""),d=t.getArrayValueOrDefault(o,7,"0"),v=t.getArrayValueOrDefault(o,8,"0"),n=t.getArrayValueOrDefault(o,9,""),y=t.getArrayValueOrDefault(o,10,""),void 0===n){e.next=4;break}return e.prev=1,e.next=2,t.decryptCookieValue(n);case 2:n=e.sent,e.next=4;break;case 3:e.prev=3,e.catch(1),n=void 0;case 4:t.ingest({ip:c,userAgent:s,status:u,method:p,path:h,protocol:l,referer:f,bytesSent:d,requestTime:v,mitataCookie:n,sessionStatus:y}).catch((function(e){console.error("Could not reach Netacea ingest API: "+e.message)})),a.reply("done");case 5:case"end":return e.stop()}}),e,null,[[1,3]])})));return function(t,r){return e.apply(this,arguments)}}())}},{key:"makeRequest",value:(p=h(i().mark((function e(t){var r=this;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,new Promise((function(e,a){t.host=t.host.replace("https://","");for(var n=N.request({agent:r.httpsAgent,host:t.host,path:t.path,headers:t.headers,method:t.method,body:t.body},(function(t){var r="";t.on("data",(function(e){r+=e})),t.on("end",(function(){var a;e({headers:t.headers,status:null!==(a=t.statusCode)&&void 0!==a?a:0,body:""===r?void 0:r})}))})),i=0,o=["error","abort","timeout"];i<o.length;i++){var c=o[i];n.on(c,(function(e){a(e),n.destroyed||n.destroy()}))}"post"===t.method.toLowerCase()&&n.write(t.body),n.end()}));case 1:return e.abrupt("return",e.sent);case 2:case"end":return e.stop()}}),e)}))),function(e){return p.apply(this,arguments)})},{key:"mitigate",value:(s=h(i().mark((function e(t){var r,a,n,o;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,this.getMitigationResponse(t);case 1:return r=e.sent,a={sessionStatus:r.sessionStatus,setCookie:r.setCookie},r.mitigated&&(a.response={body:null!==(n=r.body)&&void 0!==n?n:"Forbidden",status:403,apiCallStatus:null!==(o=r.apiCallStatus)&&void 0!==o?o:-1,mitigation:r.mitigation,mitigated:r.mitigated}),e.abrupt("return",a);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"inject",value:(o=h(i().mark((function e(t){var r;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,this.getMitigationResponse(t);case 1:return r=e.sent,e.abrupt("return",{injectHeaders:r.injectHeaders,sessionStatus:r.sessionStatus,setCookie:r.setCookie});case 2:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"getMitigationResponse",value:(a=h(i().mark((function e(t){var r,a,n,o,c,s,u;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.ip,a=t.userAgent,n=t.url,o=t.method,c=t.mitataCookie,s=t.mitataCaptchaCookie,u=t.body,e.next=1,this.processMitigateRequest({clientIp:r,getBodyFn:function(){var e=h(i().mark((function e(){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,Promise.resolve(u);case 1:return e.abrupt("return",e.sent);case 2:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),method:o,mitata:c,mitataCaptcha:s,url:n,userAgent:a});case 1:return e.abrupt("return",e.sent);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"ingest",value:(r=h(i().mark((function e(t){var r,a,n,o,c,s,u,p,h,l,f;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.ip,a=t.userAgent,n=t.status,o=t.method,c=t.path,s=t.protocol,u=t.referer,p=t.bytesSent,h=t.requestTime,l=t.mitataCookie,f=t.sessionStatus,e.next=1,this.callIngest({ip:r,userAgent:a,status:n,method:o,bytesSent:p,path:c,protocol:s,referer:u,requestTime:h,mitataCookie:l,sessionStatus:f,integrationType:"@netacea/f5".replace("@netacea/",""),integrationVersion:"4.3.147"});case 1:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"getCookieHeader",value:function(e){if(void 0!==e.mitataCookie)return"".concat(this.mitataCookieName,"=").concat(e.mitataCookie)}}]);var r,a,o,s,p,l,f,v,y}();function me(e,t){return"string"==typeof e&&""!==e?e:"number"==typeof e?e.toString():t}module.exports=ye;
|
|
1
|
+
"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(t,a,i){return a=n(a),function(t,r){if(r&&("object"==e(r)||"function"==typeof r))return r;if(void 0!==r)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(t)}(t,r()?Reflect.construct(a,i||[],n(t).constructor):a.apply(t,i))}function r(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(e){}return(r=function(){return!!e})()}function n(e){return n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},n(e)}function a(e,t){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},a(e,t)}function i(){/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */i=function(){return r};var t,r={},n=Object.prototype,a=n.hasOwnProperty,o=Object.defineProperty||function(e,t,r){e[t]=r.value},c="function"==typeof Symbol?Symbol:{},s=c.iterator||"@@iterator",u=c.asyncIterator||"@@asyncIterator",l=c.toStringTag||"@@toStringTag";function h(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{h({},"")}catch(t){h=function(e,t,r){return e[t]=r}}function p(e,t,r,n){var a=t&&t.prototype instanceof k?t:k,i=Object.create(a.prototype),c=new _(n||[]);return o(i,"_invoke",{value:N(e,r,c)}),i}function f(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}r.wrap=p;var d="suspendedStart",v="suspendedYield",y="executing",m="completed",g={};function k(){}function b(){}function x(){}var w={};h(w,s,(function(){return this}));var C=Object.getPrototypeOf,S=C&&C(C(j([])));S&&S!==n&&a.call(S,s)&&(w=S);var A=x.prototype=k.prototype=Object.create(w);function I(e){["next","throw","return"].forEach((function(t){h(e,t,(function(e){return this._invoke(t,e)}))}))}function E(t,r){function n(i,o,c,s){var u=f(t[i],t,o);if("throw"!==u.type){var l=u.arg,h=l.value;return h&&"object"==e(h)&&a.call(h,"__await")?r.resolve(h.__await).then((function(e){n("next",e,c,s)}),(function(e){n("throw",e,c,s)})):r.resolve(h).then((function(e){l.value=e,c(l)}),(function(e){return n("throw",e,c,s)}))}s(u.arg)}var i;o(this,"_invoke",{value:function(e,t){function a(){return new r((function(r,a){n(e,t,r,a)}))}return i=i?i.then(a,a):a()}})}function N(e,r,n){var a=d;return function(i,o){if(a===y)throw Error("Generator is already running");if(a===m){if("throw"===i)throw o;return{value:t,done:!0}}for(n.method=i,n.arg=o;;){var c=n.delegate;if(c){var s=T(c,n);if(s){if(s===g)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(a===d)throw a=m,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);a=y;var u=f(e,r,n);if("normal"===u.type){if(a=n.done?m:v,u.arg===g)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(a=m,n.method="throw",n.arg=u.arg)}}}function T(e,r){var n=r.method,a=e.iterator[n];if(a===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,T(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),g;var i=f(a,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,g;var o=i.arg;return o?o.done?(r[e.resultName]=o.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,g):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,g)}function O(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function P(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function _(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(O,this),this.reset(!0)}function j(r){if(r||""===r){var n=r[s];if(n)return n.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var i=-1,o=function e(){for(;++i<r.length;)if(a.call(r,i))return e.value=r[i],e.done=!1,e;return e.value=t,e.done=!0,e};return o.next=o}}throw new TypeError(e(r)+" is not iterable")}return b.prototype=x,o(A,"constructor",{value:x,configurable:!0}),o(x,"constructor",{value:b,configurable:!0}),b.displayName=h(x,l,"GeneratorFunction"),r.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===b||"GeneratorFunction"===(t.displayName||t.name))},r.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,x):(e.__proto__=x,h(e,l,"GeneratorFunction")),e.prototype=Object.create(A),e},r.awrap=function(e){return{__await:e}},I(E.prototype),h(E.prototype,u,(function(){return this})),r.AsyncIterator=E,r.async=function(e,t,n,a,i){void 0===i&&(i=Promise);var o=new E(p(e,t,n,a),i);return r.isGeneratorFunction(t)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},I(A),h(A,l,"Generator"),h(A,s,(function(){return this})),h(A,"toString",(function(){return"[object Generator]"})),r.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},r.values=j,_.prototype={constructor:_,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(P),!e)for(var r in this)"t"===r.charAt(0)&&a.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function n(n,a){return c.type="throw",c.arg=e,r.next=n,a&&(r.method="next",r.arg=t),!!a}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],c=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var s=a.call(o,"catchLoc"),u=a.call(o,"finallyLoc");if(s&&u){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(s){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!u)throw Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&a.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var o=i?i.completion:{};return o.type=e,o.arg=t,i?(this.method="next",this.next=i.finallyLoc,g):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),g},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),P(r),g}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var a=n.arg;P(r)}return a}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:j(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),g}},r}function o(e){return function(e){if(Array.isArray(e))return k(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||g(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(e,t,r,n,a,i,o){try{var c=e[i](o),s=c.value}catch(e){return void r(e)}c.done?t(s):Promise.resolve(s).then(n,a)}function s(e){return function(){var t=this,r=arguments;return new Promise((function(n,a){var i=e.apply(t,r);function o(e){c(i,n,a,o,s,"next",e)}function s(e){c(i,n,a,o,s,"throw",e)}o(void 0)}))}}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function l(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,v(n.key),n)}}function h(e,t,r){return t&&l(e.prototype,t),r&&l(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function p(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function f(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?p(Object(r),!0).forEach((function(t){d(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):p(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function d(e,t,r){return(t=v(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function v(t){var r=function(t,r){if("object"!=e(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var a=n.call(t,r||"default");if("object"!=e(a))return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==e(r)?r:r+""}function y(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=g(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,a=function(){};return{s:a,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,o=!0,c=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return o=e.done,e},e:function(e){c=!0,i=e},f:function(){try{o||null==r.return||r.return()}finally{if(c)throw i}}}}function m(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,a,i,o,c=[],s=!0,u=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=i.call(r)).done)&&(c.push(n.value),c.length!==t);s=!0);}catch(e){u=!0,a=e}finally{try{if(!s&&null!=r.return&&(o=r.return(),Object(o)!==o))return}finally{if(u)throw a}}return c}}(e,t)||g(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e,t){if(e){if("string"==typeof e)return k(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?k(e,t):void 0}}function k(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}var b=require("crypto"),x=require("buffer"),w=require("https"),C=require("querystring"),S=require("aws4");function A(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var I,E,N,T=A(b),O=A(w),P=A(C);!function(e){e.ORIGIN="ORIGIN",e.HTTP="HTTP",e.KINESIS="KINESIS",e.NATIVE="NATIVE"}(I||(I={})),function(e){e.MITIGATE="MITIGATE",e.INJECT="INJECT",e.INGEST="INGEST"}(E||(E={})),function(e){e.CAPTCHA_GET="captcha_get",e.CAPTCHA_POST="captcha_post",e.EXPIRED_SESSION="expired_session",e.FORCED_REVALIDATION="forced_revalidation",e.INVALID_SESSION="invalid_session",e.IP_CHANGE="ip_change",e.NO_SESSION="no_session"}(N||(N={}));var _=3e3;var j="_/@#/",M={none:"",block:"block",captcha:"captcha",allow:"allow",captchaPass:"captchapass"},K={0:M.none,1:M.block,2:M.none,3:M.block,4:M.none},H={1:M.captcha,2:M.captchaPass,3:M.captcha,4:M.allow,5:M.captcha,6:M.allow,7:M.captcha,a:M.captcha,b:M.captchaPass,c:M.captcha,d:M.allow,e:M.captcha},D=Object.freeze({__proto__:null,COOKIEDELIMITER:j,bestMitigationCaptchaMap:H,bestMitigationMap:K,captchaMap:{0:"",1:"captcha_serve",2:"captcha_pass",3:"captcha_fail",4:"captcha_cookiepass",5:"captcha_cookiefail",6:"checkpoint_signal",7:"checkpoint_post",a:"checkpoint_serve",b:"checkpoint_pass",c:"checkpoint_fail",d:"checkpoint_cookiepass",e:"checkpoint_cookiefail"},captchaStatusCodes:{"":0,captchaServe:1,captchaPass:2,captchaFail:3,captchaCookiePass:4,captchaCookieFail:5,checkpointSignal:6,checkpointPost:7,checkpointServe:"a",checkpointPass:"b",checkpointFail:"c",checkpointCookiePass:"d",checkpointCookieFail:"e"},matchMap:{0:"",1:"ua_",2:"ip_",3:"visitor_",4:"datacenter_",5:"sev_",6:"organisation_",7:"asn_",8:"country_",9:"combination_",b:"headerFP_"},mitigateMap:{0:"",1:"blocked",2:"allow",3:"hardblocked",4:"flagged"},mitigationTypes:M,netaceaCookieV3KeyMap:{clientIP:"cip",userId:"uid",gracePeriod:"grp",cookieId:"cid",match:"mat",mitigate:"mit",captcha:"cap",issueTimestamp:"ist",issueReason:"isr"},netaceaCookieV3OptionalKeyMap:{checkAllPostRequests:"fCAPR"},netaceaHeaders:{match:"x-netacea-match",mitigate:"x-netacea-mitigate",captcha:"x-netacea-captcha",mitata:"x-netacea-mitata-value",mitataExpiry:"x-netacea-mitata-expiry",mitataCaptcha:"x-netacea-mitatacaptcha-value",mitataCaptchaExpiry:"x-netacea-mitatacaptcha-expiry",eventId:"x-netacea-event-id"},netaceaSettingsMap:{checkAllPostRequests:"checkAllPostRequests"}}),L="ignored",R="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split(""),V=/^(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/(.*)_\/@#\/((\d|[a-z])(\d)(\d|[a-z]))$/i;function B(e){if(void 0!==e){var t=e.match(V);if(null!=t){var r=m(t,9);return{signature:r[1],expiry:r[2],userId:r[3],ipHash:r[4],mitigationType:r[5],match:r[6],mitigate:r[7],captcha:r[8]}}}}function q(e,t,r,n){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:"000";void 0===t&&(t=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:16,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:R,r=b.randomBytes(e-1),n=Array.from(r).map((function(e){return t[e%t.length]})).join("");return"c".concat(n)}());var i=[r,t,G(e+"|"+String(r),n),a].join(j),o=G(i,n);return"".concat(o).concat(j).concat(i)}function G(e,t){var r=b.createHmac("sha256",t);return r.update(e),x.Buffer.from(r.digest("hex")).toString("base64")}function F(e,t,r){var n={mitata:void 0,requiresReissue:!1,isExpired:!1,shouldExpire:!1,isSameIP:!1,isPrimaryHashValid:!1,captcha:"0",match:"0",mitigate:"0"};if("string"!=typeof e||""===e)return n;var a=B(e);if(void 0!==a){var i=[a.expiry,a.userId,a.ipHash,a.mitigationType].join(j),o=Math.floor(Date.now()/1e3),c=parseInt(a.expiry)<o,s=["1","3","5","a","c","e"].includes(a.captcha),u="3"===a.mitigate,l=s||u,h=G(t+"|"+a.expiry,r),p=a.ipHash===h;return{mitata:a,requiresReissue:c||!p,isExpired:c,shouldExpire:l,isSameIP:p,isPrimaryHashValid:a.signature===G(i,r),match:a.match,mitigate:a.mitigate,captcha:a.captcha,userId:a.userId}}return n}function U(e,t){var r=e.split(";").map((function(e){return e.trim()})).filter((function(e){return e.toLowerCase().startsWith(t.toLowerCase())}))[0];return void 0!==r&&r.length>0?null==r?void 0:r.replace("".concat(t,"="),""):void 0}function z(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return"string"!=typeof e&&(e=e.join("; ")),""===e?"":J(e.split(";"),t).join("; ")}function J(e){if(arguments.length>1&&void 0!==arguments[1]&&arguments[1])return J(e.reverse()).reverse();var t,r=new Set,n=[],a=y(e);try{for(a.s();!(t=a.n()).done;){var i=t.value;if(""!==(i=i.trimStart()).trim()){var o=i.split("=")[0].toUpperCase();r.has(o)||(r.add(o),n.push(i))}}}catch(e){a.e(e)}finally{a.f()}return n}function X(e){var t,r,n=z([null!==(t=e.otherAttributes)&&void 0!==t?t:"","Max-Age=".concat(null!==(r=e.maxAgeAttribute)&&void 0!==r?r:86400),"Path=/"].join("; "));return"".concat(e.cookieName,"=").concat(e.cookieValue,"; ").concat(n)}var W={cookie:{attributes:Object.freeze({__proto__:null,configureCookiesDomain:function(e,t){var r=e=z(null!=e?e:"",!0),n=t=z(null!=t?t:"",!0);if(void 0!==e&&void 0!==t){var a=U(e,"Domain"),i=U(t,"Domain");void 0!==a&&void 0!==i?n=t.replace(i,a):void 0!==a&&void 0===i?n=t+(""!==t?"; Domain=".concat(a):"Domain=".concat(a)):void 0===a&&void 0!==i&&(r=e+(""!==e?"; Domain=".concat(i):"Domain=".concat(i)))}else if(void 0!==e&&void 0===t){var o=U(e,"Domain");void 0!==o&&(n="Domain=".concat(o))}else if(void 0===e&&void 0!==t){var c=U(t,"Domain");void 0!==c&&(r="Domain=".concat(c))}return{cookieAttributes:""!==r?r:void 0,captchaCookieAttributes:""!==n?n:void 0}},extractAndRemoveCookieAttr:function(e,t){var r=U(e,t);return void 0!==r?{extractedAttribute:r,cookieAttributes:e.replace(/ /g,"").replace("".concat(t,"=").concat(r),"").split(";").filter((function(e){return e.length>0})).join("; ")}:{extractedAttribute:void 0,cookieAttributes:e}},extractCookieAttr:U,removeDuplicateAttrs:z}),netaceaSession:Object.freeze({__proto__:null,createNetaceaCaptchaSetCookieString:function(e){var t;return X(f(f({},e),{},{cookieName:null!==(t=e.cookieName)&&void 0!==t?t:"_mitatacaptcha"}))},createNetaceaSetCookieString:function(e){var t;return X(f(f({},e),{},{cookieName:null!==(t=e.cookieName)&&void 0!==t?t:"_mitata"}))},createSetCookieString:X})}},Y=function(){function e(t,r){u(this,e),this.crypto=t,this.TextEncoder=r}return h(e,[{key:"hashString",value:(r=s(i().mark((function e(t,r){var n,a,c,s,u,l,h=arguments;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=(n=h.length>2&&void 0!==h[2]&&h[2])?o(r).sort():o(r),c=(new this.TextEncoder).encode(a.join(",")),e.next=1,this.crypto.subtle.digest(t,c);case 1:return s=e.sent,u=Array.from(new Uint8Array(s)),l=u.map((function(e){return e.toString(16).padStart(2,"0")})).join("").substring(0,12),e.abrupt("return","h"+(n?"s":"")+"_".concat(r.length,"_").concat(l));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"hashHeaders",value:(t=s(i().mark((function t(r){var n,a,o,c=arguments;return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=c.length>1&&void 0!==c[1]&&c[1],0!==(a=e.filterHeaderNames(r)).length){t.next=1;break}return t.abrupt("return","");case 1:return t.prev=1,t.next=2,this.hashString("SHA-256",a,n);case 2:return t.abrupt("return",t.sent);case 3:return t.prev=3,o=t.catch(1),console.error(o),t.abrupt("return","");case 4:case"end":return t.stop()}}),t,this,[[1,3]])}))),function(e){return t.apply(this,arguments)})}],[{key:"filterHeaderNames",value:function(e){return e.filter((function(e){var t=e.toLowerCase();return!["","cookie","referer"].includes(t)&&null===t.match(/^(x-netacea-|cloudfront-)/i)}))}}]);var t,r}();function $(e){return e.toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function Z(e){var t=(e+"===".slice(0,(4-e.length%4)%4)).replace(/-/g,"+").replace(/_/g,"/");return Buffer.from(t,"base64")}var Q="eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0";function ee(e,t){var r=b.randomBytes(12),n=b.createCipheriv("aes-256-gcm",t,r),a=Buffer.from(Q,"ascii");n.setAAD(a);var i=n.update(e,"utf8");i=Buffer.concat([i,n.final()]);var o=n.getAuthTag();return[Q,"",$(r),$(i),$(o)].join(".")}function te(e,t){var r=e.split(".");if(5!==r.length)throw new Error("JWE should have 5 parts, got ".concat(r.length));var n=m(r,5),a=n[0],i=n[1],o=n[2],c=n[3],s=n[4];if(a!==Q)throw new Error("Incorrect JWE header");if(""!==i)throw new Error("Expected empty encrypted key for direct encryption");var u=Z(o),l=Z(c),h=Z(s);if(12!==u.length)throw new Error("IV must be ".concat(12," bytes, got ").concat(u.length));if(16!==h.length)throw new Error("Auth tag must be ".concat(16," bytes, got ").concat(h.length));var p=b.createDecipheriv("aes-256-gcm",t,u),f=Buffer.from(a,"ascii");p.setAAD(f),p.setAuthTag(h);var d=p.update(l);return(d=Buffer.concat([d,p.final()])).toString("utf8")}var re={},ne={},ae={},ie={};Object.defineProperty(ie,"__esModule",{value:!0}),ie.API_VERSION=ie.REGION=ie.PAYLOAD_TYPE=ie.STATE=void 0,ie.STATE={ACTIVE:"ACTIVE",UPDATING:"UPDATING",CREATING:"CREATING",DELETING:"DELETING"},ie.PAYLOAD_TYPE="string",ie.REGION="eu-west-1",ie.API_VERSION="2013-12-02",Object.defineProperty(ae,"__esModule",{value:!0}),ae.signRequest=void 0;var oe=S,ce=ie;function se(e,t){for(var r=[],n=0;n<e.length;n+=t){var a=e.slice(n,n+t);r.push({Data:Buffer.from(JSON.stringify(a)).toString("base64"),PartitionKey:Date.now().toString()})}return r}ae.signRequest=function(e,t,r){var n=e.accessKeyId,a=e.secretAccessKey,i={Records:se(t,r),PartitionKey:Date.now().toString(),StreamName:e.streamName};return oe.sign({service:"kinesis",body:JSON.stringify(i),headers:{"Content-Type":"application/x-amz-json-1.1","X-Amz-Target":"Kinesis_20131202.PutRecords"},region:ce.REGION},{accessKeyId:n,secretAccessKey:a})},Object.defineProperty(ne,"__esModule",{value:!0});var ue=ae;function le(e){return he.apply(this,arguments)}function he(){return(he=s(i().mark((function e(t){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,new Promise((function(e){setTimeout(e,t)}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var pe=function(){return h((function e(t){var r=t.kinesisStreamName,n=t.kinesisAccessKey,a=t.kinesisSecretKey,i=t.maxLogAgeSeconds,o=t.logBatchSize,c=t.rampUpBatchSize,s=t.maxAwaitTimePerIngestCallMs;u(this,e),this.maxLogBatchSize=20,this.maxLogAgeSeconds=10,this.logBatchSize=20,this.logCache=[],this.intervalSet=!1,this.kinesisStreamName=r,this.kinesisAccessKey=n,this.kinesisSecretKey=a,this.maxAwaitTimePerIngestCallMs=s,void 0!==i&&i<this.maxLogAgeSeconds&&i>0&&(this.maxLogAgeSeconds=i),void 0!==o&&(this.maxLogBatchSize=o),this.logBatchSize=!0===c?1:this.maxLogBatchSize}),[{key:"putToKinesis",value:(t=s(i().mark((function e(t){var r,n,a,c;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(0!==this.logCache.length){e.next=1;break}return e.abrupt("return");case 1:return r=o(this.logCache),this.logCache=[],e.prev=2,n=(0,ue.signRequest)({streamName:this.kinesisStreamName,accessKeyId:this.kinesisAccessKey,secretAccessKey:this.kinesisSecretKey},r,this.logBatchSize),e.next=3,t({headers:n.headers,host:"https://".concat(n.hostname),method:n.method,path:n.path,body:n.body});case 3:this.logBatchSize!==this.maxLogBatchSize&&(this.logBatchSize=Math.min(this.maxLogBatchSize,2*this.logBatchSize)),e.next=5;break;case 4:e.prev=4,c=e.catch(2),(a=this.logCache).push.apply(a,o(r)),console.error(c);case 5:case"end":return e.stop()}}),e,this,[[2,4]])}))),function(e){return t.apply(this,arguments)})},{key:"ingest",value:(e=s(i().mark((function e(t,r){var n,a,o=this;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.logCache.push(t),!(this.logCache.length>=this.logBatchSize)){e.next=2;break}return(n=[]).push(this.putToKinesis(r)),void 0!==this.maxAwaitTimePerIngestCallMs&&n.push(le(this.maxAwaitTimePerIngestCallMs)),e.next=1,Promise.race(n);case 1:e.next=3;break;case 2:if(this.intervalSet){e.next=3;break}if(this.intervalSet=!0,a=le(1e3*this.maxLogAgeSeconds).then(s(i().mark((function e(){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,o.putToKinesis(r);case 1:o.intervalSet=!1;case 2:case"end":return e.stop()}}),e)})))).catch((function(){})),void 0!==this.maxAwaitTimePerIngestCallMs){e.next=3;break}return e.next=3,a;case 3:case"end":return e.stop()}}),e,this)}))),function(t,r){return e.apply(this,arguments)})}]);var e,t}();ne.default=pe,Object.defineProperty(re,"__esModule",{value:!0});var fe,de=ne,ve=re.default=de.default,ye={subtle:{digest:(fe=s(i().mark((function e(t,r){var n,a,o,c,s;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=null!==(n={"SHA-256":"sha256","SHA-1":"sha1","SHA-384":"sha384","SHA-512":"sha512"}[t])&&void 0!==n?n:t.toLowerCase().replace("-",""),o=r instanceof ArrayBuffer?Buffer.from(r):Buffer.from(r.buffer,r.byteOffset,r.byteLength),c=new Uint8Array(o),s=T.createHash(a).update(c).digest(),e.abrupt("return",s.buffer.slice(s.byteOffset,s.byteOffset+s.byteLength));case 1:case"end":return e.stop()}}),e)}))),function(e,t){return fe.apply(this,arguments)})}},me=W.cookie.attributes.configureCookiesDomain,ge=W.cookie.netaceaSession,ke=ge.createNetaceaSetCookieString,be=ge.createNetaceaCaptchaSetCookieString,xe=function(){return h((function e(t){var r,n,a=t.apiKey,i=t.secretKey,o=t.timeout,c=void 0===o?3e3:o,s=t.mitigationServiceUrl,l=void 0===s?"https://mitigations.netacea.net":s,h=t.ingestServiceUrl,p=void 0===h?"https://ingest.netacea.net":h,v=t.mitigationType,y=void 0===v?E.INGEST:v,m=t.captchaSiteKey,g=t.captchaSecretKey,k=t.ingestType,b=void 0===k?I.HTTP:k,x=t.kinesis,w=t.mitataCookieExpirySeconds,C=t.netaceaCookieExpirySeconds,S=t.netaceaCookieName,A=t.netaceaCaptchaCookieName,N=t.netaceaCookieAttributes,T=t.netaceaCaptchaCookieAttributes;if(u(this,e),d(this,"mitataCookieExpirySeconds",void 0),d(this,"apiKey",void 0),d(this,"secretKey",void 0),d(this,"mitigationServiceUrl",void 0),d(this,"ingestServiceUrl",void 0),d(this,"timeout",void 0),d(this,"captchaSiteKey",void 0),d(this,"captchaSecretKey",void 0),d(this,"ingestType",void 0),d(this,"kinesis",void 0),d(this,"mitigationType",void 0),d(this,"encryptedCookies",[]),d(this,"netaceaCookieName",void 0),d(this,"netaceaCaptchaCookieName",void 0),d(this,"netaceaCookieAttributes",void 0),d(this,"netaceaCaptchaCookieAttributes",void 0),null==a)throw new Error("apiKey is a required parameter");this.apiKey=a,this.secretKey=i,this.mitigationServiceUrl=l,this.ingestServiceUrl=p,this.mitigationType=y,this.ingestType=null!=b?b:I.HTTP,this.ingestType===I.KINESIS&&(void 0===x?console.warn("NETACEA WARN: no kinesis args provided, when ingestType is ".concat(this.ingestType)):this.kinesis=new ve(f(f({},x),{},{apiKey:this.apiKey}))),void 0===m&&void 0===g||(this.captchaSiteKey=m,this.captchaSecretKey=g),this.timeout=function(e){return e<=0?_:e}(c),this.netaceaCookieName=Ce(S,"_mitata"),this.netaceaCaptchaCookieName=Ce(A,"_mitatacaptcha"),this.encryptedCookies=[this.netaceaCookieName,this.netaceaCaptchaCookieName],this.mitataCookieExpirySeconds=function(e,t){return void 0===t?e===E.INGEST?3600:60:t}(y,null!=C?C:w);var O=me(null!=N?N:"",null!=T?T:"");this.netaceaCookieAttributes=null!==(r=O.cookieAttributes)&&void 0!==r?r:"",this.netaceaCaptchaCookieAttributes=null!==(n=O.captchaCookieAttributes)&&void 0!==n?n:""}),[{key:"runMitigation",value:(w=s(i().mark((function e(t){var r,n,a,o,c;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.prev=0,o=this.mitigationType,e.next=o===E.MITIGATE?1:o===E.INJECT?3:o===E.INGEST?5:7;break;case 1:return e.next=2,this.mitigate(t);case 2:case 4:case 6:return e.abrupt("return",e.sent);case 3:return e.next=4,this.inject(t);case 5:return e.next=6,this.processIngest(t);case 7:throw new Error("Netacea Error: Mitigation type ".concat(this.mitigationType," not recognised"));case 8:e.next=10;break;case 9:return e.prev=9,c=e.catch(0),console.error("Netacea FAILOPEN Error:",c),r=t,n=this.isUrlCaptchaPost(r.url,r.method),a=this.mitigationType===E.MITIGATE,e.abrupt("return",{injectHeaders:{"x-netacea-captcha":"0","x-netacea-match":"0","x-netacea-mitigate":"0"},sessionStatus:a&&n?"error_open":""});case 10:case"end":return e.stop()}}),e,this,[[0,9]])}))),function(e){return w.apply(this,arguments)})},{key:"readCookie",value:(x=s(i().mark((function e(t,r){var n,a,o,c,s,u,l;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=r){e.next=1;break}return e.abrupt("return",void 0);case 1:if("string"!=typeof r){e.next=3;break}return e.next=2,this.readCookie(t,r.split(";"));case 2:return e.abrupt("return",e.sent);case 3:n="".concat(t,"="),a=y(r),e.prev=4,a.s();case 5:if((o=a.n()).done){e.next=11;break}if(c=o.value,!(s=c.split(";")[0].trimStart()).startsWith(n)){e.next=10;break}if(u=s.slice(n.length),!this.encryptedCookies.includes(t)){e.next=9;break}return e.prev=6,e.next=7,this.decryptCookieValue(u);case 7:return e.abrupt("return",e.sent);case 8:return e.prev=8,e.catch(6),e.abrupt("return",void 0);case 9:return e.abrupt("return",u);case 10:e.next=5;break;case 11:e.next=13;break;case 12:e.prev=12,l=e.catch(4),a.e(l);case 13:return e.prev=13,a.f(),e.finish(13);case 14:return e.abrupt("return",void 0);case 15:case"end":return e.stop()}}),e,this,[[4,12,13,14],[6,8]])}))),function(e,t){return x.apply(this,arguments)})},{key:"callIngest",value:(b=s(i().mark((function e(t){var r,n,a,o;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=this.constructWebLog(t),this.ingestType!==I.KINESIS){e.next=5;break}if(void 0!==this.kinesis){e.next=1;break}return console.error("Netacea Error: Unable to log as Kinesis has not been defined."),e.abrupt("return");case 1:return e.prev=1,e.next=2,this.kinesis.ingest(f(f({},r),{},{apiKey:this.apiKey}),this.makeRequest.bind(this));case 2:e.next=4;break;case 3:e.prev=3,o=e.catch(1),console.error("NETACEA Error: ",o.message);case 4:e.next=7;break;case 5:return n={"X-Netacea-API-Key":this.apiKey,"content-type":"application/json"},e.next=6,this.makeIngestApiCall(n,r);case 6:if(200===(a=e.sent).status){e.next=7;break}throw this.APIError(a);case 7:case"end":return e.stop()}}),e,this,[[1,3]])}))),function(e){return b.apply(this,arguments)})},{key:"makeIngestApiCall",value:(k=s(i().mark((function e(t,r){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,this.makeRequest({host:this.ingestServiceUrl,method:"POST",path:"/",headers:t,body:JSON.stringify(r),timeout:this.timeout});case 1:return e.abrupt("return",e.sent);case 2:case"end":return e.stop()}}),e,this)}))),function(e,t){return k.apply(this,arguments)})},{key:"constructV1WebLog",value:function(e){var t=e.ip,r=e.userAgent,n=e.status,a=e.method,i=e.path,o=e.protocol,c=e.referer,s=e.bytesSent,u=e.requestTime,l=e.mitataCookie,h=e.sessionStatus,p=e.integrationType,f=e.integrationVersion,d=e.headerFingerprint,v=(new Date).toUTCString();return{Request:"".concat(a," ").concat(i," ").concat(o),TimeLocal:v,RealIp:t,UserAgent:r,Status:n,RequestTime:null==u?void 0:u.toString(),BytesSent:null==s?void 0:s.toString(),Referer:""===c?"-":c,NetaceaUserIdCookie:null!=l?l:"",NetaceaMitigationApplied:null!=h?h:"",IntegrationType:null!=p?p:"",IntegrationVersion:null!=f?f:"",HeaderHash:null!=d?d:""}}},{key:"constructWebLog",value:function(e){return e.bytesSent=""===e.bytesSent?"0":e.bytesSent,this.constructV1WebLog(e)}},{key:"check",value:(g=s(i().mark((function e(t,r,n,a,o){var c,s,u,l,h,p,f,d,v,y,m,g;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0!==this.secretKey){e.next=1;break}throw new Error("Secret key is required to mitigate");case 1:if((d=F(t,r,this.secretKey)).isPrimaryHashValid&&!d.requiresReissue){e.next=4;break}return e.next=2,this.makeMitigateAPICall(null===(v=d.mitata)||void 0===v?void 0:v.userId,r,n,a,o);case 2:return m=e.sent,c=m.status,s=m.match,u=m.mitigate,l=m.captcha,h=m.body,e.next=3,this.createMitata(r,null===(y=d.mitata)||void 0===y?void 0:y.userId,s,u,l,m.mitataMaxAge);case 3:g=e.sent,p=[g],f=m.eventId,e.next=5;break;case 4:c=-1,s=d.match,u=d.mitigate,l=d.captcha,h=void 0,p=[];case 5:return e.abrupt("return",this.composeResult(h,p,c,s,u,l,!1,f));case 6:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n,a){return g.apply(this,arguments)})},{key:"createMitata",value:(m=s(i().mark((function e(t,r,n,a,o){var c,s,u,l,h,p,f,d,v=arguments;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(c=v.length>5&&void 0!==v[5]?v[5]:86400,s=v.length>6&&void 0!==v[6]?v[6]:void 0,u=["1","3","5"].includes(o),l="3"===a,h=u||l?-60:this.mitataCookieExpirySeconds,p=null!=s?s:Math.floor(Date.now()/1e3)+h,void 0!==this.secretKey){e.next=1;break}throw new Error("Cannot build cookie without secret key.");case 1:return f=[n,a,o].join(""),d=q(t,r,p,this.secretKey,f),e.abrupt("return",ke({cookieName:this.netaceaCookieName,cookieValue:d,maxAgeAttribute:String(c),otherAttributes:this.netaceaCookieAttributes}));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n,a){return m.apply(this,arguments)})},{key:"processCaptcha",value:(v=s(i().mark((function e(t,r,n,a,o){var c,s,u,l,h,p,f;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,this.makeCaptchaAPICall(t,r,n,a,o);case 1:return c=e.sent,s=c.status,u=c.match,l=c.mitigate,h=c.captcha,p=c.body,f=c.setCookie,e.abrupt("return",this.composeResult(p,f,s,u,l,h,!0));case 2:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n,a){return v.apply(this,arguments)})},{key:"getMitataCaptchaFromHeaders",value:(p=s(i().mark((function e(t){var r,n,a;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!Object.prototype.hasOwnProperty.call(t,D.netaceaHeaders.mitataCaptcha)){e.next=3;break}if(r=t[D.netaceaHeaders.mitataCaptcha],Array.isArray(r)&&(r=r[0]),null!=r&&""!==r){e.next=1;break}return e.abrupt("return",void 0);case 1:return n=parseInt(t[D.netaceaHeaders.mitataCaptchaExpiry]),e.next=2,this.encryptCookieValue(r);case 2:return a=e.sent,e.abrupt("return",be({cookieName:this.netaceaCaptchaCookieName,cookieValue:a,maxAgeAttribute:String(isNaN(n)?86400:n),otherAttributes:this.netaceaCaptchaCookieAttributes}));case 3:return e.abrupt("return",void 0);case 4:case"end":return e.stop()}}),e,this)}))),function(e){return p.apply(this,arguments)})},{key:"makeCaptchaAPICall",value:(l=s(i().mark((function e(t,r,n,a,o){var c,s,u,l;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return c={"X-Netacea-API-Key":this.apiKey,"X-Netacea-Client-IP":r,"user-agent":n,"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"},void 0!==(s=B(t))&&(c["X-Netacea-UserId"]=s.userId),void 0!==this.captchaSiteKey&&void 0!==this.captchaSecretKey&&(c["X-Netacea-Captcha-Site-Key"]=this.captchaSiteKey,c["X-Netacea-Captcha-Secret-Key"]=this.captchaSecretKey),u={},"string"==typeof o&&""!==o&&(u.headerFP=o),e.next=1,this.makeRequest({host:this.mitigationServiceUrl,path:"/AtaVerifyCaptcha",headers:c,method:"POST",body:a,timeout:this.timeout,params:u});case 1:return l=e.sent,e.next=2,this.getApiCallResponseFromResponse(l,null==s?void 0:s.userId,r);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n,a){return l.apply(this,arguments)})},{key:"getApiCallResponseFromResponse",value:(c=s(i().mark((function e(t,r,n){var a,o,c,s,u,l,h,p,f,d,v,y,m,g;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(200===t.status){e.next=1;break}throw this.APIError(t);case 1:return h=null!==(a=null===(o=t.headers[D.netaceaHeaders.match])||void 0===o?void 0:o.toString())&&void 0!==a?a:"0",p=null!==(c=null===(s=t.headers[D.netaceaHeaders.mitigate])||void 0===s?void 0:s.toString())&&void 0!==c?c:"0",f=null!==(u=null===(l=t.headers[D.netaceaHeaders.captcha])||void 0===l?void 0:l.toString())&&void 0!==u?u:"0",d=parseInt(t.headers[D.netaceaHeaders.mitataExpiry]),isNaN(d)&&(d=86400),e.next=2,this.createMitata(n,r,h,p,f);case 2:return v=e.sent,e.next=3,this.getMitataCaptchaFromHeaders(t.headers);case 3:return y=e.sent,m=[v,y].filter((function(e){return void 0!==e})),g=t.headers[D.netaceaHeaders.eventId],e.abrupt("return",{status:t.status,match:h,mitigate:p,captcha:f,setCookie:m,body:t.body,eventId:g,mitataMaxAge:d});case 4:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return c.apply(this,arguments)})},{key:"buildCookieHeader",value:function(e){var t="",r="";for(var n in e){var a=e[n];void 0!==a&&(t="".concat(t).concat(r).concat(n,"=").concat(a),r="; ")}return t}},{key:"makeMitigateAPICall",value:(o=s(i().mark((function e(t,r,n,a,o){var c,s,u;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return c={"X-Netacea-API-Key":this.apiKey,"X-Netacea-Client-IP":r,"user-agent":n,cookie:this.buildCookieHeader({_mitatacaptcha:a})},void 0!==t&&(c["X-Netacea-UserId"]=t),void 0!==this.captchaSiteKey&&void 0!==this.captchaSecretKey&&(c["X-Netacea-Captcha-Site-Key"]=this.captchaSiteKey,c["X-Netacea-Captcha-Secret-Key"]=this.captchaSecretKey),s={},"string"==typeof o&&""!==o&&(s.headerFP=o),e.next=1,this.makeRequest({host:this.mitigationServiceUrl,path:"/",headers:c,method:"GET",timeout:this.timeout,params:s});case 1:return u=e.sent,e.next=2,this.getApiCallResponseFromResponse(u,t,r);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n,a){return o.apply(this,arguments)})},{key:"composeResult",value:function(e,t,r,n,a,i,o,c){var s=this.findBestMitigation(n,a,i,o),u={body:e,apiCallStatus:r,setCookie:t,sessionStatus:s.sessionStatus,mitigation:s.mitigation,mitigated:[D.mitigationTypes.block,D.mitigationTypes.captcha,D.mitigationTypes.captchaPass].includes(s.mitigation)};if(this.mitigationType===E.INJECT){var l={"x-netacea-match":s.parts.match.toString(),"x-netacea-mitigate":s.parts.mitigate.toString(),"x-netacea-captcha":s.parts.captcha.toString()};void 0!==c&&(l["x-netacea-event-id"]=c),u.injectHeaders=l}return u}},{key:"findBestMitigation",value:function(e,t,r,n){var a,i,o="unknown";n||("2"===r?r="4":"3"===r&&(r="5"));var c=null!==(a=D.matchMap[e])&&void 0!==a?a:o+"_";c+=null!==(i=D.mitigateMap[t])&&void 0!==i?i:o;var s=D.bestMitigationMap[t];if("0"!==r){var u;c+=","+(null!==(u=D.captchaMap[r])&&void 0!==u?u:o);var l=D.bestMitigationCaptchaMap[r];void 0!==l&&(s=l)}return this.mitigationType===E.INJECT&&(s=D.mitigationTypes.none),{sessionStatus:c,mitigation:s,parts:{match:e,mitigate:t,captcha:r}}}},{key:"APIError",value:function(e){var t="Unknown error";switch(e.status){case 403:t="Invalid credentials";break;case 500:t="Server error";break;case 502:t="Bad Gateway";break;case 503:t="Service Unavailable";break;case 400:t="Invalid request"}return new Error("Error reaching Netacea API (".concat(t,"), status: ").concat(e.status))}},{key:"isUrlCaptchaPost",value:function(e,t){return e.includes("/AtaVerifyCaptcha")&&"post"===t.toLowerCase()}},{key:"processMitigateRequest",value:(a=s(i().mark((function e(t,r){var n,a,o,c,s,u,l;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.isUrlCaptchaPost(t.url,t.method)){e.next=2;break}return a=this,o=t.mitata,c=t.clientIp,s=t.userAgent,e.next=1,t.getBodyFn();case 1:u=e.sent,l=r,n=a.processCaptcha.call(a,o,c,s,u,l),e.next=3;break;case 2:n=this.check(t.mitata,t.clientIp,t.userAgent,t.mitataCaptcha,r);case 3:return e.next=4,n;case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"setIngestOnlyMitataCookie",value:(n=s(i().mark((function e(t){var r;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,this.createMitata(L,t,"0","0","0",86400);case 1:return r=e.sent,e.abrupt("return",{sessionStatus:"",setCookie:[r]});case 2:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"processIngest",value:(r=s(i().mark((function e(t){var r,n,a,o;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0!==this.secretKey){e.next=1;break}throw new Error("Secret key is required for ingest");case 1:return r=this.getCookieHeader(t),e.next=2,this.readCookie(this.netaceaCookieName,r);case 2:if(n=e.sent,(a=F(n,L,this.secretKey)).isPrimaryHashValid){e.next=4;break}return e.next=3,this.setIngestOnlyMitataCookie(void 0);case 3:case 5:return e.abrupt("return",e.sent);case 4:if(!a.requiresReissue){e.next=6;break}return e.next=5,this.setIngestOnlyMitataCookie(null===(o=a.mitata)||void 0===o?void 0:o.userId);case 6:return e.abrupt("return",{sessionStatus:"",setCookie:[]});case 7:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"encryptCookieValue",value:(t=s(i().mark((function e(t){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t);case 1:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})},{key:"decryptCookieValue",value:(e=s(i().mark((function e(t){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t);case 1:case"end":return e.stop()}}),e)}))),function(t){return e.apply(this,arguments)})}]);var e,t,r,n,a,o,c,l,p,v,m,g,k,b,x,w}(),we=function(){function e(r){var n,a,i,o,c;u(this,e),d(c=t(this,e,[r]),"httpsAgent",void 0),d(c,"mitataCookieName",void 0),d(c,"mitataCaptchaCookieName",void 0),d(c,"hashGenerator",void 0),d(c,"debugMode",void 0),d(c,"encryptionEnabled",!1),d(c,"encryptionKeyBuffer",void 0),d(c,"mitigationHeaders",["cookie","user-agent"]),c.httpsAgent=new O.Agent({timeout:c.timeout,keepAlive:!0,maxSockets:null!==(n=r.maxSockets)&&void 0!==n?n:25}),c.mitataCookieName=null!==(a=r.netaceaCookieName)&&void 0!==a?a:"_mitata",c.mitataCaptchaCookieName=null!==(i=r.netaceaCaptchaCookieName)&&void 0!==i?i:"_mitatacaptcha";var s=function(){return h((function e(){u(this,e)}),[{key:"encode",value:function(e){return new Uint8Array(Buffer.from(e,"utf8"))}}])}();if(c.hashGenerator=new Y(ye,s),c.debugMode=null!==(o=r.debugMode)&&void 0!==o&&o,void 0!==r.cookieEncryptionKey){var l=function(e){if(null==e||""===e)return{valid:!1,error:"key is empty"};if(!/^[A-Za-z0-9_-]+$/.test(e))return{valid:!1,error:"key contains invalid base64url characters"};var t;try{t=Z(e)}catch(e){return{valid:!1,error:"key is not valid base64url"}}return 32!==t.length?{valid:!1,error:"key must be ".concat(32," bytes (256 bits), got ").concat(t.length," bytes")}:{valid:!0,keyBuffer:t}}(r.cookieEncryptionKey);l.valid&&void 0!==l.keyBuffer?(c.encryptionKeyBuffer=l.keyBuffer,c.encryptionEnabled=!0):console.warn("NETACEA WARN: Invalid cookieEncryptionKey - ".concat(l.error,". Cookies will not be encrypted."))}return c}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&a(e,t)}(e,xe),h(e,[{key:"computeHeaderFingerprint",value:(g=s(i().mark((function e(t){var r;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0!==t&&""!==t){e.next=1;break}return e.abrupt("return","");case 1:return r=t.split(","),e.next=2,this.hashGenerator.hashHeaders(r);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return g.apply(this,arguments)})},{key:"encryptCookieValue",value:(y=s(i().mark((function e(t){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.encryptionEnabled&&void 0!==this.encryptionKeyBuffer){e.next=1;break}return e.abrupt("return",t);case 1:return e.abrupt("return",ee(t,this.encryptionKeyBuffer));case 2:case"end":return e.stop()}}),e,this)}))),function(e){return y.apply(this,arguments)})},{key:"decryptCookieValue",value:(v=s(i().mark((function e(t){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.encryptionEnabled&&void 0!==this.encryptionKeyBuffer){e.next=1;break}return e.abrupt("return",t);case 1:if(5===(r=t).split(".").length&&r.includes("..")){e.next=2;break}throw new Error("Cookie is not JWE encrypted");case 2:return e.abrupt("return",te(t,this.encryptionKeyBuffer));case 3:case"end":return e.stop()}var r}),e,this)}))),function(e){return v.apply(this,arguments)})},{key:"createMitata",value:(f=s(i().mark((function e(t,r,n,a,o){var c,s,u,l,h,p,f,d,v,y=arguments;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(c=y.length>5&&void 0!==y[5]?y[5]:86400,s=y.length>6&&void 0!==y[6]?y[6]:void 0,u=["1","3","5"].includes(o),l="3"===a,h=u||l?-60:this.mitataCookieExpirySeconds,p=null!=s?s:Math.floor(Date.now()/1e3)+h,void 0!==this.secretKey){e.next=1;break}throw new Error("Cannot build cookie without secret key.");case 1:return f=[n,a,o].join(""),d=q(t,r,p,this.secretKey,f),e.next=2,this.encryptCookieValue(d);case 2:return v=e.sent,e.abrupt("return",ke({cookieName:this.netaceaCookieName,cookieValue:v,maxAgeAttribute:String(c),otherAttributes:this.netaceaCookieAttributes}));case 3:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n,a){return f.apply(this,arguments)})},{key:"getInjectHeaders",value:function(e){if(this.mitigationType===E.INJECT){var t,r,n,a,i=e;if(void 0!==i.injectHeaders)return[null!==(t=i.injectHeaders["x-netacea-match"])&&void 0!==t?t:"0",null!==(r=i.injectHeaders["x-netacea-mitigate"])&&void 0!==r?r:"0",null!==(n=i.injectHeaders["x-netacea-captcha"])&&void 0!==n?n:"0",null!==(a=i.injectHeaders["x-netacea-event-id"])&&void 0!==a?a:""]}return[]}},{key:"registerPolicyHandler",value:function(e){var t=this;e.addMethod("getMitigationHeaderPolicy",(function(e,r){var n=t.mitigationHeaders.join(",");console.info('level=info component=f5 handler=getMitigationHeaderPolicy policy="'.concat(n,'"')),r.reply(n)}))}},{key:"registerMitigateHandler",value:function(e){var t=this;e.addMethod("handleRequest",function(){var e=s(i().mark((function e(r,n){var a,o,c,s,u,l,h,p,f,d,v,y,g,k,b,x,w,C,S,A,I,E,N,T,O,P;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return c=r.params(),s=m(c,3),u=s[0],l=s[1],h=s[2],p=t.getArrayValueOrDefault(c,3,void 0),f=t.getArrayValueOrDefault(c,4,void 0),d=t.getArrayValueOrDefault(c,5,void 0),t.debugMode&&console.info('level=debug component=f5 handler=handleRequest event=header_values headerValuesStr="'.concat(null!=d?d:"",'"')),v=t.parseHeaderValues(d),y=null!==(a=v.cookie)&&void 0!==a?a:null,g=null!==(o=v["user-agent"])&&void 0!==o?o:"",e.prev=1,e.next=2,t.computeHeaderFingerprint(f);case 2:return k=e.sent,t.debugMode&&console.info('level=debug component=f5 handler=handleRequest event=header_fingerprint method="'.concat(l,'" path="').concat(h,'" headers="').concat(null!=f?f:"",'" header_count=').concat(null!==(b=null==f?void 0:f.split(",").length)&&void 0!==b?b:0,' fingerprint="').concat(k,'"')),e.next=3,t.getMitataCookies(y);case 3:return x=e.sent,w=m(x,2),C=w[0],S=w[1],t.debugMode&&console.info('level=debug component=f5 handler=handleRequest event=mitigation_request headerFP="'.concat(k,'"')),e.next=4,t.runMitigation({ip:u,method:l,url:h,mitataCaptchaCookie:S,mitataCookie:C,userAgent:g,body:p,headerFingerprint:k});case 4:if("error_open"!==(null==(A=e.sent)?void 0:A.sessionStatus)){e.next=5;break}return n.reply(["",500,[],"error_open",!0,"",[],k]),e.abrupt("return");case 5:if(void 0!==A){e.next=6;break}return n.reply(["",0,[],"",!1,"",[],k]),e.abrupt("return");case 6:I="",E=0,N=!1,T=t.getValueOrDefault(C,""),void 0!==A.setCookie&&A.setCookie.length>0&&void 0!==(O=A.setCookie.find((function(e){return e.includes("".concat(t.netaceaCookieName,"="))})))&&(T=O.split(";")[0].replace("".concat(t.netaceaCookieName,"="),"")),void 0!==A.response&&(E=A.response.apiCallStatus,I=t.getValueOrDefault(A.response.body,"Forbidden"),N=t.getValueOrDefault(A.response.mitigated,N)),n.reply([I,E,t.getValueOrDefault(A.setCookie,[]),A.sessionStatus,N,t.getValueOrDefault(T,""),t.getInjectHeaders(A),k]),e.next=8;break;case 7:e.prev=7,P=e.catch(1),console.error("Could not reach Netacea mitigation API: ",P.message),n.reply(["",0,[],"",!1,"",[],""]);case 8:case"end":return e.stop()}}),e,null,[[1,7]])})));return function(t,r){return e.apply(this,arguments)}}())}},{key:"parseHeaderValues",value:function(e){var t={};if(void 0===e||""===e)return t;for(var r=Buffer.from(e,"base64").toString("utf8").split("\n"),n=0;n<this.mitigationHeaders.length&&n<r.length;n++)t[this.mitigationHeaders[n].toLowerCase()]=r[n];return t}},{key:"getValueOrDefault",value:function(e,t){return null!=e?e:t}},{key:"getArrayValueOrDefault",value:function(e,t,r){var n;return null!==(n=e[t])&&void 0!==n?n:r}},{key:"getMitataCookies",value:(p=s(i().mark((function e(t){var r,n,a;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=null==t?void 0:t.split("; "),n=this.getCookie(this.mitataCookieName,r),a=this.getCookie(this.mitataCaptchaCookieName,r),void 0===n){e.next=4;break}return e.prev=1,e.next=2,this.decryptCookieValue(n);case 2:n=e.sent,e.next=4;break;case 3:e.prev=3,e.catch(1),n=void 0;case 4:if(void 0===a){e.next=8;break}return e.prev=5,e.next=6,this.decryptCookieValue(a);case 6:a=e.sent,e.next=8;break;case 7:e.prev=7,e.catch(5),a=void 0;case 8:return e.abrupt("return",[n,a]);case 9:case"end":return e.stop()}}),e,this,[[1,3],[5,7]])}))),function(e){return p.apply(this,arguments)})},{key:"getCookie",value:function(e,t){var r;return null==t||null===(r=t.find((function(t){return t.includes("".concat(e,"="))})))||void 0===r?void 0:r.replace("".concat(e,"="),"")}},{key:"registerIngestHandler",value:function(e){var t=this;e.addMethod("ingest",function(){var e=s(i().mark((function e(r,n){var a,o,c,s,u,l,h,p,f,d,v,y,m;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=r.params(),c=t.getArrayValueOrDefault(o,0,""),s=t.getArrayValueOrDefault(o,1,""),u=t.getArrayValueOrDefault(o,2,"-1"),l=t.getArrayValueOrDefault(o,3,""),h=t.getArrayValueOrDefault(o,4,""),p=t.getArrayValueOrDefault(o,5,""),f=t.getArrayValueOrDefault(o,6,""),d=t.getArrayValueOrDefault(o,7,"0"),v=t.getArrayValueOrDefault(o,8,"0"),a=t.getArrayValueOrDefault(o,9,""),y=t.getArrayValueOrDefault(o,10,""),m=t.getArrayValueOrDefault(o,11,""),t.debugMode&&console.info('level=debug component=f5 handler=ingest event=ingest_request ingestType="'.concat(t.ingestType,'" headerFingerprint="').concat(m,'"')),void 0===a){e.next=4;break}return e.prev=1,e.next=2,t.decryptCookieValue(a);case 2:a=e.sent,e.next=4;break;case 3:e.prev=3,e.catch(1),a=void 0;case 4:t.ingest({ip:c,userAgent:s,status:u,method:l,path:h,protocol:p,referer:f,bytesSent:d,requestTime:v,mitataCookie:a,sessionStatus:y,headerFingerprint:m}).catch((function(e){console.error("Could not reach Netacea ingest API: "+e.message)})),n.reply("done");case 5:case"end":return e.stop()}}),e,null,[[1,3]])})));return function(t,r){return e.apply(this,arguments)}}())}},{key:"makeRequest",value:(l=s(i().mark((function e(t){var r=this;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,new Promise((function(e,n){t.host=t.host.replace("https://","");var a=t.path;if(void 0!==t.params){var i=t.params instanceof URLSearchParams?t.params.toString():P.stringify(t.params);""!==i&&(a+=(a.includes("?")?"&":"?")+i)}for(var o=O.request({agent:r.httpsAgent,host:t.host,path:a,headers:t.headers,method:t.method,body:t.body},(function(t){var r="";t.on("data",(function(e){r+=e})),t.on("end",(function(){var n;e({headers:t.headers,status:null!==(n=t.statusCode)&&void 0!==n?n:0,body:""===r?void 0:r})}))})),c=0,s=["error","abort","timeout"];c<s.length;c++){var u=s[c];o.on(u,(function(e){n(e),o.destroyed||o.destroy()}))}"post"===t.method.toLowerCase()&&o.write(t.body),o.end()}));case 1:return e.abrupt("return",e.sent);case 2:case"end":return e.stop()}}),e)}))),function(e){return l.apply(this,arguments)})},{key:"mitigate",value:(c=s(i().mark((function e(t){var r,n,a,o;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,this.getMitigationResponse(t);case 1:return r=e.sent,n={sessionStatus:r.sessionStatus,setCookie:r.setCookie},r.mitigated&&(n.response={body:null!==(a=r.body)&&void 0!==a?a:"Forbidden",status:403,apiCallStatus:null!==(o=r.apiCallStatus)&&void 0!==o?o:-1,mitigation:r.mitigation,mitigated:r.mitigated}),e.abrupt("return",n);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return c.apply(this,arguments)})},{key:"inject",value:(o=s(i().mark((function e(t){var r;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,this.getMitigationResponse(t);case 1:return r=e.sent,e.abrupt("return",{injectHeaders:r.injectHeaders,sessionStatus:r.sessionStatus,setCookie:r.setCookie});case 2:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"getMitigationResponse",value:(n=s(i().mark((function e(t){var r,n,a,o,c,u,l,h;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.ip,n=t.userAgent,a=t.url,o=t.method,c=t.mitataCookie,u=t.mitataCaptchaCookie,l=t.body,h=t.headerFingerprint,e.next=1,this.processMitigateRequest({clientIp:r,getBodyFn:function(){var e=s(i().mark((function e(){return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,Promise.resolve(l);case 1:return e.abrupt("return",e.sent);case 2:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),method:o,mitata:c,mitataCaptcha:u,url:a,userAgent:n},h);case 1:return e.abrupt("return",e.sent);case 2:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"ingest",value:(r=s(i().mark((function e(t){var r,n,a,o,c,s,u,l,h,p,f,d;return i().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.ip,n=t.userAgent,a=t.status,o=t.method,c=t.path,s=t.protocol,u=t.referer,l=t.bytesSent,h=t.requestTime,p=t.mitataCookie,f=t.sessionStatus,d=t.headerFingerprint,e.next=1,this.callIngest({ip:r,userAgent:n,status:a,method:o,bytesSent:l,path:c,protocol:s,referer:u,requestTime:h,mitataCookie:p,sessionStatus:f,headerFingerprint:d,integrationType:"@netacea/f5".replace("@netacea/",""),integrationVersion:"5.0.2"});case 1:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"getCookieHeader",value:function(e){if(void 0!==e.mitataCookie)return"".concat(this.mitataCookieName,"=").concat(e.mitataCookie)}}]);var r,n,o,c,l,p,f,v,y,g}();function Ce(e,t){return"string"==typeof e&&""!==e?e:"number"==typeof e?e.toString():t}module.exports=we;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netacea/f5",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.2",
|
|
4
4
|
"description": "Netacea F5 CDN integration",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/index.js",
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
"aws4": "^1.13.2",
|
|
22
22
|
"f5-nodejs": "^1.0.0"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "a3a09c10acfd2cd3a4b7c3db59f6ba15f50a25b0"
|
|
25
25
|
}
|