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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# BEX Engine Production Readiness Audit
|
| 2 |
+
|
| 3 |
+
This document records the current production posture of `pluginengine01` after the HTTP/backend re-audit.
|
| 4 |
+
|
| 5 |
+
## Current Verdict
|
| 6 |
+
|
| 7 |
+
The engine is **usable in C/C++ desktop/server apps today** as a portable WASM plugin runtime with:
|
| 8 |
+
|
| 9 |
+
- Pure C ABI (`bex_engine.h`)
|
| 10 |
+
- Async callback API
|
| 11 |
+
- Wasmtime Component Model sandboxing
|
| 12 |
+
- Per-plugin manifests and capability gates
|
| 13 |
+
- HTTP host API with browser-like headers, cookies, compression, HTTP/2
|
| 14 |
+
- QuickJS host API for site-specific JavaScript/cipher code
|
| 15 |
+
- Redb-backed KV/secrets storage
|
| 16 |
+
- FlatBuffer/JSON conversion paths for C++ apps
|
| 17 |
+
|
| 18 |
+
The engine is **not yet a universal Cloudflare bypass engine**. The default HTTP backend is intentionally portable (`reqwest + rustls`) and does not byte-match Chrome's TLS JA3/JA4 fingerprint.
|
| 19 |
+
|
| 20 |
+
## Production-Safe Default Backend
|
| 21 |
+
|
| 22 |
+
Current default:
|
| 23 |
+
|
| 24 |
+
```toml
|
| 25 |
+
reqwest = { version = "0.12", default-features = false, features = [
|
| 26 |
+
"rustls-tls", "json", "gzip", "brotli", "deflate", "cookies", "http2"
|
| 27 |
+
] }
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
Why this is the default:
|
| 31 |
+
|
| 32 |
+
- Builds reliably on Linux, macOS, Windows.
|
| 33 |
+
- Embeds cleanly into C/C++ apps.
|
| 34 |
+
- Avoids native BoringSSL/curl-impersonate build complexity.
|
| 35 |
+
- Keeps the repo buildable without unverified crate APIs.
|
| 36 |
+
|
| 37 |
+
Limitations:
|
| 38 |
+
|
| 39 |
+
- TLS fingerprint is rustls, not Chrome/BoringSSL.
|
| 40 |
+
- Advanced anti-bot systems may still challenge/block.
|
| 41 |
+
- Browser-like HTTP headers help with simple checks but do not fix JA3/JA4.
|
| 42 |
+
|
| 43 |
+
## Cloudflare / Anti-Bot Reality
|
| 44 |
+
|
| 45 |
+
| Protection type | Default backend | Notes |
|
| 46 |
+
|---|---:|---|
|
| 47 |
+
| Basic header checks | ✅ | Chrome-like headers, cookies, H2, compression |
|
| 48 |
+
| Cookie/session checks | ✅ | `cookie_store(true)` |
|
| 49 |
+
| Simple CF managed challenge | ⚠️ | Can pass some; not guaranteed due TLS fingerprint |
|
| 50 |
+
| CF JS challenge | ⚠️ | Requires plugin/QuickJS solver and session cookies |
|
| 51 |
+
| Turnstile/CAPTCHA | ❌ | Needs user interaction/WebView/browser handoff |
|
| 52 |
+
| DataDome/PerimeterX/Akamai bot | ❌/⚠️ | Usually requires Chrome TLS + H2 fingerprint impersonation |
|
| 53 |
+
|
| 54 |
+
## Optional Hardened HTTP Backend Roadmap
|
| 55 |
+
|
| 56 |
+
For real browser-grade anti-bot bypass, add an **optional Cargo feature**, not the default:
|
| 57 |
+
|
| 58 |
+
```toml
|
| 59 |
+
[features]
|
| 60 |
+
default = ["http-reqwest"]
|
| 61 |
+
http-reqwest = ["dep:reqwest"]
|
| 62 |
+
http-impersonate = ["dep:rquest"] # or another verified crate
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
Requirements before enabling this in production:
|
| 66 |
+
|
| 67 |
+
1. Verify crate/version exists and API compiles.
|
| 68 |
+
2. Verify Chrome profile enum/import path.
|
| 69 |
+
3. Verify Linux/macOS/Windows build in CI.
|
| 70 |
+
4. Verify cross-compilation for app targets.
|
| 71 |
+
5. Verify TLS fingerprint on every target with an external JA3/JA4 tester.
|
| 72 |
+
6. Keep `reqwest` fallback for platforms where impersonation cannot build.
|
| 73 |
+
|
| 74 |
+
Do **not** ship an unverified `rquest = "1.0"` or undocumented builder API.
|
| 75 |
+
|
| 76 |
+
## C++ App Integration Status
|
| 77 |
+
|
| 78 |
+
### Good
|
| 79 |
+
|
| 80 |
+
- ABI is plain C, no Rust types across boundary.
|
| 81 |
+
- Callbacks return `payload` plus length; C++ can copy before return.
|
| 82 |
+
- Sync plugin management functions use integer status codes.
|
| 83 |
+
- Strings returned by Rust have explicit free functions.
|
| 84 |
+
- CMake now supports macOS/Linux/Windows better and no longer forces full static glibc linking.
|
| 85 |
+
|
| 86 |
+
### Integration Rules
|
| 87 |
+
|
| 88 |
+
C++ apps must:
|
| 89 |
+
|
| 90 |
+
1. Keep `BexEngine*` alive until all callbacks complete.
|
| 91 |
+
2. Keep `user_data` alive until callback fires or request is cancelled and callback path is known.
|
| 92 |
+
3. Copy callback payload before returning from callback.
|
| 93 |
+
4. Marshal callback results to the app/UI thread if needed.
|
| 94 |
+
5. Call `bex_engine_free` only during shutdown, not while new requests are being submitted.
|
| 95 |
+
|
| 96 |
+
## Known Issues To Fix Before Hard Production
|
| 97 |
+
|
| 98 |
+
These are not architecture blockers, but should be addressed before high-volume deployment:
|
| 99 |
+
|
| 100 |
+
1. **Cancellation tokens should be removed after async task completion.**
|
| 101 |
+
- Current code inserts tokens but does not visibly remove them in `submit_async` after completion.
|
| 102 |
+
- Long-running apps may leak entries in the cancellation map.
|
| 103 |
+
|
| 104 |
+
2. **`bex_engine_secret_get` should guard zero-length buffers.**
|
| 105 |
+
- If caller passes `*out_buf_len == 0`, `buf_size - 1` underflows.
|
| 106 |
+
- Add explicit `if buf_size == 0 { required_len = value.len()+1; return -2; }`.
|
| 107 |
+
|
| 108 |
+
3. **Scheduler exists but FFI async submit path does not visibly acquire scheduler permits.**
|
| 109 |
+
- The architecture has lane semaphores, but `submit_async` currently uses `spawn_blocking` directly.
|
| 110 |
+
- Add scheduler acquisition around user/control/background calls for true production backpressure.
|
| 111 |
+
|
| 112 |
+
4. **HTTP cache key is URL-only.**
|
| 113 |
+
- If two plugins request the same URL with different auth headers, cached response can cross-contaminate.
|
| 114 |
+
- Make key `plugin_id + method + url + vary-relevant headers`, or disable cache for requests with auth/cookie-sensitive headers.
|
| 115 |
+
|
| 116 |
+
5. **`call-js-fn` should resolve Promises like `eval-js`.**
|
| 117 |
+
- Async JS functions returning promises may stringify as `{}`.
|
| 118 |
+
- Reuse the Promise resolution logic from `eval_js` in `worker.rs`.
|
| 119 |
+
|
| 120 |
+
## Plugin Architecture Assessment
|
| 121 |
+
|
| 122 |
+
The WIT interface is sufficient for multi-site media plugins:
|
| 123 |
+
|
| 124 |
+
- home/category/search/info/servers/stream
|
| 125 |
+
- subtitles/articles
|
| 126 |
+
- HTTP with headers/body/method/cache mode
|
| 127 |
+
- KV/secrets
|
| 128 |
+
- QuickJS for ciphers/player scripts
|
| 129 |
+
- logging/clock/rng
|
| 130 |
+
|
| 131 |
+
The KaiAnime plugin proves the model works end-to-end:
|
| 132 |
+
|
| 133 |
+
- HTML scraping
|
| 134 |
+
- AJAX endpoints
|
| 135 |
+
- self-describing episode IDs
|
| 136 |
+
- multi-step token encryption/decryption
|
| 137 |
+
- server listing
|
| 138 |
+
- stream resolution
|
| 139 |
+
- HLS + subtitles
|
| 140 |
+
|
| 141 |
+
However, KaiAnime currently depends on `enc-dec.app` instead of local QuickJS cipher code. For long-term reliability, move site ciphers into plugin-local JS via `call-js-fn`.
|
| 142 |
+
|
| 143 |
+
## Cross-Platform Matrix
|
| 144 |
+
|
| 145 |
+
| Target | Current default backend | Status |
|
| 146 |
+
|---|---:|---|
|
| 147 |
+
| Linux x86_64 | reqwest/rustls | ✅ Good |
|
| 148 |
+
| Linux aarch64 | reqwest/rustls | ✅ Good |
|
| 149 |
+
| macOS x86_64/arm64 | reqwest/rustls | ✅ Good, CMake framework links added |
|
| 150 |
+
| Windows MSVC | reqwest/rustls | ✅ Likely, system libs added |
|
| 151 |
+
| Android | Rust staticlib possible | ⚠️ Needs NDK CI proof |
|
| 152 |
+
| iOS | Rust staticlib possible | ⚠️ Needs iOS toolchain + Wasmtime support verification |
|
| 153 |
+
| Fully static Linux glibc | Not default | ⚠️ Opt-in only via `BEX_FORCE_STATIC_EXE=ON` |
|
| 154 |
+
|
| 155 |
+
## Recommendation
|
| 156 |
+
|
| 157 |
+
For production apps today:
|
| 158 |
+
|
| 159 |
+
1. Use the current default backend for portability.
|
| 160 |
+
2. Add CI for Linux/macOS/Windows release builds.
|
| 161 |
+
3. Fix the five known issues above.
|
| 162 |
+
4. Add optional impersonation backend later, behind a feature flag, only after compile/API/fingerprint verification.
|
| 163 |
+
5. For sites with serious bot defenses, provide app-level browser/WebView handoff as fallback.
|