-
Notifications
You must be signed in to change notification settings - Fork 67
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: AwsSolutions-APIG4 triggers for CORS preflight endpoints #1816
Conversation
I thinks it's better to keep the current implementation of the rule and add additional information on the description that it may not apply to pre-flight endpoints Instead of marking all While not ideal I'd rather users suppress false positives instead of opening up the rule for false negatives |
I'm alright with updating the description, but I would rather update the check as it is affecting a built-in feature of CDK. If all we are concerned about is false negatives, then could we take the other approach of matching the built-in CORS feature by matching against the |
Perhaps we could be a bit more generic and check the above |
I've just updated the check to match the If you still think it's better to leave it then I'm happy to revert and just change the description. However, I did try and come up with an exemption config which only exempts |
You can mark that specific case as NagRuleCompliance.NOT_APPLICABLE |
test/rules/APIGW.test.ts
Outdated
@@ -193,7 +194,11 @@ describe('Amazon API Gateway', () => { | |||
}); | |||
validateStack(stack, ruleId, TestType.NON_COMPLIANCE); | |||
}); | |||
test('Compliance', () => { | |||
test('Noncompliance 3', () => { | |||
new RestApi(stack, 'rRestApi').root.addMethod('OPTIONS'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the r
prefix from the resource names. That's a legacy naming convention that I'd like to remove from the code base
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, I've just removed it from the tests within the describe block, let me know if you want it removed for the whole file.
Thanks for contributing! 🎉 |
Fixes #1815.
Currently this PR just marks all
OPTIONS
methods as compliant. I'm not sure the best way to narrow this down to specifically CORS preflight endpoints. We could try and match the template that CDK generates through itsaddCorsPreflight
method, but that won't include any custom preflight endpoints which people may be using, and any changes to the CDK template may break our checks here.I took a look at the MDN docs for the
OPTIONS
method, and it seems like it has limited use cases outside of CORS. Perhaps we can mark them all as compliant?Here is the CloudFormation CfnMethod template which CDK generates when using the following code: