Skip to content

Commit 991de0b

Browse files
committed
Refactor function resource arn regex to only allow valid characters
1 parent 9b94cf8 commit 991de0b

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/deploy/stepFunctions/compileIamRole.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = {
1212
customRolesProvided.push('role' in stateMachineObj);
1313

1414
const stateMachineJson = JSON.stringify(stateMachineObj);
15-
const regex = new RegExp(/"Resource":"([a-z:#{}_\-.]*)"/gi);
15+
const regex = new RegExp(/"Resource":"([\w\-:*]*)"/gi);
1616
let match = regex.exec(stateMachineJson);
1717
while (match !== null) {
1818
functionArns.push(match[1]);

lib/deploy/stepFunctions/compileIamRole.test.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ describe('#compileIamRole', () => {
8787
});
8888

8989
it('should give invokeFunction permission for only functions referenced by state machine', () => {
90-
const helloLambda = 'arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:hello';
91-
const worldLambda = 'arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:world';
90+
const helloLambda = 'arn:aws:lambda:123:*:function:hello';
91+
const worldLambda = 'arn:aws:lambda:*:*:function:world';
92+
const fooLambda = 'arn:aws:lambda:us-west-2::function:foo_';
9293
serverless.service.stepFunctions = {
9394
stateMachines: {
9495
myStateMachine1: {
@@ -117,6 +118,19 @@ describe('#compileIamRole', () => {
117118
},
118119
},
119120
},
121+
myStateMachine3: {
122+
name: 'stateMachineBeta3',
123+
definition: {
124+
StartAt: 'Foo',
125+
States: {
126+
Hello: {
127+
Type: 'Task',
128+
Resource: fooLambda,
129+
End: true,
130+
},
131+
},
132+
},
133+
},
120134
},
121135
};
122136

@@ -125,6 +139,6 @@ describe('#compileIamRole', () => {
125139
.provider.compiledCloudFormationTemplate.Resources.IamRoleStateMachineExecution
126140
.Properties.Policies[0];
127141
expect(policy.PolicyDocument.Statement[0].Resource)
128-
.to.be.deep.equal([helloLambda, worldLambda]);
142+
.to.be.deep.equal([helloLambda, worldLambda, fooLambda]);
129143
});
130144
});

0 commit comments

Comments
 (0)