awslabs / cognito-at-edge

Serverless authentication solution to protect your website or Amplify application
Apache License 2.0
168 stars 54 forks source link

Incorrect Regex of idToken With Subdomains #43

Closed ckifer closed 1 year ago

ckifer commented 1 year ago

What happened:

Upon visiting beta.myurl.com cognito-at-edge uses the cookie from myurl.com as opposed to beta.myurl.com. They are both sent, but according to this Regex it should only parse the idToken from that of the initialized "_userPoolAppId". From my tests this doesn't seem to be the case.

This causes an infinite loop and eventual 503 on Viewer Request.

What did you expect to have happen:

The Regex correctly parses cookies even if there are multiple on the same domain of the form userPoolAppId}\..+?\.idToken=(.*?)(?:;|$)

How to reproduce this (as precisely and succinctly as possible):

Deploy cognito-at-edge to a lambda@edge function with cloudfront distro served at url of the form: beta.myurl.com Deploy the same setup to myurl.com making sure cookies are set from both.

Anything else you think we should know?

Environment:

Here is a contrived example with the structure that my cookies get set and sent to Lambda@edge with:

Edit hungry-lalande-loeuce

As you can see the regex is incorrect. The order of the cookies shouldn't matter.

Regex test https://regex101.com/r/GdVCo6/1

Working Regex (needs tested more): https://regex101.com/r/vQSdRa/1 Edit: this working regex breaks the case of a username with a . character

ckifer commented 1 year ago

fixed in latest release #49 - closing