Spaces:
Running
Running
ahmdelbaz28-ux
fix(sonar): harden ops scripts — header allowlist in proxy (S5146/S6109/S5144), argv-only secrets (S5443), log-injection sanitizers (S5145), flat ternary map (S3358)
3b1d754 Download scripts/email_paths_final_proof.mjs from ahmdelbaz28/AHMDRTAP: direct link, hf CLI and curl.
- Browser
- Download file 2.89 kB
-
https://huggingface.co/spaces/ahmdelbaz28/AHMDRTAP/resolve/main/scripts/email_paths_final_proof.mjs
- Command line
-
hf download hf://spaces/ahmdelbaz28/AHMDRTAP/scripts/email_paths_final_proof.mjs
-
curl -L -o email_paths_final_proof.mjs https://huggingface.co/spaces/ahmdelbaz28/AHMDRTAP/resolve/main/scripts/email_paths_final_proof.mjs
2.89 kB
| // FINAL EMAIL PROOF — logs in as admin on production (via origin proxy) and | |
| // fires ALL THREE email paths, printing the server's own delivery verdicts: | |
| // 1. auth.sendVerificationEmail (profile "تأكيد البريد" button) | |
| // 2. auth.sendEmailSelfTest (admin one-click provider probe) | |
| // 3. auth.forgotPassword (reset code + link) | |
| // | |
| // Usage: node scripts/email_paths_final_proof.mjs <admin-password> | |
| // (password comes from argv/env — never stored in a file) | |
| const BASE = process.env.BASE || "http://localhost:4174"; | |
| const PASS = process.argv[2] || process.env.ADMIN_PASS || ""; | |
| if (!PASS) { | |
| console.log("usage: node scripts/email_paths_final_proof.mjs <admin-password>"); | |
| process.exit(1); | |
| } | |
| async function trpc(procedure, input, cookie) { | |
| const res = await fetch(`${BASE}/api/trpc/${procedure}?batch=1`, { | |
| method: "POST", | |
| headers: { "Content-Type": "application/json", ...(cookie ? { cookie } : {}) }, | |
| body: JSON.stringify({ "0": { json: input ?? null } }), | |
| }); | |
| const setCookies = res.headers.getSetCookie ? res.headers.getSetCookie() : []; | |
| const text = await res.text(); | |
| return { status: res.status, setCookies, text }; | |
| } | |
| // Log-injection sanitizer: strip CR/LF from upstream-derived values. | |
| const safe = (v) => String(v ?? "").replace(/[\r\n]+/g, " "); | |
| const login = await trpc("auth.login", { username: "admin", password: PASS, remember: true }); | |
| const authCookie = login.setCookies.map((c) => c.split(";")[0]).filter((c) => c.length > 20).join("; "); | |
| console.log("login:", safe(login.status), authCookie ? "(session established)" : "(NO COOKIE)"); | |
| if (login.status !== 200 || !authCookie) { console.log(safe(login.text.slice(0, 300))); process.exit(1); } | |
| const unwrap = (text) => { | |
| try { | |
| const j = JSON.parse(text); | |
| const e = j?.[0]?.error?.json; | |
| if (e) return { error: e.message }; | |
| return j?.[0]?.result?.data?.json ?? j?.[0]?.result?.data ?? j; | |
| } catch { return text.slice(0, 200); } | |
| }; | |
| console.log("\n── Path 1: auth.sendVerificationEmail (profile confirmation) ──"); | |
| const p1 = await trpc("auth.sendVerificationEmail", null, authCookie); | |
| console.log(" status:", safe(p1.status), "| verdict:", safe(JSON.stringify(unwrap(p1.text)).slice(0, 200))); | |
| console.log("\n── Path 2: auth.sendEmailSelfTest (admin provider probe) ──"); | |
| const p2 = await trpc("auth.sendEmailSelfTest", null, authCookie); | |
| console.log(" status:", safe(p2.status), "| verdict:", safe(JSON.stringify(unwrap(p2.text)).slice(0, 260))); | |
| console.log("\n── Path 3: auth.forgotPassword (reset code) ──"); | |
| const p3 = await trpc("auth.forgotPassword", { email: "admin@ahmedelbaz.qzz.io" }); | |
| console.log(" status:", safe(p3.status), "| verdict:", safe(JSON.stringify(unwrap(p3.text)).slice(0, 200))); | |
| console.log("\nAll three email paths have been triggered against the LIVE production server."); | |