Skip to content

feat(pro-327): forward client IP to origin via clientIpHeader KVS entry - #5

Open
alistairsmith-tech wants to merge 1 commit into
mainfrom
feat/pro-327
Open

feat(pro-327): forward client IP to origin via clientIpHeader KVS entry#5
alistairsmith-tech wants to merge 1 commit into
mainfrom
feat/pro-327

Conversation

@alistairsmith-tech

Copy link
Copy Markdown
Collaborator

Summary

Plugin half of the SFCC client-IP header feature (PRO-327, part of the PRO-316 stacked-CDN work; the web deploy flow already writes a clientIpHeader KVS entry that the current function ignores).

  • The viewer-request function reads clientIpHeader from the KVS right after acquiring the handle and, when present, stamps event.viewer.ip under that (lowercased) header name on the request object, so every origin-bound pass-through path carries it: valid-cookie, unprotected-path, no-cookie-secret fail-open, and the outer fail-open catch (the stamp happens before anything that can throw). The /__mcl/verify return deliberately precedes it: that behavior is answered by the Lambda and never reaches the origin.
  • Anti-spoofing invariant: always overwritten, removed when no viewer IP is available; an inbound client-supplied value can never reach the origin. No behavior change when the entry is absent.
  • Byte budget: stripped artifact is 10,043 of 10,240 bytes (~200 headroom); build.mjs enforces the cap and passes.

Tests

Five new cases: overwrite of a forged value on the valid-cookie path, stamping on the unprotected-path and no-secret fail-open paths, removal when no viewer IP is available, and untouched headers when the entry is absent. Full suite: 55/55 passing. (Pre-existing strip.mjs TS7016 on main is untouched.)

Release notes

After merge: tag a release, bump MONOCLE_CLOUDFRONT_PLUGIN_VERSION in web, redeploy SFCC apps (function republish + distribution propagation takes minutes per app).

🤖 Generated with Claude Code

When the clientIpHeader KVS entry is set (written by the web deploy flow),
the viewer-request function stamps event.viewer.ip under that header name
immediately after acquiring the KVS handle, so every origin-bound
pass-through path (valid cookie, unprotected path, no-secret fail-open, and
the outer catch) carries it. Edge trust boundary: always overwritten, and
removed when no viewer IP is available, so an inbound client-supplied value
can never reach the origin as a spoofed identity. No behavior change when
the entry is absent. Stripped artifact: 10043 of 10240 bytes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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

Successfully merging this pull request may close these issues.

1 participant