UNPKG

@hclsoftware/secagent

Version:

IAST agent

67 lines (56 loc) 2.97 kB
//IASTIGNORE // save orig method for use by the agent // a separate file because we need those before we apply the hooks // e.g. - it is used by logger /* * **************************************************** * Licensed Materials - Property of HCL. * (c) Copyright HCL Technologies Ltd. 2017, 2025. * Note to U.S. Government Users *Restricted Rights. * **************************************************** */ const IastProperties = require('./IastProperties') saveOrigMethod(['String', 'prototype'], 'concat', 'origConcat') saveOrigMethod(['String', 'prototype'], 'replace', 'origReplace') saveOrigMethod(['String', 'prototype'], 'toLowerCase', 'origToLowerCase') saveOrigMethod(['String', 'prototype'], 'includes', 'origStringIncludes') saveOrigMethod(['String', 'prototype'], 'replaceAll', 'origReplaceAll') saveOrigMethod(['String', 'prototype'], 'match', 'origMatch') saveOrigMethod(['String', 'prototype'], 'split', 'origSplit') saveOrigMethod(['String', 'prototype'], 'toUpperCase', 'origToUpperCase') saveOrigMethod(['String', 'prototype'], 'substring', 'origSubstring') saveOrigMethod(['String', 'prototype'], 'trim', 'origTrim') saveOrigMethod(['String', 'prototype'], 'startsWith', 'origStartsWith') saveOrigMethod(['String', 'prototype'], 'endsWith', 'origEndsWith') saveOrigMethod(['String', 'prototype'], 'lastIndexOf', 'origLastIndexOf') saveOrigMethod(['String', 'prototype'], 'indexOf', 'origIndexOf') saveOrigMethod(['String', 'prototype'], 'slice', 'origSlice') saveOrigMethod(['String', 'prototype'], 'toString', 'origToString') saveOrigMethod(['Array', 'prototype'], 'slice', 'origSlice') saveOrigMethod(['Array', 'prototype'], 'join', 'origJoin') saveOrigMethod(['Array', 'prototype'], 'includes', 'origArrayIncludes') saveOrigMethod(['Array'], 'from', 'origFrom') saveOrigMethod(['Buffer'], 'from', 'origFrom') saveOrigMethod(['Buffer'], 'concat', 'origConcat') saveOrigMethod(['RegExp', 'prototype'], 'test', 'origTest') saveOrigMethod(['JSON'], 'stringify', 'origStringify') saveOrigMethod(['JSON'], 'parse', 'origParse') saveOrigMethod([], 'isNaN', 'origIsNaN') saveOrigMethod(['Math'], 'random', 'origRandom') saveOrigMethod([], 'Error', 'origError') saveOrigMethod(['console'], 'log', 'origLog') saveOrigMethod(['console'], 'error', 'origError') // currently createHash is not added due to FP // const crypto = require('crypto') // IastProperties.definePropertyWithValue(crypto, 'origCreateHash', crypto['createHash']) /** * Saves the original function with 'orig' prefixed name, to be able to call original methods in the Agent so hook code is ignored. * @function saveOrigMethod */ function saveOrigMethod(scopes, propertyName, newOrigPropertyName) { let hookScope = global for (const scope of scopes) { hookScope = hookScope[scope] } IastProperties.definePropertyWithValue(hookScope, newOrigPropertyName, hookScope[propertyName]) }