1.11.85 • Published 10 months ago

@erboladaiorg/quos-hic v1.11.85

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

@erboladaiorg/quos-hic

CircleCI

Why?

You want to let end users enter their own regular expressions. But regular expressions can lead to catastrophic backtracking. This can take up hours of CPU time. In Node.js this means no other code can execute. It is a Denial of Service (DOS) attack vector, whether intentionally or by accident.

This module lets you test regular expressions with a time limit to mitigate the pain.

Usage

// Set a 1-second limit. Default is 0.25 seconds
const regExp = require('@erboladaiorg/quos-hic')({ limit: 1 });

// A common email address validator with potentially evil characteristics
// (catastrophic backtracking)
const evil = /^([a-zA-Z0-9])(([\-.]|[_]+)?([a-zA-Z0-9]+))*(@){1}[a-z0-9]+[.]{1}(([a-z]{2,3})|([a-z]{2,3}[.]{1}[a-z]{2,3}))$/;

(async () => {
  // Run a potentially slow regular expression on short, matching input
  const realEmail = 'test@test.com';
  const realEmailResult = await regExp.match(evil, realEmail);
  // Normal behavior, may be truthy or falsy according to match,
  // returns the same array result as regular regexp match() calls
  console.log(realEmailResult);
  // This input is long enough to trigger catastrophic backtracking and
  // could take hours to evaluate
  const evilEmail = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
  try {
    const evilEmailResult = await regExp.match(evil, evilEmail);
    // We will not get here, exception will be thrown
  } catch (e) {
    console.log(e.name); // Will be 'timeout'
  }
})();

Notes

"Why is match an async function?" It runs in a separate process because that is the only way to avoid starving the Node.js application and implement a portable timeout on the regular expression.

"How bad is the performance overhead?" Communication with a separate worker process makes it slower of course, but the process is reused by later calls, so the hit is not serious.

Flags, for instance the g flag, are supported.

You can pass the regular expression as a string, but regular expression literals (what you are used to typing) are easier to get right because you don't have to double-escape anything.

flatMapsetPrototypeOfpasswordES2017has-ownObject.definePropertydirexecfile-0codesbabelhardlinks_.extendTypeBoxArrayBuffer#sliceworkflowJSONObject.keyscallbinditerationvarserror-handlinga11ymkdirbrowserURLSearchParamsRegExp#flagsutilsparserwidthArray.prototype.includesprotofantasy-landutil.inspectcloudwatchdateextendwindowsnativeswfloggerObject.getPrototypeOfrobustsignalargsreadimmutablel10nbundlercompilerpinoHyBipyyamlcore-jsexpressionObservableiteratoriechaiperformancequeueMicrotaskissymbolsvalidateexitjson-schemaglobalThisString.prototype.trimcjkefficientdependenciesstarterhashgetintrinsiceventDispatcherbinaryfast-cloneletargvfastcopyJSON-SchemaoncekoreanECMAScript 2016stringyamlhookformpackage managermkdirpchinesecss variableisConcatSpreadableshellkinesisdayjsString.prototype.matchAllserializationprotobufArray.prototype.flatreact-componentclassespluginponyfillextrastyled-componentsmapECMAScriptcloudformationjsoneslintconfigpreprocessorsettingsECMAScript 2018rapidURLemrtypeemitbinariesregularArray.prototype.flattengroupBydescriptionclass-validatorvariablesMaptypesexecworkspace:*less compilerregular expressionio-tses8asciiReactiveExtensionshandlerArray.prototype.flatMapinstallerstatusUint16Arrayinputpropertymakespinnerwritepackage.jsoninferencedirectorytypescriptdropgetpopmotionreplayrangeerrortraverseeslintprocesslengthfigletES8ansifunction.length256AsyncIteratorstylestoragegatewaywarningsessharedcolumnslruxhrcall-binddragsharedarraybufferWeakMapsyntaxclassnamesuperstructelectroncopyeffect-tselblesscssenvironmentreadablestreamassertsclientECMAScript 2020Function.prototype.namedataViewconcatMapsafeintrinsicclonegestureswritablejestpicomatchlocationES3loadbalancingdeletesimpledbzxframerfullcryptoES7sqstermendercallbackcorepropwaapinamesBigUint64Arrayfastclonegroupmulti-packagemodulesArrayBuffer.prototype.slicekeysdeepcopylocalcheckdatastyleguidetypedmapreducegradients css3expressnopeUint32ArrayvestES2016symlinkjQueryutilObject.isRxregexfindLastsubprocessreact poseautoprefixerunicodees7fpbootstrap lesstoolsgetOwnPropertyDescriptorcss nestingES5stylingsnsWebSocketsflagbyteweakmapInt32Arraycensorflatlazyprivate0sequencenested csscontainsfluxargumentmrunumbertesterspeedhasOwnPropertyArray.prototype.filtertddhttpsimmerfull-widthconsumesyntaxerrorPushCSStestterminalstablecircularESnextsymlinkseveryECMAScript 2022__proto__offsetsameValueZeroautoscalingfile systemdatastructureequalityredactcolorrecursiveauthmodulestreamidentifiers.envdataviewES2015fetchasttypedarraysshimhigher-ordercollectionrandomminimaltrimtranspilervariables in cssArray.prototype.findLastIndexSystem.globalschemees-abstractconsolecommandermixinsencryptioneventEmitternpmespreebabel-corelintagentsidevartc39schematacitmockingrequestsigintfindpostcss-plugin$.extendless.jsglacierurlstylesheetoperating-systemmacosentriesyupdefinePropertyworkerchromiumtypeofinUint8ClampedArraypackagesdeepObject.valuesvpccolumnesprotocol-bufferspolyfillapollonpmignorefnmatchStreamrdsES2019servicepostcssloggingbuffersReactiveXprivate dataselfbufferhandlersreactassertionless mixinstakeuploadinspecttrimStartpathimportphoneFloat64Arraydescriptorsfilterglobal this valueruleswafes5apisetteropensslObject.gitignoreartpnpm9WeakSetcolorsprettyassertsymboldom-testing-librarycss lesssignedkeyserializerWebSocketcallboundinstallstructuredCloneSymbol.toStringTagsuperagentSetpromisebddlastES2023statelesswalkgradients cssobjfunctionform-validationcss-in-jsscheme-validationservertouchcommandinternalelmformarraysperformantObject.assignsigtermcertificatesmonorepoassignutilitiesReflect.getPrototypeOfinvariantincludesRegExp.prototype.flagses-shimss3uninstallmkdirsfast-copycall-boundwhichchromehasOwnfast-deep-copysignalstoobjectprototypeescapeinternal slotcomputed-typesstringifyawslinuxconfigcompile lessSymbolECMAScript 2015typesafecallRFC-6455exit-codefast-deep-clonereuseCSSStyleDeclarationreal-timejson-schema-validatortyped arrayES2022point-freejsxjwtObject.fromEntriesTypedArrayresolvees6fullwidthtslibjapanesematchAllarrayglobalshotvalidationgdprredirectec2difftranspileback-endhooksstreamscloudfrontdeep-clonecurlairbnbInt8ArraytoArraygitignorejstelephoneUnderscorefindLastIndexsetajvfront-endES2020cliECMAScript 2023shamidlecharacterbindes2018metadataformatpropertiesStyleSheetYAML[[Prototype]]movebyteLengthwindowcloudtrailbyteOffsetview3dbinserializereduxdynamodbramdaeventswaitvisualcollection.es6globalajaxindicatortoSortedpipedescriptorsortwgetchanneltransportcloudsearchmake dirInt16ArrayreadablemomentgetPrototypeOfauthenticationTypeScriptdeep-copytsdotenvglobal objectebsutilityharmonyObservablesvalidatorgenericsnodejsobjectiteratetoStringTagquoteroutinggettertextsomeflattenregular-expressionformsqueueES6negative zerozodimportexporthttpexecutecsstoolkitfscreateomitflags@@toStringTaguser-streamsestreeRxJSi18nspinnerslanguageredux-toolkitshebangfunctionalArrayasterisksslotreducextermloglinkdeepclonelessgraphqlbusyownfileconsteslintplugingloboptionjson-schema-validationECMAScript 2019ECMAScript 6whatwgelasticacheanimationsliceparsecommand-lineroutematchBigInt64Arrayes-shim APIArrayBufferfastreact-testing-libraryarraybufferamazonpersistentnegativecomparejshintjsdomtostringtagacornformattingdependency managertypanionenvironmentstypeerrorliveMicrosoftprogressmanagercachecurriedchildttysortedfpsUint8ArrayES2021ECMAScript 2017testingtrimEndjoipushES2018es2015browserslistvalidECMAScript 2021forEachqueryjsdiffbcryptArray.prototype.containsspectimeIteratorzerobrowserlistarktypeproxyECMAScript 7namenodecoercibleeslint-pluginpredictableFloat32Arrayjsonschemaconfigurable
1.11.85

10 months ago

1.10.85

11 months ago

1.10.84

11 months ago

1.10.83

11 months ago

1.10.82

11 months ago

1.10.81

11 months ago

1.9.81

11 months ago

1.9.80

11 months ago

1.9.79

11 months ago

1.9.78

11 months ago

1.9.77

11 months ago

1.9.76

11 months ago

1.9.75

11 months ago

1.9.74

11 months ago

1.9.73

11 months ago

1.9.72

11 months ago

1.9.71

11 months ago

1.9.70

11 months ago

1.9.69

11 months ago

1.9.68

11 months ago

1.9.67

11 months ago

1.9.66

11 months ago

1.9.65

11 months ago

1.9.64

11 months ago

1.9.63

11 months ago

1.8.63

11 months ago

1.7.63

11 months ago

1.7.62

11 months ago

1.7.61

11 months ago

1.6.61

11 months ago

1.6.60

11 months ago

1.6.59

12 months ago

1.6.58

12 months ago

1.6.57

12 months ago

1.6.56

12 months ago

1.6.55

12 months ago

1.6.54

12 months ago

1.6.53

12 months ago

1.6.52

12 months ago

1.6.51

12 months ago

1.6.50

12 months ago

1.6.49

12 months ago

1.6.48

12 months ago

1.6.47

12 months ago

1.6.46

12 months ago

1.6.45

12 months ago

1.6.44

12 months ago

1.5.44

12 months ago

1.5.43

12 months ago

1.4.43

12 months ago

1.4.42

12 months ago

1.4.41

1 year ago

1.4.40

1 year ago

1.4.39

1 year ago

1.4.38

1 year ago

1.4.37

1 year ago

1.4.36

1 year ago

1.4.35

1 year ago

1.4.34

1 year ago

1.4.33

1 year ago

1.4.32

1 year ago

1.4.31

1 year ago

1.3.31

1 year ago

1.3.30

1 year ago

1.3.29

1 year ago

1.3.28

1 year ago

1.3.27

1 year ago

1.3.26

1 year ago

1.2.26

1 year ago

1.1.26

1 year ago

1.1.25

1 year ago

1.1.24

1 year ago

1.1.23

1 year ago

1.1.22

1 year ago

1.1.21

1 year ago

1.1.20

1 year ago

1.1.19

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

1.1.16

1 year ago

1.1.15

1 year ago

1.1.14

1 year ago

1.1.13

1 year ago

1.1.12

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago