fix(router): remove originAccessControlConfig for HTTP origins to prevent 502#6743
Open
turisanapo wants to merge 1 commit intoanomalyco:devfrom
Open
fix(router): remove originAccessControlConfig for HTTP origins to prevent 502#6743turisanapo wants to merge 1 commit intoanomalyco:devfrom
turisanapo wants to merge 1 commit intoanomalyco:devfrom
Conversation
Author
|
This fix is insufficient — we validated that just deleting both The correct fix is to replace if (override.protocol === "http") {
- delete origin.customOriginConfig;
+ origin.customOriginConfig = { port: 80, protocol: "http", sslProtocols: ["TLSv1.2"] };
+ delete origin.originAccessControlConfig;
}See the updated analysis in #6742. |
… prevent 502
When `override.protocol === "http"`, the CloudFront Function's `setUrlOrigin`
previously deleted `customOriginConfig` expecting `cf.updateRequestOrigin` to
inherit the placeholder origin's http-only settings. However, the remaining
`originAccessControlConfig: { enabled: false }` prevents this inheritance,
and simply deleting both properties also fails — CloudFront does not reliably
inherit `customOriginConfig` when dynamically switching origins.
The fix explicitly sets `customOriginConfig` to HTTP port 80 and removes the
unused `originAccessControlConfig`. The `override.originAccessControlConfig`
check below still allows OAC-enabled origins to re-add it when needed.
Fixes anomalyco#6742
Made-with: Cursor
64eec9f to
bd9e155
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
router.route("/", "http://<alb-dns>")returns 502 "Failed to contact the origin" because CloudFront tries HTTPS:443 instead of HTTP:80.Root cause
In
setUrlOrigin, whenoverride.protocol === "http", onlycustomOriginConfigis deleted — the expectation being thatcf.updateRequestOrigininherits the placeholder origin'shttp-onlyconfig.However:
originAccessControlConfig: { enabled: false }prevents this inheritancecf.updateRequestOrigindoes not reliably inheritcustomOriginConfigfrom the placeholder origin when thedomainNamechanges dynamicallyFix
Explicitly set
customOriginConfigto HTTP port 80 for HTTP origins, and remove the unusedoriginAccessControlConfig:if (override.protocol === "http") { - delete origin.customOriginConfig; + origin.customOriginConfig = { port: 80, protocol: "http", sslProtocols: ["TLSv1.2"] }; + delete origin.originAccessControlConfig; }The
override.originAccessControlConfigcheck below still allows OAC-enabled origins (protection: "oac") to re-add it explicitly, so existing behavior is preserved.Validation
Tested by deploying a CloudFront Function that calls
cf.updateRequestOriginwith explicit HTTPcustomOriginConfig— confirmed 200 responses through CloudFront to an HTTP-only ALB. Verified thecfmodule is completely frozen in CloudFront Functions runtime (writable: false, configurable: false), so runtime workarounds via injection are not possible.Fixes #6742