@hclsoftware/secagent
Version:
IAST agent
48 lines (43 loc) • 2 kB
JavaScript
//IASTIGNORE
/*
* ****************************************************
* Licensed Materials - Property of HCL.
* (c) Copyright HCL Technologies Ltd. 2017, 2025.
* Note to U.S. Government Users *Restricted Rights.
* ****************************************************
*/
const BeforeRule = require("./BeforeRule");
const {registerObjectTaint} = require("../../TaintTracker")
const RequestInfo = require("../../RequestInfo")
const StackInfo = require("../../StackInfo");
const {EntityType} = require("../../Entity");
/**
* RegisterTaintOnRabbitMQMessageRule registers taint on the RabbitMQ message.
* It is done here since express hooks doesn't handle the RabbitMQ message protocol
* and also there is no request information in the message, there creating one here for message's TaintedObjectData
* @class RegisterTaintOnRabbitMQMessageRule
* @extends BeforeRule
* @see BeforeRule
*/
module.exports = class RegisterTaintOnRabbitMQMessageRule extends BeforeRule {
doRule(hookValues) {
try {
// receiver method signature: handleMessage (message) and message = {content: {}, fields: {}, properties: {}}
const message = hookValues.args[0]
message.content = this.getTaintedObject(message.content, message.fields, hookValues)
} catch (err) {
console.origLog("Cannot register taint. Exception:" + err);
}
}
getTaintedObject(content, fields, hookValues) {
let requestInfo = new RequestInfo( {
uri : fields.routingKey,
url : fields.routingKey,
method: "RabbitMQ",
queryString: "",
secure: true
}, null)
const parameters = StackInfo.getParamsStringArray(hookValues.that, hookValues.simpleThat, hookValues.methodName, hookValues.simpleArgs, hookValues.simpleRet)
return registerObjectTaint(content, requestInfo, "", content.toString(), EntityType.MESSAGE, parameters)
}
}