Skip to content

Redact request bodies on the Edge runtime - #48

Draft
PetrHeinz wants to merge 2 commits into
mainfrom
claude/redact-other-realm
Draft

PetrHeinz wants to merge 2 commits into
mainfrom
claude/redact-other-realm

Conversation

@PetrHeinz

Copy link
Copy Markdown
Member

In 0.5.0 the redact option does not filter the request body in route handlers that run on the Edge runtime. With withBetterStack(handler, { logRequestDetails: true, redact: ['password'] }) the password in a JSON body is sent to Better Stack as is. Headers, cookies and log fields are filtered, and the Node.js runtime is not affected.

The body parsed by the Edge runtime is an object from another realm, so its prototype is not the Object.prototype the library compares against, and redact treated it as an opaque value instead of walking into it.

  • redact now treats an object as plain when its prototype is null or a root prototype, whatever realm it comes from. Dates, class instances and other non-plain values are still left alone.
  • Unit tests build objects from another realm with vm.
  • The end-to-end test posts a secret to two new example routes, /api/redact and /api/redact-edge, and asserts that no secret reaches the receiver on either runtime.

Found by running the end-to-end checks against @logtail/next@0.5.0 installed from npm. This deserves a 0.5.1.

The first commit adds the tests and the example routes, and is expected to fail CI in the unit tests and in every E2E leg; the second commit holds the change to redact.

🤖 Generated with Claude Code

PetrHeinz and others added 2 commits September 29, 2026 19:46
A request body parsed on the Edge runtime is an object from another
realm. Unit tests build one with vm, the end-to-end test posts a secret
to two new example routes, one per runtime.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
redact only recursed into objects whose prototype was the library's own
Object.prototype. A body parsed by the Edge runtime comes from another
realm, so it went out unfiltered. A plain object is now one whose
prototype is null or a root prototype.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant