Catalog npm
Back to packageRELEASE DETAILS

1.0.0-1

npm

@0xc/forward-cloudfront-proto

Express middleware to forward origin protocol headers through CloudFront

npmtypescript
Published16 Oct 2020
Direct dependencies12
Transitive dependenciesNot calculated

README

Current package documentation

forward-cloudfront-proto

When serving an Express server behind CloudFront, you might run into a case where your authentication cookies don't work and you want to blow your brains out because you have validated that everything is up to spec, and you've pored through MDN documentation, and you validated that you are setting cookies to secure for your new SameSite configuration but for the love of god it just won't work!

That sounds like me so far, what now?

Well if you managed to find this package, you may be going through something that our team already encountered. If you happen to have an architecture diagram that is a superset of the following:


+-----+      +----------------+     +-------------+     +----------------+
| WWW | -->  | Cloudfront CDN | --> | API Gateway | --> | Express Server |
+-----+      +----------------+     +-------------+     +----------------+

you just might want to use this. Or write it yourself. It's a very simple package. At the very least, I may propogate some SEO hit on Google that will give you a solution to end your suffering.

So what is this actually good for?

Cloudfront doesn't forward the original protocol using the standard X-Forwarded-Proto header. In fact, their forwarded protocol header needs to be enabled, and it's also a custom header called Cloudfront-Fowarded-Proto. So, make sure you update your Cloudfront configuration to forward this as well. You will need to include it in the whitelist for the request policy.

Enough talking, what do I do?

This is designed as a simple Express middleware you can include in your application. If your app is sitting behind Cloudfront and you have some Express server initialized as app already, include the following:

import { forwardCloudfrontProto } from "@0xc/forward-cloudfront-proto";

// ...

app.use(forwardCloudfrontProto);

And you're done! Express will now handle requests as it would have expected, identifying HTTPS requests as secure, allowing use of SameSite in Chrome, and more.

Many thanks to

Kindly, @beeme1mr, who did 99% of the work here to figure out the cause of the issue. I just packaged it for re-use.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 12

Native requirements
12 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
@types/express
Environment
{
  "local_name": "@types/express",
  "alias": false,
  "peer_metadata": null
}
^4.17.8development
@types/jest
Environment
{
  "local_name": "@types/jest",
  "alias": false,
  "peer_metadata": null
}
25.1.0development
@types/node
Environment
{
  "local_name": "@types/node",
  "alias": false,
  "peer_metadata": null
}
^12.12.27development
@typescript-eslint/eslint-plugin
Environment
{
  "local_name": "@typescript-eslint/eslint-plugin",
  "alias": false,
  "peer_metadata": null
}
^4.4.1development
@typescript-eslint/parser
Environment
{
  "local_name": "@typescript-eslint/parser",
  "alias": false,
  "peer_metadata": null
}
^4.4.1development
eslint
Environment
{
  "local_name": "eslint",
  "alias": false,
  "peer_metadata": null
}
^7.11.0development
jest
Environment
{
  "local_name": "jest",
  "alias": false,
  "peer_metadata": null
}
^25.1.0development
jest-junit
Environment
{
  "local_name": "jest-junit",
  "alias": false,
  "peer_metadata": null
}
^10.0.0development
nodemon
Environment
{
  "local_name": "nodemon",
  "alias": false,
  "peer_metadata": null
}
^2.0.2development
prettier
Environment
{
  "local_name": "prettier",
  "alias": false,
  "peer_metadata": null
}
^1.19.1development
ts-jest
Environment
{
  "local_name": "ts-jest",
  "alias": false,
  "peer_metadata": null
}
^25.0.0development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
^4.0.0development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-0UAOlRSNEjAINY3wrlWrxJfyIrpSdKlZWLKPsD/nhwJLdOjlerLwopZPlw/3Wtm0eItXkbznzTCuFSxDn0jpcQ==",
  "shasum": "6e112514875892e7046c534c514bc85e7a9406bf",
  "tarball": "https://registry.npmjs.org/@0xc/forward-cloudfront-proto/-/forward-cloudfront-proto-1.0.0-1.tgz",
  "fileCount": 5,
  "unpackedSize": 5243,
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfiRsvCRA9TVsSAnZWagAAHDkQAJGN3Jr6vMsR2oE8NneV\nHZnGwCS+RID5GTsK+2mKf++NuEyJS/CNB8MHEuRqAfJsgQKeccIpqAHH76Fy\nDyIdGSHFJlpgJArGpPCsLoDJmEDouXPIuZENo90BJgZdCeGASq1sYyKUgDNO\nHvXW5eymgdctoLjViMbear2Kzg67pTkO0uGQCJ2EG94qViN/RzvuUcL/KIgD\n+AiMG0izSuA0kw+sKbmondVDIAlLAVzaPY00Ow68ytRELiXu5XnIjzrWnrpC\nEtMmwo1xf6Wv0i6nan/IQMH/MMLFZBcIyO3iAAMIHfJ+hb0PZsjlxbzBOgMx\nfhtxqGDrgT6k39/puvrWcAwNclvyuqMsXBlowVddBOJ8tSIp3PAxNRGpLLr6\n8Cov4kGdBKr9garoZnJCYnPg8eFGiwDslunXfMSSUuRd5f7ivc+lycEXtJm9\nNvWLwfNn14A6olbHXfwksc7S0LGVyXvxgePUQrrWk8ihXO4jRNjgrmbT4Qir\n8Ga84fGw7YaTIdozeiMnUg7pZLkS5Dqd8z5/Nvhi0rktuuiiomAsqkUyy6xc\nFoPVK61T3i+iuCBwzUcJOQ1DWtMVRMZCTalVVHLkj2KBcijh1Q5UM6wmuujf\n82L1E8xbfORfe7m8B9/pWPPgChtDKtWOS1D0qDNN4x0PGt+K3weTQrrp0s0d\n+7To\r\n=2Qul\r\n-----END PGP SIGNATURE-----\r\n",
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEYCIQCwfcYMtUXmSpCHGh2i0Ai5dA2v5gI/PYtKFknoB64QJgIhAPN6zl12KWId2JMK2uq00GeMzubPYnudg+Gtga1vCOYt"
    }
  ]
}

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:44 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:f8e92ac97c59bf54286dcd01e2a5fd8677ff1cd1da5b563cdf03f8855b29e807

Other collected versions

View all collected versions →