Skip to content

Add public method to bypass Zen for a request - #1128

Open
timokoessler wants to merge 2 commits into
mainfrom
expose-bypass-request-function
Open

Add public method to bypass Zen for a request#1128
timokoessler wants to merge 2 commits into
mainfrom
expose-bypass-request-function

Conversation

@timokoessler

Copy link
Copy Markdown
Member

No description provided.

Comment thread library/agent/Context.ts
return;
}

context.bypassRequest = true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium - Request bypass state escapes the request and disables protection in background async work

bypassRequest() stores the bypass flag on the shared AsyncLocalStorage request context, so every async resource created during that request inherits the flag as well. runWithContext does not clear that state when the HTTP response finishes, and the existing context tests show timers keep the request context after the handler returns. As a result, queued work such as setTimeout, promise continuations, or post-response tasks spawned from a bypassed request will also skip Zen's blocking and detection logic, extending the bypass far beyond the single request the API claims to affect.

Show fix

Scope bypassing to an explicit callback or clear the bypass state when the response lifecycle ends, so detached async work does not inherit it. If background work must be supported, use a separate AsyncLocalStorage scope for withBypassedProtection(fn) instead of persisting the flag on the request context object.

More info - Reply on this comment to give feedback or ignore the issue.

@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
library/sources/FunctionsFramework.ts 0.00% 1 Missing ⚠️
library/sources/Lambda.ts 0.00% 1 Missing ⚠️
.../sources/http-server/http2/createStreamListener.ts 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Comment thread docs/bypassRequest.md Outdated
// ...
```

Please use this feature with caution, as it can potentially expose your application to security risks if not used properly.

@hansott hansott Aug 14, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use github warning? to make this a bit more screamy?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added 278897f

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.

3 participants