Skip to content

Commit

Permalink
fix: RD-13884-Node-Tracer-can-change-event-body-of-a-Lambda-function (#…
Browse files Browse the repository at this point in the history
…522)

* fix: node tracer can change event body of a lambda function
  • Loading branch information
eugene-lumigo authored Oct 30, 2024
1 parent fc31380 commit 4e86360
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@lumigo/node-core": "1.16.0",
"agentkeepalive": "^4.1.4",
"axios": "1.7.7",
"rfdc": "^1.4.1",
"shimmer": "1.2.1",
"utf8": "^3.0.0"
},
Expand Down
4 changes: 3 additions & 1 deletion src/parsers/eventParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {

import * as logger from '../logger';
import { getEnvVarAsList, isScrubKnownServicesOn } from '../utils';
const clone = require('rfdc')();

const API_GW_KEYS_ORDER = getEnvVarAsList('LUMIGO_API_GW_KEYS_ORDER', [
'version',
Expand Down Expand Up @@ -234,7 +235,8 @@ export const parseCloudfrontEvent = (event: CloudFrontRequestEvent) => {
return newCloudfrontEvent;
};

export const parseEvent = (event) => {
export const parseEvent = (awsEvent) => {
const event = clone(awsEvent);
if (isApiGwEvent(event)) {
return parseApiGwEvent(event);
}
Expand Down
24 changes: 24 additions & 0 deletions src/spans/awsSpan.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
EXECUTION_TAGS_KEY,
getEventEntitySize,
LUMIGO_SECRET_MASKING_ALL_MAGIC,
LUMIGO_SECRET_MASKING_EXACT_PATH,
LUMIGO_SECRET_MASKING_REGEX_ENVIRONMENT,
LUMIGO_SECRET_MASKING_REGEX_HTTP_REQUEST_BODIES,
LUMIGO_SECRET_MASKING_REGEX_HTTP_REQUEST_HEADERS,
Expand Down Expand Up @@ -466,6 +467,29 @@ describe('awsSpan', () => {
expect(JSON.parse(startSpan.event).Records[0].s3.object.key).toEqual('value');
});

test('Lambda invoked by Lambda -> shouldnt scrub initial event', () => {
const { context } = TracerGlobals.getHandlerInputs();
const event = {
string: 'value',
object: {
string: 'value',
object: {
string: 'value',
},
},
};
process.env[LUMIGO_SECRET_MASKING_EXACT_PATH] =
'["string","object.string", "object.object.string"]';
TracerGlobals.setHandlerInputs({ event, context });
const startSpan = awsSpan.getFunctionSpan(event, context);

expect(event.string).toEqual('value');
expect(event.object.string).toEqual('value');
expect(event.object.object.string).toEqual('value');
expect(JSON.parse(startSpan.event).string).toEqual('****');
expect(JSON.parse(startSpan.event).object.object.string).toEqual('****');
});

test('Lambda invoked by DDB stream -> shouldnt scrub known fields', () => {
const { context } = TracerGlobals.getHandlerInputs();
const event = {
Expand Down

0 comments on commit 4e86360

Please sign in to comment.