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

set: Type-validates the forbidden "cookie"/"set-cookie" response headers #819

Merged
merged 1 commit into from
Jul 23, 2021

Conversation

kettanaito
Copy link
Member

@kettanaito kettanaito commented Jul 19, 2021

GitHub

Changes

  • Setting forbidden cookie headers with the ctx.set utility now produces a TypeScript violation.
  • Forbidden cookie headers include (case-insensitive):
    • cookie
    • cookie2
    • set-cookie
    • set-cookie2

We are not including all forbidden header names for now, starting with the cookie ones.

Motivation

We should fail fast in preventing the developer from setting forbidden response cookies. Setting such cookies will raise a runtime exception anyway.

Experience

set({ cookie: 'secret' })

// Argument of type '[{ cookie: string; }]' is not assignable to parameter of type
// '"SafeResponseHeader: the 'cookie' header cannot be set on the response. Please use the 'ctx.cookie()' function instead."'.ts(2345)

Utilizes this technique to have custom type violation messages until microsoft/TypeScript#40468 is merged.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 19, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 5ce843f:

Sandbox Source
MSW React Configuration

@kettanaito
Copy link
Member Author

The smoke tests are failing due to the old TypeScript version being used in the usage examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant