Skip to content

Use WASM module of zen-internals instead of FFI - #347

Open
hansott wants to merge 8 commits into
mainfrom
wasm-zen-internals
Open

Use WASM module of zen-internals instead of FFI#347
hansott wants to merge 8 commits into
mainfrom
wasm-zen-internals

Conversation

@hansott

@hansott hansott commented Aug 18, 2026

Copy link
Copy Markdown
Member

Similar to go agent, packages the wasm module inside the agent jar and gets rid of the required native flag to disable warning

In terms of perf, it's 3-4x faster than the current FFI approach. However, we're loading the FFI library on every invocation so it was slow by design. Caching the FFI library is much faster than the WASM approach but in a real application you don't notice the difference between cached FFI and WASM (because there's other overhead).

Comment thread agent/src/main/java/dev/aikido/agent/Agent.java
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.64407% with 37 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ulnerabilities/sql_injection/WasmSQLInterface.java 65.88% 21 Missing and 8 partials ⚠️
...pi/vulnerabilities/sql_injection/WasmInstance.java 75.00% 4 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

@hansott
hansott force-pushed the wasm-zen-internals branch from 3a69bc3 to 62f342b Compare August 19, 2026 08:40
instance = current.pool.acquire();
} catch (Throwable e) {
logger.trace(e);
return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The catch-all failure path returns false from detectSqlInjection, treating WASM errors as safe input and bypassing SQL injection validation.

Details

✨ AI Reasoning
​The new error path converts any WASM execution failure into a normal negative detection result. This makes failures indistinguishable from safe input and can disable SQL injection protection without surfacing the problem to callers.

🔧 How do I fix it?
Remove debugging statements like console.log, debugger, dd(), or logic bypasses like || true. Keep legitimate logging for monitoring and error handling.

Reply @AikidoSec feedback: [FEEDBACK] to get better review comments in the future.
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info

Similar to go agent, packages the wasm module inside the agent jar and
gets rid of the required native flag to disable warning

In terms of perf, it's 3-4x faster than the current FFI approach.
However, we're loading the FFI library on every invocation so it was
slow by design. Caching the FFI library is much faster than the WASM
approach but in a real application you don't notice the difference
between cached FFI and WASM (because there's other overhead).
@hansott
hansott force-pushed the wasm-zen-internals branch from 62f342b to 1ad6bb1 Compare August 19, 2026 09:04
Comment on lines +54 to +55
// If zen-internals is unavailable, let the database query proceed.
return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High - WASM failures are handled fail-open, disabling SQL injection detection

detectSqlInjection catches initialization and instance-acquisition errors and returns false, which is the same result used for a clean query. Because SqlDetector treats false as "no attack" and Agent ignores the result of the startup initialize() call, a missing, corrupt, or otherwise broken zen-internals module silently turns off SQL injection protection instead of surfacing a hard failure. An attacker only needs the detector to be unavailable for malicious queries to be allowed through unchecked.

Show fix

Fail closed when the WASM detector cannot be initialized or executed. Either abort agent startup if initialize() fails, or make detectSqlInjection propagate a distinct failure so callers can block/disable the protected operation instead of interpreting detector errors as "no injection detected."

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

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.

2 participants