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(cognito): quote or mime-encode fromName to comply RFC 5322 #23227

Merged
merged 4 commits into from Dec 19, 2022

Conversation

Tietew
Copy link
Contributor

@Tietew Tietew commented Dec 5, 2022

Closes #18903

When fromName of UserPoolEmail.withSES() does not comply RFC 5322 atom or quoted-string, it will be quoted or mime-encoded.

For example:

fromName Template Description
'simple atom' "simple atom <address@example.com>" as is
'"quoted string"' "\"quoted string\" <address@example.com>" as is
'あいう' "=?UTF-8?B?44GC44GE44GG?= <address@example.com>" mime encode (RFC 2047)
'name@company' "\"name@company\" <address@example.com>" make quoted-string

For details, see RFC 5322 Section 3.4 and RFC 2047


All Submissions:

Adding new Construct Runtime Dependencies:

  • This PR adds new construct runtime dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)?

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Dec 5, 2022

@aws-cdk-automation aws-cdk-automation requested a review from a team December 5, 2022 06:28
@github-actions github-actions bot added repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK bug This issue is a bug. p1 labels Dec 5, 2022
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

@Tietew
Copy link
Contributor Author

Tietew commented Dec 5, 2022

I tried to update integration test but it failed with following error:

Stack Deployments Failed: Error: The stack named integ-user-pool-signup-code failed to deploy: UPDATE_FAILED (The following resource(s) failed to update: [myuserpool01998219]. ): Cognito received the following error from Amazon SES when attempting to send email: Email address is not verified. The following identities failed the check in region US-EAST-1: arn:aws:ses:us-east-1:********:identity/example.com (Service: AWSCognitoIdentityProviderService; Status Code: 400; Error Code: InvalidParameterException; Request ID: ef20db4e-9e68-49df-ae9c-7c174fe9cd37; Proxy: null)

I cannot verify example.com domain. How do I fix this?

@Tietew
Copy link
Contributor Author

Tietew commented Dec 5, 2022

Is it acceptable to try following steps?

  1. replace existing test's domain from example.com to my private domain which is SES verified in us-east-1
  2. remove the old snapshot not to create a stack with example.com domain
  3. run yarn integ --update-on-failed
  4. confirm successful
  5. replace the test's domain back to example.com
  6. run yarn integ --update-on-failed --dry-run to recreate the snapshot including example.com domain

@TheRealAmazonKendra TheRealAmazonKendra added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Dec 7, 2022
@TheRealAmazonKendra
Copy link
Contributor

Is it acceptable to try following steps?

  1. replace existing test's domain from example.com to my private domain which is SES verified in us-east-1
  2. remove the old snapshot not to create a stack with example.com domain
  3. run yarn integ --update-on-failed
  4. confirm successful
  5. replace the test's domain back to example.com
  6. run yarn integ --update-on-failed --dry-run to recreate the snapshot including example.com domain

This is an excellent solution.

@TheRealAmazonKendra TheRealAmazonKendra removed the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Dec 7, 2022
@aws-cdk-automation aws-cdk-automation dismissed their stale review December 8, 2022 07:06

✅ Updated pull request passes all PRLinter validations. Dissmissing previous PRLinter review.

@Tietew
Copy link
Contributor Author

Tietew commented Dec 8, 2022

yarn integ --update-on-failed succeeded with my private domain.

screenshot 2022-12-08 160233

packages/@aws-cdk/aws-cognito/lib/user-pool-email.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-cognito/lib/user-pool-email.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-cognito/lib/user-pool-email.ts Outdated Show resolved Hide resolved
@corymhall corymhall self-assigned this Dec 14, 2022
@mergify mergify bot dismissed corymhall’s stale review December 16, 2022 04:13

Pull request has been modified.

@Tietew
Copy link
Contributor Author

Tietew commented Dec 16, 2022

@corymhall Thank you for review! I refactored them to separate functions and more explanations.

*
* @see https://www.rfc-editor.org/rfc/rfc5322#section-3.4
*/
function formatFromName(fromName: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks this is much easier to follow! The only question I have is how this
handles different types of quotes? Will it still work if you use " or ```

fromName: "'foo.bar'"
fromName: `'${someVar}'`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per RFC 5322, both the single quote ' and the backquote ` are "atext". They are same as alphabet/digit letters. But surprising, the dot . is a "specials".

   atext           =   ALPHA / DIGIT /    ; Printable US-ASCII
                       "!" / "#" /        ;  characters not including
                       "$" / "%" /        ;  specials.  Used for atoms.
                       "&" / "'" /
                       "*" / "+" /
                       "-" / "/" /
                       "=" / "?" /
                       "^" / "_" /
                       "`" / "{" /
                       "|" / "}" /
                       "~"

Note: White space is not defined as "atext", but also allowed.

Examples:

source template cause
"'foo.bar'" quoted-string
"From": "\"'foo.bar'\" <addr@example.com>"
the dot . is "specials"
"'foo bar'" bare
"From": "'foo bar' <addr@example.com>"
all chars are "atext"
"Foo's Bar" bare
"From": "Foo's Bar <addr@example.com>"
all chars are "atext"
'${price}' bare
"From": "${price} <addr@example.com>"
all chars are "atext"
"`foo bar`" bare
"From": "`foo bar` <addr@example.com>"
all chars are "atext"
'Café' mime encode
"From": "=?UTF-8?B?Q2Fmw6k=?= <addr@example.com>"
é is not US-ASCII
'"Café"' entire "Café" including double quote " is mime encoded
"From": "=?UTF-8?B?IkNhZsOpIg==?= <addr@example.com>"
é is not US-ASCII
`'${someVar}'` mime encode if someVar is not US-ASCII
quoted-string if someVar includes "specials"
otherwise, as-is
`~` is evaluated at runtime
single quote ' is atext
`"${someVar}"` mime encode if someVar is not US-ASCII
quoted-string again if someVar includes malformed escape
otherwise, as-is
already quoted-string form

@mergify
Copy link
Contributor

mergify bot commented Dec 19, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: f6ec3f3
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 78d474a into aws:main Dec 19, 2022
@mergify
Copy link
Contributor

mergify bot commented Dec 19, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@Tietew Tietew deleted the cognito-fromname-rfc5322 branch December 21, 2022 03:50
brennanho pushed a commit to brennanho/aws-cdk that referenced this pull request Jan 20, 2023
…#23227)

Closes aws#18903

When `fromName` of `UserPoolEmail.withSES()` does not comply RFC 5322 atom or quoted-string, it will be quoted or mime-encoded.

For example:
|`fromName`|Template|Description|
|-|-|-|
|`'simple atom'`|`"simple atom <address@example.com>"`|as is|
|`'"quoted string"'`|`"\"quoted string\" <address@example.com>"`|as is|
|`'あいう'`|`"=?UTF-8?B?44GC44GE44GG?= <address@example.com>"`|mime encode (RFC 2047)|
|`'name@company'`|`"\"name@company\" <address@example.com>"`|make quoted-string|

For details, see [RFC 5322 Section 3.4](https://www.rfc-editor.org/rfc/rfc5322#section-3.4) and [RFC 2047](https://www.rfc-editor.org/rfc/rfc2047)

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Construct Runtime Dependencies:

* [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
brennanho pushed a commit to brennanho/aws-cdk that referenced this pull request Feb 22, 2023
…#23227)

Closes aws#18903

When `fromName` of `UserPoolEmail.withSES()` does not comply RFC 5322 atom or quoted-string, it will be quoted or mime-encoded.

For example:
|`fromName`|Template|Description|
|-|-|-|
|`'simple atom'`|`"simple atom <address@example.com>"`|as is|
|`'"quoted string"'`|`"\"quoted string\" <address@example.com>"`|as is|
|`'あいう'`|`"=?UTF-8?B?44GC44GE44GG?= <address@example.com>"`|mime encode (RFC 2047)|
|`'name@company'`|`"\"name@company\" <address@example.com>"`|make quoted-string|

For details, see [RFC 5322 Section 3.4](https://www.rfc-editor.org/rfc/rfc5322#section-3.4) and [RFC 2047](https://www.rfc-editor.org/rfc/rfc2047)

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Construct Runtime Dependencies:

* [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p1 repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cognito/ses: "Provided From email address is invalid" when using email address for from_name
4 participants