mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-11-21 15:05:56 +00:00
fix(security): drop the cookie header from plugin hook contexts too
The dashboard session token travels in a cookie, so it is a client credential like authorization and x-api-key.
This commit is contained in:
@@ -269,8 +269,8 @@ silently falls back to the built-in seed registry and logs a warning.
|
||||
opt-in tamper-detection, **not** a security boundary: it does not limit what
|
||||
a loaded plugin can do.
|
||||
- **No client credentials in hooks** — the context passed to `onRequest`,
|
||||
`onResponse` and `onError` has the `authorization`, `x-api-key` and
|
||||
`proxy-authorization` headers removed, and the API key record carries no key
|
||||
`onResponse` and `onError` has the `authorization`, `x-api-key`,
|
||||
`proxy-authorization` and `cookie` headers removed, and the API key record carries no key
|
||||
value (`redactPluginContext()` in `src/lib/plugins/hooks.ts`).
|
||||
|
||||
## Manifest (`plugin.json`)
|
||||
|
||||
@@ -87,8 +87,8 @@ onRequest: (ctx) => {
|
||||
| `timestamp` | `number` | Request timestamp |
|
||||
| `apiKeyInfo` | `object` (optional) | API key metadata (see note) |
|
||||
|
||||
The context never carries the client's credentials: the `authorization`, `x-api-key` and
|
||||
`proxy-authorization` headers are removed (any casing), and `apiKeyInfo` keeps the key's
|
||||
The context never carries the client's credentials: the `authorization`, `x-api-key`,
|
||||
`proxy-authorization` and `cookie` headers are removed (any casing), and `apiKeyInfo` keeps the key's
|
||||
metadata (such as `id`, `name` and `scopes`) but not the key value or its fingerprint
|
||||
(`redactPluginContext()` in `src/lib/plugins/hooks.ts`). This applies to `onRequest`,
|
||||
`onResponse` and `onError`.
|
||||
|
||||
@@ -246,6 +246,8 @@ const CREDENTIAL_HEADER_NAMES: ReadonlySet<string> = new Set([
|
||||
"authorization",
|
||||
"x-api-key",
|
||||
"proxy-authorization",
|
||||
// The dashboard session token travels in a cookie.
|
||||
"cookie",
|
||||
]);
|
||||
|
||||
/** API key record fields that carry the key itself or a fingerprint of it. */
|
||||
@@ -260,7 +262,7 @@ function omitFields(
|
||||
|
||||
/**
|
||||
* Copy of a hook context without the client's credentials: drops the `authorization`,
|
||||
* `x-api-key` and `proxy-authorization` headers (any casing) and the key value/fingerprint
|
||||
* `x-api-key`, `proxy-authorization` and `cookie` headers (any casing) and the key value/fingerprint
|
||||
* from the API key record. The input is never mutated.
|
||||
*/
|
||||
function redactPluginContext<T extends PluginContext>(ctx: T): T {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Plugin hooks must not receive the client's credentials. A plugin is third-party code
|
||||
// running as a plain Node child process, so whatever the hook context carries is fully
|
||||
// readable by it. The request headers handed to onRequest/onResponse/onError must not
|
||||
// include `authorization`, `x-api-key` or `proxy-authorization` (any casing), and the
|
||||
// include `authorization`, `x-api-key`, `proxy-authorization` or `cookie` (any casing), and the
|
||||
// API key record must not carry the key itself — only its id/name/scopes-style metadata.
|
||||
import { test, afterEach } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
@@ -16,13 +16,14 @@ const { runPluginOnRequestHook } =
|
||||
const { loadPlugin } = await import("../../src/lib/plugins/loader.ts");
|
||||
|
||||
const SECRET = "sk-client-secret-value-0001";
|
||||
const CREDENTIAL_HEADERS = ["authorization", "x-api-key", "proxy-authorization"];
|
||||
const CREDENTIAL_HEADERS = ["authorization", "x-api-key", "proxy-authorization", "cookie"];
|
||||
|
||||
function clientHeaders(): Record<string, string> {
|
||||
return {
|
||||
Authorization: `Bearer ${SECRET}`,
|
||||
"X-Api-Key": SECRET,
|
||||
"proxy-authorization": `Basic ${SECRET}`,
|
||||
Cookie: `auth_token=${SECRET}; theme=dark`,
|
||||
"x-trace-id": "trace-123",
|
||||
"content-type": "application/json",
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user