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

url redirect adding multiple path #37

Open
imti283 opened this issue Oct 30, 2023 · 1 comment
Open

url redirect adding multiple path #37

imti283 opened this issue Oct 30, 2023 · 1 comment

Comments

@imti283
Copy link

imti283 commented Oct 30, 2023

I have this simple function to route traffic equally to two APIGW as origin. I see few requests works but after that it starts giving me 403. Looks this function is adding same literal multiple times or in some way function cache is messing it up.

function handler(event) {
    var randomnumber = Math.floor(Math.random() * 100)
    if (randomnumber < 50) {
        var reg = 'east'
        console.log({
            statusCode: 302,
            statusDescription: 'Found',
            headers: {
                "location": {
                    "value": `https://${event.request.headers.host.value}//${reg}${event.request.uri}`
                }
            }
        })
        return {
            statusCode: 302,
            statusDescription: 'Found',
            headers: {
                "location": {
                    "value": `https://${event.request.headers.host.value}//${reg}${event.request.uri}`
                }
            }
        };
    }
    return event.request
}

Correct redirect url would be something like this -
https://XXXXXXXXXX.cloudfront.net//east/p1/p2/p3/p4

But when it gives 403 and i check function log, i see these as return - (essentially "east" multiple times in path, which explains why i am getting 403). But I am unable to figure out what i am doing wrong. This function is associated with distribution as "Viewer request".
https://XXXXXXXXXX.cloudfront.net//east//east/p1/p2/p3/p4
https://XXXXXXXXXX.cloudfront.net//east//east//east/p1/p2/p3/p4

@stschulte
Copy link

From your code I assume the redirect is pointing to the the same CloudFront distribution. This means you can be redirected many times, e.g.:

  1. request: XX.cloudfront.net/foo ==> 50% chance of being redirected to XX.cloudfront.net/east/foo
  2. request: XX.cloudfront.net/east/foo ==> 50% chance of being redirected to XX.cloudfront.net/east/east/foo
  3. request: XX.cloudfront.net/east/east/foo => 50% chance of no redirect => origin request of /east/east/foo returns 403 and is returned to viewer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants