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(apigateway): validation for path parts does not allow creation of resources beginning with dollar sign #27619

Merged
Merged
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

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"myapiDeployment92F2CB4993c0f175ba8d5964f5e1cc7bc64fe6e6": {
"myapiDeployment92F2CB49069d16df09c59427069eb74581a0403d": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"Description": "beta stage",
Expand All @@ -66,8 +66,8 @@
}
},
"DependsOn": [
"myapiv1appliancesallGETC4DF552D",
"myapiv1appliancesallCF8C6A16",
"myapiv1appliancesallGETB8EB1B77",
"myapiv1appliancesallD279897B",
"myapiv1booksGETC6B996D0",
"myapiv1booksPOST53E2832E",
"myapiv1books1D4BE6C1",
Expand All @@ -86,7 +86,7 @@
"CacheClusterEnabled": true,
"CacheClusterSize": "0.5",
"DeploymentId": {
"Ref": "myapiDeployment92F2CB4993c0f175ba8d5964f5e1cc7bc64fe6e6"
"Ref": "myapiDeployment92F2CB49069d16df09c59427069eb74581a0403d"
},
"Description": "beta stage",
"MethodSettings": [
Expand Down Expand Up @@ -290,19 +290,19 @@
}
}
},
"myapiv1appliancesallCF8C6A16": {
"myapiv1appliancesallD279897B": {
"Type": "AWS::ApiGateway::Resource",
"Properties": {
"ParentId": {
"Ref": "myapiv113487378"
},
"PathPart": "appliances:all",
"PathPart": "$appliances:all",
"RestApiId": {
"Ref": "myapi4C7BF186"
}
}
},
"myapiv1appliancesallGETC4DF552D": {
"myapiv1appliancesallGETB8EB1B77": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
"AuthorizationType": "NONE",
Expand All @@ -311,7 +311,7 @@
"Type": "MOCK"
},
"ResourceId": {
"Ref": "myapiv1appliancesallCF8C6A16"
"Ref": "myapiv1appliancesallD279897B"
},
"RestApiId": {
"Ref": "myapi4C7BF186"
Expand Down Expand Up @@ -682,7 +682,7 @@
}
},
"DependsOn": [
"myapiv1appliancesallGETC4DF552D",
"myapiv1appliancesallGETB8EB1B77",
"myapiv1booksGETC6B996D0",
"myapiv1booksPOST53E2832E",
"myapiv1toysGET7348114D",
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Test extends cdk.Stack {
toys.addMethod('POST');
toys.addMethod('PUT');

const appliances = v1.addResource('appliances:all');
const appliances = v1.addResource('$appliances:all');
appliances.addMethod('GET');

const books = v1.addResource('books');
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk-lib/aws-apigateway/lib/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,8 @@ function validateResourcePathPart(part: string) {
}
}

if (!/^[a-zA-Z0-9:\.\_\-]+$/.test(part)) {
throw new Error(`Resource's path part only allow [a-zA-Z0-9:._-], an optional trailing '+'
if (!/^[a-zA-Z0-9:\.\_\-\$]+$/.test(part)) {
throw new Error(`Resource's path part only allow [a-zA-Z0-9:._-$], an optional trailing '+'
and curly braces at the beginning and the end: ${part}`);
}
}
17 changes: 17 additions & 0 deletions packages/aws-cdk-lib/aws-apigateway/test/resource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ describe('resource', () => {
const aResource = api.root.addResource('a');
const cResource = aResource.addResource('b').addResource('c');
const colonResource = cResource.addResource('d:e');
const dollarResource = cResource.addResource('$d');

// THEN
expect(stack.resolve(api.urlForPath(aResource.path))).toEqual({
Expand Down Expand Up @@ -247,6 +248,22 @@ describe('resource', () => {
],
],
});
expect(stack.resolve(api.urlForPath(dollarResource.path))).toEqual({
'Fn::Join': [
'',
[
'https://',
{ Ref: 'apiC8550315' },
'.execute-api.',
{ Ref: 'AWS::Region' },
'.',
{ Ref: 'AWS::URLSuffix' },
'/',
{ Ref: 'apiDeploymentStageprod896C8101' },
'/a/b/c/$d',
],
],
});

});

Expand Down