【问题标题】:S3 CloudFront React SPA returns 403 due to hashtag but cannot setup 403 error page由于主题标签,S3 CloudFront React SPA 返回 403 但无法设置 403 错误页面
【发布时间】:2019-01-28 03:07:28
【问题描述】:

不幸的是,Auth0 在回调 URL 中为单页样式应用程序添加了一个标签。请参阅下面的示例。

https://stage.domain.com/callback#access_token=...&otherQueryParam=...

这会在我的 S3 和 Cloudfront 环境中返回 403 错误。

<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>...</RequestId>
<HostId>
...
</HostId>
</Error>

我在互联网上看到的解决方案涉及在 CloudFront 中创建额外的自定义错误句柄配置,以将任何 403 错误重定向到 200 并呈现 index.html。

但是,我不能这样做,因为 staging 环境只能通过 VPN 访问 并且有一个 WAF 规则 阻止除 VPN 之外的所有 IP 地址。如果我允许 403,它将使 WAF 规则无用并公开暴露我的暂存环境。

希望我的 React SPA 托管在 S3 中以便于扩展,但是看起来我可能需要启动某种运行 Nginx 的 EC2。

存储桶政策

{
    "Version": "2008-10-17",
    "Id": "PolicyForCloudFrontPrivateContent",
    "Statement": [
        {
            "Sid": "1",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity ..."
            },
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::stage.domain.com/*"
        }
    ]
}

对这个问题有哪些建议的解决方案?

【问题讨论】:

  • 你找到解决办法了吗?

标签: reactjs amazon-s3 amazon-cloudfront auth0 amazon-waf


【解决方案1】:

我有类似的设置,

- WAF only allows access from a set of whitelisted IPs
- CloudFront Serves React Site from S3
- CloudFront Custom error response redirects 403 -> 200 and renders index.html

任何请求网页的白名单之外的 IP 都会收到 200 响应,但应用不呈现,只显示白页。

我同意,任何未列入白名单的 IP 都无法获得任何访问权限,但现在它可以正常工作,直到我找到更好的解决方案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-22
    • 2011-10-24
    • 2021-05-24
    • 2021-06-17
    • 2014-03-11
    • 1970-01-01
    • 2019-05-22
    相关资源
    最近更新 更多