fix(wasm): run leak scan on pre-injection headers in channel callbacks - #1377
ilblackdragon merged 5 commits into
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue where the leak detector in WASM channel HTTP callbacks would incorrectly flag host-injected credentials as potential leaks. By adjusting the timing of the leak scan to occur on the raw, pre-injection headers, the change ensures that only WASM-provided values are checked, thereby eliminating false positives and allowing legitimate channel callbacks to function correctly. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request addresses a potential security vulnerability in the WASM channel wrapper by ensuring that the leak detector scans the original WASM-provided headers before any credential injection occurs. This prevents false positives caused by host-injected credentials triggering the leak detector. The changes involve modifying the http_request function to extract and scan the raw headers before credential injection, aligning with the approach used in the tools wrapper. The test plan includes unit tests and manual testing to verify the fix.
f9c2dae to
b28f65d
Compare
b28f65d to
ec4267a
Compare
|
Addressed Gemini review feedback in ec4267a:
All checks pass (clippy, fmt, tests). |
0b00bfa to
e578ced
Compare
aa28202 to
75b08ee
Compare
75b08ee to
24c25f7
Compare
ilblackdragon
left a comment
There was a problem hiding this comment.
Review: fix(wasm): run leak scan on pre-injection headers in channel callbacks
Must-fix
- Eliminate double-parse of
headers_json— the code parsesheaders_jsontwice: once at line 340-341 for the existing flow, and again in the new block for the leak scan. The tools wrapper (src/tools/wasm/wrapper.rs:296-328) avoids this by scanningraw_headersBEFORE consuming it withinto_iter(). Restructure to match:
let raw_headers = serde_json::from_str(&headers_json).unwrap_or_default();
// Leak scan on raw WASM-provided values
leak_detector.scan_http_request(&url, &header_vec, body.as_deref())?;
// THEN inject credentials
let headers = raw_headers.into_iter()
.map(|(k, v)| (k.clone(), self.inject_credentials(&v, ...)))
.collect();- Misleading comment — says "ORIGINAL WASM-provided values (before ANY credential injection)" but the URL is post-template-injection (
injected_url). Fix to say "before host credential injection" or "pre-host-injection."
Should-fix
-
Migrate import — per CLAUDE.md, "new code should import from
ironclaw_safetydirectly." Both the production code and test usecrate::safety::LeakDetector. Migrate toironclaw_safety::LeakDetector. -
Remove unnecessary block scope — the
{ ... }around the leak scan provides no scoping benefit. -
Remove
raw_url_for_scanalias — it's just&urlwith no transformation.
The WASM channel host's http_request handler was scanning request headers
AFTER inject_credentials() replaced placeholder values (e.g. {SLACK_BOT_TOKEN})
with real secrets. This caused the leak detector to flag host-injected
credentials as potential leaks, blocking legitimate WASM channel callbacks.
Run the leak scan on the original WASM-provided headers (before any
credential injection) so host-injected tokens never appear in the scan.
WASM never sees the real values, so scanning the pre-injection state is
correct. Matches the existing pattern in src/tools/wasm/wrapper.rs.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Proves that scanning post-injection headers triggers a false positive on host-injected xoxb- tokens, confirming the fix must scan WASM-provided headers before credential injection.
…igrate import - Eliminate double-parse of headers_json: parse once, scan raw headers, then inject credentials (matches tools wrapper pattern) - Fix misleading comment: URL has template substitution but not yet host credential injection (was "before ANY credential injection") - Migrate import to ironclaw_safety::LeakDetector per CLAUDE.md - Remove unnecessary block scope around leak scan - Remove raw_url_for_scan alias (just use &url directly) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
24c25f7 to
c594003
Compare
|
Addressed all review feedback from @ilblackdragon in c594003, rebased onto latest staging ( Must-fix (both resolved)
Should-fix (all resolved)
All checks pass (cargo check, clippy, fmt, tests). |
zmanian
left a comment
There was a problem hiding this comment.
Review -- APPROVE
Security fix is correct. Leak scan now runs on pre-injection headers, preventing false positives from host-injected credentials (e.g., Slack xoxb- tokens).
All of ilblackdragon's feedback addressed:
- Double-parse eliminated -- single parse into
raw_headers, consumed byinto_iter()after scan - Comment updated to accurately describe pre/post-injection ordering
- Import migrated to
ironclaw_safety::LeakDetector - Block scope and URL alias removed
unwrap_or_defaultreplaced withunwrap_or_else+tracing::warn
Single fix point in http_request host function correctly covers all WASM HTTP egress (other callbacks invoke guest code which calls back into http_request).
Minor suggestion (non-blocking)
Consider whether malformed headers_json should be a hard error rather than falling back to empty headers -- a WASM module producing unparseable JSON may be worth failing fast on.
serrrfirat
left a comment
There was a problem hiding this comment.
Approved. I resolved the staging merge conflict and re-checked the final diff against origin/staging; it stays scoped to the WASM channel wrapper leak-scan ordering. The rerun checks on head 7db495c3 are green, including formatting, clippy default/libsql/all-features, cargo-deny, no-panics, and regression enforcement.
nearai#1377) * fix(wasm): run leak scan on pre-injection headers in channel callbacks The WASM channel host's http_request handler was scanning request headers AFTER inject_credentials() replaced placeholder values (e.g. {SLACK_BOT_TOKEN}) with real secrets. This caused the leak detector to flag host-injected credentials as potential leaks, blocking legitimate WASM channel callbacks. Run the leak scan on the original WASM-provided headers (before any credential injection) so host-injected tokens never appear in the scan. WASM never sees the real values, so scanning the pre-injection state is correct. Matches the existing pattern in src/tools/wasm/wrapper.rs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * test: regression test for pre-injection leak scan ordering Proves that scanning post-injection headers triggers a false positive on host-injected xoxb- tokens, confirming the fix must scan WASM-provided headers before credential injection. * fix: address review feedback — eliminate double-parse, fix comment, migrate import - Eliminate double-parse of headers_json: parse once, scan raw headers, then inject credentials (matches tools wrapper pattern) - Fix misleading comment: URL has template substitution but not yet host credential injection (was "before ANY credential injection") - Migrate import to ironclaw_safety::LeakDetector per CLAUDE.md - Remove unnecessary block scope around leak scan - Remove raw_url_for_scan alias (just use &url directly) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: serrrfirat <f@nuff.tech> Co-authored-by: Illia Polosukhin <ilblackdragon@gmail.com>
Summary
Run the leak detector on original WASM-provided headers before credential injection in channel HTTP callbacks. This is the companion fix to #791 (merged) which fixed the same bug in the tools wrapper.
Problem
The WASM channel host's
http_requesthandler callsinject_credentials()to replace placeholder values (e.g.{SLACK_BOT_TOKEN}) with real secrets, then runs the leak scan. Host-injected credentials trigger the leak detector, blocking legitimate channel callbacks like Slackchat.postMessage.Fix
Scan the raw WASM-provided headers (pre-injection) instead of the post-injection headers. WASM never sees the real token values, so the pre-injection state is the correct input for leak detection. Matches the existing pattern in
src/tools/wasm/wrapper.rs(PR #791).Test plan
cargo test --libpasses (3150 tests)cargo clippy --all --all-featurescleancargo fmt --checkcleanxoxb-token🤖 Generated with Claude Code