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

route53: " not escaped correctly #26104

Closed
dbartholomae opened this issue Jun 23, 2023 · 5 comments
Closed

route53: " not escaped correctly #26104

dbartholomae opened this issue Jun 23, 2023 · 5 comments
Labels
@aws-cdk/aws-route53 Related to Amazon Route 53 bug This issue is a bug. effort/small Small work item – less than a day of effort p2

Comments

@dbartholomae
Copy link
Contributor

Describe the bug

Hi there!

    new TxtRecord(this, "TxtRecord", {
      recordName: "xxx.example.com",
      values: [
        'a""b',
      ],
      zone,
    });

Expected Behavior

This should generate a text record with a""b

Current Behavior

It creates a\"\"b instead.

Reproduction Steps

See example

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.72.1

Framework Version

No response

Node.js Version

16.14.2

OS

Mac

Language

Typescript

Language Version

No response

Other information

No response

@dbartholomae dbartholomae added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 23, 2023
@github-actions github-actions bot added the @aws-cdk/aws-route53 Related to Amazon Route 53 label Jun 23, 2023
@stefanfreitag
Copy link
Contributor

stefanfreitag commented Jun 23, 2023

Hi @dbartholomae ,

I have seen this behavior also when creating a TXT record in the AWS Management Console itself.
The double quotes are escaped in the way you described: a""b -> a\"\"b,

The latter seems to be in line with the Route53 documentation available here. There is an information about using double quotes:

To include a quotation mark (") in a string, put a backslash (\) character before the quotation mark: \".

An example is also provided

"This string includes \"quotation marks\"."

Hope this helps a bit.

@peterwoodworth
Copy link
Contributor

We seem to do this intentionally

export class TxtRecord extends RecordSet {
constructor(scope: Construct, id: string, props: TxtRecordProps) {
super(scope, id, {
...props,
recordType: RecordType.TXT,
target: RecordTarget.fromValues(...props.values.map(v => formatTxt(v))),
});
}
}
/**
* Formats a text value for use in a TXT record
*
* Use `JSON.stringify` to correctly escape and enclose in double quotes ("").
*
* DNS TXT records can contain up to 255 characters in a single string. TXT
* record strings over 255 characters must be split into multiple text strings
* within the same record.
*
* @see https://aws.amazon.com/premiumsupport/knowledge-center/route53-resolve-dkim-text-record-error/
*/
function formatTxt(string: string): string {
const result = [];
let idx = 0;
while (idx < string.length) {
result.push(string.slice(idx, idx += 255)); // chunks of 255 characters long
}
return result.map(r => JSON.stringify(r)).join('');
}

Thanks for the additional context @stefanfreitag. @dbartholomae is there a specific value you're trying to provide that doesn't want to have the backslash?

@peterwoodworth peterwoodworth added p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jun 23, 2023
@dbartholomae
Copy link
Contributor Author

Thanks! I'm currently transferring an existing Hosted Zone to CDK and compare the records with help of aws route53 list-resource-record-sets. The specific record that I can't seem to match exactly is a verification record from an external provider and I will reach out to them to understand whether the quote is intentional, but given that the current version works, I'm hesitant to just change it to a version with backslash.
Do you know if there is a workaround to manually set the value to include the quotation mark?

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jun 24, 2023
@dbartholomae
Copy link
Contributor Author

Thanks! The difference came because the record was larger than maximum length and CDK split it at a different point than the previous setup. Since this doesn't have an effect on the actual record, the current behavior should be fine except for very weird special cases.

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-route53 Related to Amazon Route 53 bug This issue is a bug. effort/small Small work item – less than a day of effort p2
Projects
None yet
Development

No branches or pull requests

3 participants