Skip to content
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

fix(NODE-5260): AWS Lambda metadata detection logic is too permissive #3663

Merged
merged 7 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion src/cmap/handshake/client_metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ export function getFAASEnv(): Map<string, string | Int32> | null {
VERCEL_REGION = ''
} = process.env;

const isAWSFaaS = AWS_EXECUTION_ENV.length > 0 || AWS_LAMBDA_RUNTIME_API.length > 0;
const isAWSFaaS =
AWS_EXECUTION_ENV.startsWith('AWS_Lambda_') || AWS_LAMBDA_RUNTIME_API.length > 0;
const isAzureFaaS = FUNCTIONS_WORKER_RUNTIME.length > 0;
const isGCPFaaS = K_SERVICE.length > 0 || FUNCTION_NAME.length > 0;
const isVercelFaaS = VERCEL.length > 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ describe('Handshake Prose Tests', function () {
['AWS_EXECUTION_ENV', 'AWS_Lambda_java8'],
['AWS_LAMBDA_FUNCTION_MEMORY_SIZE', 'big']
]
},
{
expectedProvider: undefined,
context: '8. Invalid - AWS_EXECUTION_ENV does not start with "AWS_Lambda_"',
env: [['AWS_EXECUTION_ENV', 'EC2']]
}
];

Expand Down
15 changes: 9 additions & 6 deletions test/unit/cmap/handshake/client_metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ describe('client metadata module', () => {
context(`when ${envVariable} is in the environment`, () => {
before(() => {
process.env[envVariable] = 'non empty string';
if (envVariable === 'AWS_EXECUTION_ENV') {
process.env[envVariable] = 'AWS_Lambda_non empty string';
}
});
after(() => {
delete process.env[envVariable];
Expand All @@ -70,7 +73,7 @@ describe('client metadata module', () => {
context('unrelated environments', () => {
before(() => {
// aws
process.env.AWS_EXECUTION_ENV = 'non-empty-string';
process.env.AWS_EXECUTION_ENV = 'AWS_Lambda_non-empty-string';
dariakp marked this conversation as resolved.
Show resolved Hide resolved
// azure
process.env.FUNCTIONS_WORKER_RUNTIME = 'non-empty-string';
});
Expand Down Expand Up @@ -384,15 +387,15 @@ describe('client metadata module', () => {
aws: [
dariakp marked this conversation as resolved.
Show resolved Hide resolved
{
context: 'no additional metadata',
env: [['AWS_EXECUTION_ENV', 'non-empty string']],
env: [['AWS_EXECUTION_ENV', 'AWS_Lambda_non-empty string']],
outcome: {
name: 'aws.lambda'
}
},
{
context: 'AWS_REGION provided',
env: [
['AWS_EXECUTION_ENV', 'non-empty string'],
['AWS_EXECUTION_ENV', 'AWS_Lambda_non-empty string'],
['AWS_REGION', 'non-null']
],
outcome: {
Expand All @@ -403,7 +406,7 @@ describe('client metadata module', () => {
{
context: 'AWS_LAMBDA_FUNCTION_MEMORY_SIZE provided',
env: [
['AWS_EXECUTION_ENV', 'non-empty string'],
['AWS_EXECUTION_ENV', 'AWS_Lambda_non-empty string'],
['AWS_LAMBDA_FUNCTION_MEMORY_SIZE', '3']
],
outcome: {
Expand Down Expand Up @@ -526,7 +529,7 @@ describe('client metadata module', () => {
context('when faas region is too large', () => {
beforeEach('1. Omit fields from `env` except `env.name`.', () => {
sinon.stub(process, 'env').get(() => ({
AWS_EXECUTION_ENV: 'iLoveJavaScript',
AWS_EXECUTION_ENV: 'AWS_Lambda_iLoveJavaScript',
AWS_REGION: 'a'.repeat(512)
}));
});
Expand All @@ -543,7 +546,7 @@ describe('client metadata module', () => {
context('release too large', () => {
beforeEach('2. Omit fields from `os` except `os.type`.', () => {
sinon.stub(process, 'env').get(() => ({
AWS_EXECUTION_ENV: 'iLoveJavaScript',
AWS_EXECUTION_ENV: 'AWS_Lambda_iLoveJavaScript',
AWS_REGION: 'abc'
}));
sinon.stub(os, 'release').returns('a'.repeat(512));
Expand Down