Repository navigation
Description
User Story
I use OpenShell with provider profiles that put a credential in a request body (request_body_credential_rewrite: true), for a service whose sign-in takes the credential in the body. I need clients that compress their JSON request bodies (Content-Encoding: gzip) to keep the real credential out of the sandbox, or at least to get a clear refusal. The CLI I run signed in through such a profile on 0.1.9, so its sign-in body is not compressed; I measured compressing clients with curl in a sandbox on 0.1.10 (below): the request is dropped without a response, or it reaches the service with the placeholder unresolved. This affects any client that compresses its request bodies and sends its credential in the body to an endpoint with request_body_credential_rewrite: true.
Problem Statement
With request_body_credential_rewrite: true on a REST endpoint, OpenShell 0.1.10 never reads the request's Content-Encoding. It buffers the body (at most 256 KiB) and substitutes a placeholder only when the Content-Type is application/json, application/x-www-form-urlencoded or text/* and the whole body is valid UTF-8 (collect_and_rewrite_request_body and rewrite_buffered_body in crates/openshell-supervisor-network/src/l7/rest.rs). A gzip or deflate body is not valid UTF-8. Measured over plain HTTP with curl in a sandbox:
- Under those content types the request is refused before anything reaches the upstream, whether or not the compressed body holds a placeholder. The client connection closes with no HTTP response (
curl: (52) Empty reply from server); the log shows the L7 decisionALLOWEDfollowed byNET:FAIL [LOW]with no reason, anddenied_action_countstays 0. Every compressed JSON, form or text request to the endpoint fails this way. - Under any other
Content-Type, or none, the compressed body is forwarded unchanged with the placeholder still inside the compressed stream: the client gets the upstream's response, the upstream receives an unresolved placeholder, and nothing in the log says so. A body whose bytes show the placeholder text, such as gzip with stored blocks, is refused as in the first bullet. - A body over 256 KiB is refused the same way as in the first bullet (measured uncompressed: 262,049 bytes rewritten, 262,249 and 300,149 bytes dropped).
With the flag off, compressed bodies are forwarded unchanged. In every compressed request that reached the upstream, the real credential was absent from both the raw and the decompressed bytes: no leak was observed, only a dropped request or an unresolved placeholder.
Impact / Why This Matters
A user whose client compresses sees a dropped connection or an authentication error, with no explanation in the default log line, and must then pass the real credential into the sandbox environment, which defeats credential isolation, or switch client. OpenShell already refuses a non-identity Content-Encoding explicitly elsewhere: the agent trace relay answers 415, and a GraphQL endpoint records a denial with the reason (reject_unsupported_headers in l7/graphql.rs). The REST rewrite path has no such check; its refusal appears only as a bare NET:FAIL line.
Proposed Design
Two steps, which can land separately.
- Refuse explicitly. On an endpoint with
request_body_credential_rewrite: true, a request whoseContent-Encodingis not identity, or whose body the rewrite cannot read, gets an HTTP error response and a denial event that states the reason and counts indenied_action_count, as other refused requests do, instead of a closed connection. This includes requests under content types that are forwarded today with the placeholder still compressed. - Rewrite inside
gzipanddeflatebodies. The upstream receives the credential in place of the placeholder, with aContent-EncodingandContent-Lengththat match the forwarded body; decoding is bounded by a size limit.br,zstd, stacked codings and decoded bodies over the limit are refused with a reason, as in step 1.
Notional endpoint:
endpoints:
- host: api.example.com
port: 443
path: /auth/login
protocol: rest
enforcement: enforce
rules:
- allow: { method: POST, path: /auth/login }
request_body_credential_rewrite: true # step 2: also for gzip and deflate bodiesAcceptance Criteria
- A compressed request to an endpoint with
request_body_credential_rewrite: truenever ends in a connection closed without a response: it is either rewritten and forwarded, or refused with an HTTP error and a denial reason in the OCSF event. - After step 2, a gzip request and a deflate request that contain a placeholder reach the upstream with the credential substituted, and with a valid
Content-EncodingandContent-Length. - An unsupported encoding and a compressed body over the limit are refused with a reason, never forwarded.
- The decoded body and the credential never appear in logs or events.
- Uncompressed bodies, and endpoints without
request_body_credential_rewrite, behave as today.
Alternatives Considered
- Supervisor middleware (RFC 0009) can deny an encoded request with a reason code, which covers step 1, but it cannot do step 2: an encoded request gets no body modes, content-coding headers are protected, and credentials are injected after middleware runs. Step 1 still belongs in the rewrite path, because the failure comes from the endpoint's own flag and appears with no middleware registered. Gateway interceptors (RFC 0010) govern control-plane calls, not egress bodies.
- Not every client can be configured not to compress.
- A header-borne credential (bearer) avoids the problem, but some clients send the credential only in a body; the profile docs mention OAuth tokens sent in request bodies.
Agent Investigation
Measured on OpenShell 0.1.10 with a test profile and a local test server, reached from a sandbox with curl: uncompressed, gzip, deflate, gzip with stored blocks and chunked gzip bodies; uncompressed JSON with a false Content-Encoding: gzip header; an uncompressed body with one invalid UTF-8 byte; JSON, form, text and other content types (including none); and the flag on and off. The published reference for the flag (docs/how-it-works/policies/schema.mdx) says only that rewriting applies to "UTF-8 JSON, form, and text bodies of up to 256 KiB"; the middleware and trace-relay docs do describe encoded requests. Not measured: compressed bodies over 256 KiB, br and zstd, and the TLS-terminated HTTPS path. Related: #4671 (a refusal that closes the connection instead of answering), #5132 (delivering a refusal while the client is still uploading, relevant to bodies over the limit), #6067 (an example profile that uses request_body_credential_rewrite).
Checklist
- I've reviewed existing issues and the published docs
- This is a design proposal, not a "please build this" request
Activity