Skip to content

feat: Support for IAST Scan Failure event #210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions lib/nr-security-agent/lib/core/FuzzFailEvent.js

This file was deleted.

50 changes: 50 additions & 0 deletions lib/nr-security-agent/lib/core/IASTScanFailure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2024 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: New Relic Software License v1.0
*/

const { BasicInfo } = require('./event');
const applicationInfo = require('./applicationinfo').getInstance();
const { NR_CSEC_FUZZ_REQUEST_ID, CSEC_SEP, EMPTY_STR } = require('./sec-agent-constants');
const LinkingMetaData = require('./LinkingMetadata');
/**
* Function Constructor to create object of IASTScanFailure event
* @param {*} fuzzRequest
*/
function IASTScanFailure(fuzzRequest, logMessageException, failureMessage) {
BasicInfo.call(this);

this.jsonVersion = applicationInfo.jsonVersion;
this.jsonName = 'iast-scan-failure';
this.pid = applicationInfo.pid;
this.applicationUUID = applicationInfo.applicationUUID;
this.groupName = applicationInfo.groupName;
this.policyVersion = applicationInfo.policyVersion;
this.replayFailure = {
apiId: getAPIId(fuzzRequest),
error: logMessageException,
nrCsecFuzzRequestId: fuzzRequest.headers[NR_CSEC_FUZZ_REQUEST_ID],
controlCommandId: fuzzRequest['id'],
failureMessage: failureMessage ? failureMessage : EMPTY_STR
};
this.linkingMetadata = LinkingMetaData.getLinkingMetadata();
this.securityAgentMetaData = {}
}

function getAPIId(fuzzRequest) {
let apiId = EMPTY_STR;
try {
if (fuzzRequest.headers && fuzzRequest.headers[NR_CSEC_FUZZ_REQUEST_ID]) {
apiId = fuzzRequest.headers[NR_CSEC_FUZZ_REQUEST_ID].split(CSEC_SEP)[0];
}
} catch (error) {
}
return apiId;

}

IASTScanFailure.prototype.constructor = IASTScanFailure;

module.exports = {
IASTScanFailure
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const stringify = require('fast-safe-stringify');
const restClient = require('../../restclient');
const grpcClient = require('../../grpcClient');
const { Agent } = require('../../../agent');
const { FuzzFailEvent } = require('../../../FuzzFailEvent');
const { IASTScanFailure } = require('../../../IASTScanFailure');
const { CSEC_HOME_TMP, COLON, NR_CSEC_FUZZ_REQUEST_ID, SLASH, CSEC_SEP, SEVERE } = require('../../../sec-agent-constants');
const LOCALHOST = 'localhost';
const COLON_SLASH_SLASH = '://';
Expand All @@ -22,6 +22,7 @@ require('dns').setDefaultResultOrder('ipv4first')
const PolicyManager = require('../../../Policy');

const statusUtils = require('../../../statusUtils');
const { error } = require('console');

const find = `${SLASH}{{NR_CSEC_VALIDATOR_HOME_TMP}}`;
const CSEC_HOME_TMP_CONST = new RegExp(find, 'g');
Expand Down Expand Up @@ -156,16 +157,25 @@ function handleFuzzRequest(fuzzDetails) {
logger.info('Firing http request:: URL: ' + config.url);
const response = restClient.fireRequest(config);
handleFuzzResponse(response, fuzzDetails);

}
} catch (err) {
statusUtils.addErrortoBuffer(err);
const fuzzFailEvent = new FuzzFailEvent(fuzzRequest.headers[NR_CSEC_FUZZ_REQUEST_ID]);
logger.error(stringify(fuzzFailEvent));
logger.debug("Error while fuzzing:", err)

//Generation of IAST Scan Failure
const logMessage = new LogMessage.logMessage(SEVERE, 'Error while fuzzing', __filename, err);
const iastScanErrorEvent = new IASTScanFailure(fuzzRequest, logMessage.exception, "Unable to fuzz given control command");
logger.error(stringify(iastScanErrorEvent))

try {
Agent.getAgent().client.dispatcher(fuzzFailEvent);
Agent.getAgent().client.dispatcher(iastScanErrorEvent);
} catch (error) {
logger.debug('Error in sending fuzz request:', error.stack);
logger.debug('Error in sending fuzzing error:', error.stack);
}



}
}

Expand Down
Loading