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

Pkg: httpHeaderNormalizer to handle canonical sanitized headers #1185

Conversation

ScoobySmack2612
Copy link
Contributor

@ScoobySmack2612 ScoobySmack2612 commented Mar 1, 2024

Given canonical: true,
And an event containing a header that's "sanitized" (X----)
A runtime error occurs, "Cannot read property 'toUpperCase' of undefined".

To Reproduce:

Unit test

test('It should not fail given a corrupted header key', async (t) => {
  const handler = middy((event, context) => event)

  handler.use(httpHeaderNormalizer({ canonical: true }))

  const event = {
    headers: {
      'X----': 'foo'
    }
  }

  const expectedHeaders = {
    'X----': 'foo'
  }

  const originalHeaders = { ...event.headers }

  const resultingEvent = await handler(event, context)

  t.deepEqual(resultingEvent.headers, expectedHeaders)
  t.deepEqual(resultingEvent.rawHeaders, originalHeaders)
})

Thrown error: "Cannot read property 'toUpperCase' of undefined".

Expected behavior: Should simply return the raw header

Additional context:
We had a client who appears to be sanitizing headers resulting in our lambdas receiving a header that looks like X----. Though this is a one-off, rather than push the onus to our client, an empty string fallback gets them back up an running.


t.deepEqual(resultingEvent.headers, expectedHeaders)
t.deepEqual(resultingEvent.rawHeaders, originalHeaders)
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was added to the wrong file. Can you do a quick update please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, sorry about that.

@willfarrell
Copy link
Member

X---- header? Can say I've never seen that before. I would still tell the client to update X---- to something more standard. Thanks for the PR and quick update.

@willfarrell willfarrell merged commit e886e2d into middyjs:main Mar 2, 2024
8 checks passed
@ScoobySmack2612
Copy link
Contributor Author

ScoobySmack2612 commented Mar 2, 2024

X---- header? Can say I've never seen that before. I would still tell the client to update X---- to something more standard. Thanks for the PR and quick update.

Its definitely not, I suspect they have just enough of a proxy configuration to get themselves in trouble. I suspect they're stripping unknown headers, or something similar. Thanks for a speedy review!

mergify bot pushed a commit to SvenKirschbaum/share.kirschbaum.cloud that referenced this pull request Mar 3, 2024
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@middy/core](https://middy.js.org) ([source](https://togithub.com/middyjs/middy/tree/HEAD/packages/core)) | [`5.2.4` -> `5.2.6`](https://renovatebot.com/diffs/npm/@middy%2fcore/5.2.4/5.2.6) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@middy%2fcore/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@middy%2fcore/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@middy%2fcore/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@middy%2fcore/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) |
| [@middy/error-logger](https://middy.js.org) ([source](https://togithub.com/middyjs/middy/tree/HEAD/packages/error-logger)) | [`5.2.4` -> `5.2.6`](https://renovatebot.com/diffs/npm/@middy%2ferror-logger/5.2.4/5.2.6) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@middy%2ferror-logger/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@middy%2ferror-logger/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@middy%2ferror-logger/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@middy%2ferror-logger/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) |
| [@middy/http-content-negotiation](https://middy.js.org) ([source](https://togithub.com/middyjs/middy/tree/HEAD/packages/http-content-negotiation)) | [`5.2.4` -> `5.2.6`](https://renovatebot.com/diffs/npm/@middy%2fhttp-content-negotiation/5.2.4/5.2.6) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@middy%2fhttp-content-negotiation/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@middy%2fhttp-content-negotiation/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@middy%2fhttp-content-negotiation/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@middy%2fhttp-content-negotiation/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) |
| [@middy/http-error-handler](https://middy.js.org) ([source](https://togithub.com/middyjs/middy/tree/HEAD/packages/http-error-handler)) | [`5.2.4` -> `5.2.6`](https://renovatebot.com/diffs/npm/@middy%2fhttp-error-handler/5.2.4/5.2.6) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@middy%2fhttp-error-handler/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@middy%2fhttp-error-handler/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@middy%2fhttp-error-handler/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@middy%2fhttp-error-handler/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) |
| [@middy/http-header-normalizer](https://middy.js.org) ([source](https://togithub.com/middyjs/middy/tree/HEAD/packages/http-header-normalizer)) | [`5.2.4` -> `5.2.6`](https://renovatebot.com/diffs/npm/@middy%2fhttp-header-normalizer/5.2.4/5.2.6) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@middy%2fhttp-header-normalizer/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@middy%2fhttp-header-normalizer/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@middy%2fhttp-header-normalizer/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@middy%2fhttp-header-normalizer/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) |
| [@middy/http-json-body-parser](https://middy.js.org) ([source](https://togithub.com/middyjs/middy/tree/HEAD/packages/http-json-body-parser)) | [`5.2.4` -> `5.2.6`](https://renovatebot.com/diffs/npm/@middy%2fhttp-json-body-parser/5.2.4/5.2.6) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@middy%2fhttp-json-body-parser/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@middy%2fhttp-json-body-parser/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@middy%2fhttp-json-body-parser/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@middy%2fhttp-json-body-parser/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) |
| [@middy/http-response-serializer](https://middy.js.org) ([source](https://togithub.com/middyjs/middy/tree/HEAD/packages/http-response-serializer)) | [`5.2.4` -> `5.2.6`](https://renovatebot.com/diffs/npm/@middy%2fhttp-response-serializer/5.2.4/5.2.6) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@middy%2fhttp-response-serializer/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@middy%2fhttp-response-serializer/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@middy%2fhttp-response-serializer/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@middy%2fhttp-response-serializer/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) |
| [@middy/validator](https://middy.js.org) ([source](https://togithub.com/middyjs/middy/tree/HEAD/packages/validator)) | [`5.2.4` -> `5.2.6`](https://renovatebot.com/diffs/npm/@middy%2fvalidator/5.2.4/5.2.6) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@middy%2fvalidator/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@middy%2fvalidator/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@middy%2fvalidator/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@middy%2fvalidator/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>middyjs/middy (@&#8203;middy/core)</summary>

### [`v5.2.6`](https://togithub.com/middyjs/middy/releases/tag/5.2.6)

[Compare Source](https://togithub.com/middyjs/middy/compare/5.2.4...5.2.6)

##### What's Changed

-   Pkg: httpHeaderNormalizer to handle canonical sanitized headers by [@&#8203;ScoobySmack2612](https://togithub.com/ScoobySmack2612) in [middyjs/middy#1185

##### New Contributors

-   [@&#8203;ScoobySmack2612](https://togithub.com/ScoobySmack2612) made their first contribution in [middyjs/middy#1185

**Full Changelog**: middyjs/middy@5.2.5...5.2.6

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 5am on sunday" (UTC), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/SvenKirschbaum/share.kirschbaum.cloud).
mergify bot pushed a commit to SvenKirschbaum/aws-utils that referenced this pull request Mar 3, 2024
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@middy/core](https://middy.js.org) ([source](https://togithub.com/middyjs/middy/tree/HEAD/packages/core)) | [`5.2.4` -> `5.2.6`](https://renovatebot.com/diffs/npm/@middy%2fcore/5.2.4/5.2.6) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@middy%2fcore/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@middy%2fcore/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@middy%2fcore/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@middy%2fcore/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) |
| [@middy/error-logger](https://middy.js.org) ([source](https://togithub.com/middyjs/middy/tree/HEAD/packages/error-logger)) | [`5.2.4` -> `5.2.6`](https://renovatebot.com/diffs/npm/@middy%2ferror-logger/5.2.4/5.2.6) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@middy%2ferror-logger/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@middy%2ferror-logger/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@middy%2ferror-logger/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@middy%2ferror-logger/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) |
| [@middy/http-error-handler](https://middy.js.org) ([source](https://togithub.com/middyjs/middy/tree/HEAD/packages/http-error-handler)) | [`5.2.4` -> `5.2.6`](https://renovatebot.com/diffs/npm/@middy%2fhttp-error-handler/5.2.4/5.2.6) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@middy%2fhttp-error-handler/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@middy%2fhttp-error-handler/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@middy%2fhttp-error-handler/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@middy%2fhttp-error-handler/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) |
| [@middy/http-header-normalizer](https://middy.js.org) ([source](https://togithub.com/middyjs/middy/tree/HEAD/packages/http-header-normalizer)) | [`5.2.4` -> `5.2.6`](https://renovatebot.com/diffs/npm/@middy%2fhttp-header-normalizer/5.2.4/5.2.6) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@middy%2fhttp-header-normalizer/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@middy%2fhttp-header-normalizer/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@middy%2fhttp-header-normalizer/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@middy%2fhttp-header-normalizer/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) |
| [@middy/http-response-serializer](https://middy.js.org) ([source](https://togithub.com/middyjs/middy/tree/HEAD/packages/http-response-serializer)) | [`5.2.4` -> `5.2.6`](https://renovatebot.com/diffs/npm/@middy%2fhttp-response-serializer/5.2.4/5.2.6) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@middy%2fhttp-response-serializer/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@middy%2fhttp-response-serializer/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@middy%2fhttp-response-serializer/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@middy%2fhttp-response-serializer/5.2.4/5.2.6?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>middyjs/middy (@&#8203;middy/core)</summary>

### [`v5.2.6`](https://togithub.com/middyjs/middy/releases/tag/5.2.6)

[Compare Source](https://togithub.com/middyjs/middy/compare/5.2.4...5.2.6)

##### What's Changed

-   Pkg: httpHeaderNormalizer to handle canonical sanitized headers by [@&#8203;ScoobySmack2612](https://togithub.com/ScoobySmack2612) in [middyjs/middy#1185

##### New Contributors

-   [@&#8203;ScoobySmack2612](https://togithub.com/ScoobySmack2612) made their first contribution in [middyjs/middy#1185

**Full Changelog**: middyjs/middy@5.2.5...5.2.6

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "on sunday" in timezone Europe/Berlin, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/SvenKirschbaum/aws-utils).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants