Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eager-lizards-stand.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@solana/rpc-transport-http': minor
---

The React Native and Node builds now permit you to set the `Origin` header. This header continues to be forbidden in the browser build, as it features on the list of forbidden request headers: https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_request_header
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ describe('assertIsAllowedHttpRequestHeader', () => {
'Expect',
'Host',
'Keep-Alive',
'Origin',
'Permissions-Policy',
'Proxy-Anything',
'Proxy-Authenticate',
Expand Down Expand Up @@ -64,6 +63,17 @@ describe('assertIsAllowedHttpRequestHeader', () => {
);
});
}
if (__BROWSER__) {
it('throws when called with the `Origin` header', () => {
expect(() => {
assertIsAllowedHttpRequestHeaders({ Origin: 'https://spoofed.site' });
}).toThrow(
new SolanaError(SOLANA_ERROR__RPC__TRANSPORT_HTTP_HEADER_FORBIDDEN, {
headers: ['Origin'],
}),
);
});
}
['Authorization', 'Content-Language', 'Solana-Client'].forEach(allowedHeader => {
it('does not throw when called with the header `' + allowedHeader + '`', () => {
expect(() => {
Expand Down
7 changes: 5 additions & 2 deletions packages/rpc-transport-http/src/http-transport-headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ type ForbiddenHeaders =
| 'Expect'
| 'Host'
| 'Keep-Alive'
| 'Origin'
// Similar to `Accept-Encoding`, we don't have a way to target TypeScript types depending on
// which platform you are authoring for. `Origin` is therefore omitted from the forbidden
// headers type, but is still a runtime error in dev mode when supplied in a browser context.
// | 'Origin'
| 'Permissions-Policy'
| 'Referer'
| 'TE'
Expand Down Expand Up @@ -64,7 +67,6 @@ const FORBIDDEN_HEADERS: Record<string, boolean> = /* @__PURE__ */ Object.assign
expect: true,
host: true,
'keep-alive': true,
origin: true,
'permissions-policy': true,
// Prefix matching is implemented in code, below.
// 'proxy-': true,
Expand All @@ -77,6 +79,7 @@ const FORBIDDEN_HEADERS: Record<string, boolean> = /* @__PURE__ */ Object.assign
via: true,
},
__NODEJS__ ? undefined : { 'accept-encoding': true },
__BROWSER__ ? { origin: true } : undefined,
);

export function assertIsAllowedHttpRequestHeaders(
Expand Down
Loading