mirror of
https://github.com/therealaleph/MasterHttpRelayVPN-RUST.git
synced 2026-05-18 15:44:40 +03:00
feat: v1.8.0 — DPI evasion, active-probing defense, full-mode usage counters
Five user-visible changes shipping together. Each is independently useful + bounded; bundled because they're all "small architectural hardening" that benefits from one release announcement. 1. Random payload padding (#313, #365 §1) Every outbound Apps Script JSON request now carries a `_pad` field of uniform-random length 0..1024 bytes (base64). Defeats DPI that fingerprints on the tight length distribution of mhrv-rs's previous per-mode-bound packet sizes. ~25% bandwidth on a typical 2 KB batch, negligible against Apps Script's per-call latency floor. Backward- compatible — old `Code.gs` deployments ignore the unknown field. Applied at all three payload-build sites: single relay, single tunnel op, batch tunnel. 2. Active-probing decoy: GAS bad-auth → 200 HTML (#365 §3) `Code.gs` and `CodeFull.gs` now return a benign Apps-Script-style placeholder HTML page on bad/missing AUTH_KEY instead of the JSON `{"e":"unauthorized"}`. To an active scanner the deployment looks like one of the millions of forgotten public Apps Script projects rather than an obvious API endpoint. New `DIAGNOSTIC_MODE` const restores JSON errors during setup; default false (production-strong). 3. Active-probing decoy: tunnel-node bad-auth → 404 nginx (#365 §3) `tunnel-node` returns an HTTP 404 with an nginx-style HTML body on bad auth instead of `{"e":"unauthorized"}`. Active scanners cataloging the host see "static web server, nothing tunnel-shaped here." New `MHRV_DIAGNOSTIC=1` env var restores verbose JSON during setup. 4. Fix: Full-mode usage counter stuck at zero (#230, #362) `today_calls` / `today_bytes` were only being incremented on the apps_script-mode relay path. Full-mode batches go through `tunnel_client::fire_batch` which never wired into the counter. Now `fire_batch` calls `record_today(response_bytes)` after each successful batch — bytes estimated from the `d` (TCP payload) and `pkts` (UDP datagrams) sizes in the BatchTunnelResponse. Full-mode users now see real usage numbers. 5. Fix: quota reset countdown was UTC, should be PT (#230, #362) Apps Script's UrlFetchApp daily quota resets at midnight Pacific Time, not UTC. We were displaying the countdown to UTC midnight, off by 7-8h depending on DST. New `current_pt_day_key()` and `seconds_until_pacific_midnight()` helpers with hand-rolled US DST detection (2nd Sunday March → 1st Sunday November = PDT, else PST) so we don't pull `chrono-tz` and a ~3 MB IANA tzdb just for one helper. UI label "UTC day" → "PT day". Tests pin DST window boundaries against March/November of 2024, 2026, 2027 to catch regressions in the day-of-week math. Tested: - cargo test --lib: 154 passed (was 152, +2 for DST window + day-of-week) - cargo build --release: clean - cargo build --release --bin mhrv-rs-ui --features ui: clean (macOS arm64) - tunnel-node cargo test: 30 passed - Android: ./gradlew assembleDebug succeeds; APK installs + launches on mhrv_test emulator (arm64-v8a), no UnsatisfiedLink, no crash Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -18,6 +18,19 @@
|
||||
|
||||
const AUTH_KEY = "CHANGE_ME_TO_A_STRONG_SECRET";
|
||||
|
||||
// Active-probing defense. When false (production default), bad AUTH_KEY
|
||||
// requests get a decoy HTML page that looks like a placeholder Apps
|
||||
// Script web app instead of the JSON `{"e":"unauthorized"}` body. This
|
||||
// makes the deployment indistinguishable from a forgotten-but-public
|
||||
// Apps Script project to active scanners that POST malformed payloads
|
||||
// looking for proxy endpoints.
|
||||
//
|
||||
// Set to `true` during initial setup if a misconfigured client is
|
||||
// hitting "unauthorized" and you want the explicit JSON error to debug
|
||||
// — then flip back to false before the deployment is widely shared.
|
||||
// (Inspired by #365 Section 3, mhrv-rs v1.8.0+.)
|
||||
const DIAGNOSTIC_MODE = false;
|
||||
|
||||
// Keep browser capability headers (sec-ch-ua*, sec-fetch-*) intact.
|
||||
// Some modern apps, notably Google Meet, use them for browser gating.
|
||||
const SKIP_HEADERS = {
|
||||
@@ -26,10 +39,25 @@ const SKIP_HEADERS = {
|
||||
"priority": 1, te: 1,
|
||||
};
|
||||
|
||||
// HTML body for the bad-auth decoy. Mimics a minimal Apps Script-style
|
||||
// placeholder page — no proxy-shaped JSON, nothing distinctive enough
|
||||
// for a probe to fingerprint as a tunnel endpoint.
|
||||
const DECOY_HTML =
|
||||
'<!DOCTYPE html><html><head><title>Web App</title></head>' +
|
||||
'<body><p>The script completed but did not return anything.</p>' +
|
||||
'</body></html>';
|
||||
|
||||
function _decoyOrError(jsonBody) {
|
||||
if (DIAGNOSTIC_MODE) return _json(jsonBody);
|
||||
return ContentService
|
||||
.createTextOutput(DECOY_HTML)
|
||||
.setMimeType(ContentService.MimeType.HTML);
|
||||
}
|
||||
|
||||
function doPost(e) {
|
||||
try {
|
||||
var req = JSON.parse(e.postData.contents);
|
||||
if (req.k !== AUTH_KEY) return _json({ e: "unauthorized" });
|
||||
if (req.k !== AUTH_KEY) return _decoyOrError({ e: "unauthorized" });
|
||||
|
||||
// Batch mode: { k, q: [...] }
|
||||
if (Array.isArray(req.q)) return _doBatch(req.q);
|
||||
@@ -37,10 +65,23 @@ function doPost(e) {
|
||||
// Single mode
|
||||
return _doSingle(req);
|
||||
} catch (err) {
|
||||
return _json({ e: String(err) });
|
||||
// Parse failures of the request body are also probe-shaped — a real
|
||||
// mhrv-rs client never sends invalid JSON. Decoy for the same reason.
|
||||
return _decoyOrError({ e: String(err) });
|
||||
}
|
||||
}
|
||||
|
||||
// `doGet` is what active scanners hit first (HTTP GET probes are cheaper
|
||||
// than POSTs). Apps Script defaults to a "Script function not found" page
|
||||
// here which is a fine-enough decoy on its own, but explicitly returning
|
||||
// the same harmless placeholder makes the response identical to the
|
||||
// bad-auth POST decoy — one less fingerprint vector.
|
||||
function doGet(e) {
|
||||
return ContentService
|
||||
.createTextOutput(DECOY_HTML)
|
||||
.setMimeType(ContentService.MimeType.HTML);
|
||||
}
|
||||
|
||||
function _doSingle(req) {
|
||||
if (!req.u || typeof req.u !== "string" || !req.u.match(/^https?:\/\//i)) {
|
||||
return _json({ e: "bad url" });
|
||||
|
||||
Reference in New Issue
Block a user