canghe-danger-gemini-web
Generates images and text via reverse-engineered Gemini Web API. Supports text generation, image generation from prompts, reference images for vision input, and multi-turn conversations. Use when other skills need image generation backend, or when user requests "generate image with Gemini", "Gemini text generation", or needs vision-capable AI generation.
1How It Works & Mechanism
The implementation foundation is a handwritten Gemini Web client: the open-source gemini_webapi is ported file-by-file into TypeScript (client/types/utils), enabling text and image generation without an official API key.
| `scripts/gemini-webapi/*` | TypeScript port of `gemini_webapi` (GeminiClient, types, utils) |
Endpoints are centralized in constants.ts: INIT fetches the page token, StreamGenerate uses the private streaming endpoint, ROTATE_COOKIES rotates session cookies, UPLOAD uploads reference images, and BATCH_EXEC handles batchexecute.
'https://gemini.google.com/_/BardChatUi/data/assistant.lamda.BardFrontendService/StreamGenerate',
The first step of authentication is acquiring the access token: during init, get_access_token is called with existing cookies, throwing an error if a valid token cannot be obtained—all generation requests must carry it.
const [token, valid] = await get_access_token(this.cookies, this.proxy, vb);
Credentials originate from browser session cookies: load-browser-cookies probes the local debugging port (/json/version, default 127.0.0.1) and spawns browser processes on demand to read the active login state.
const res = await fetch_with_timeout(`http://127.0.0.1:${port}/json/version`, { timeout_ms: 5_000 });
Cookies and rotation results are persisted to local files: cookie-file writes to disk as JSON, and rotate-1psidts caches refreshed 1PSIDTS values to a file.
await writeFile(p, JSON.stringify(payload, null, 2), 'utf8');
Image capabilities reside in types/image.ts: remote images are downloaded and written to disk (writeFile(dest, buf)), while reference images are routed through the content-push upload channel via upload-file.
await writeFile(dest, buf);
Multi-turn conversations do not rely on server-side sessions; instead, Gemini chat metadata is saved locally to sessions/<id>.json, using --sessionId to reuse metadata and continue dialogues.
Session files stored in data directory under `sessions/<id>.json`.
Reverse-engineered usage explicitly requires 'prior consent': on first run, it must verify the consent file (accepted and disclaimerVersion 1.0), exiting immediately if declined.
1. Check if consent file exists with `accepted: true` and `disclaimerVersion: "1.0"`
The request layer features a running retry decorator: it automatically calls init if the client is not initialized, and sleeps for 1s before retrying upon encountering an APIError if retries remain.
if (e instanceof APIError && r > 0) {
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| network | gemini.google.com(INIT 页面取令牌 + StreamGenerate 私有生成接口 + batchexecute) |
| network | accounts.google.com(RotateCookies 轮换会话 cookie) |
| network | content-push.googleapis.com(参考图上传) |
| network | lh3.googleusercontent.com(返回图像资源 gg-dl) |
| cli | bun / npx(以 npx -y bun 直接运行脚本,无运行时抽象) |
| cli | 本机 Chrome/Chromium/Edge 可执行文件(按需 spawn 以读取会话 cookie) |
4Recommended Governance & Evidence
- SKILL.md / 脚本: Calls undisclosed or reverse-engineered private APIs / forges client identification
- SKILL.md / 脚本参数: Bypasses automated detection, disables host sandboxes, or skips SSL certificate verification
- SKILL.md / 会话存储: Reads or reuses browser user login states and session cookies
- 本地凭据 / 浏览器配置: Reads user login cookies/sessions/keyrings: browser session cookies: __Secure-1PSID / __Secure-1PSIDTS, etc. (local cookies.json or via local Chrome)
- scripts/: Executes local scripts or commands: scripts/main.ts (run via npx -y bun; probes and spawns local browsers on demand to read cookies)
- 网络端点: Declares external network access: https://gemini.google.com/app (INIT fetches page token)
- 本地工作目录: File read/write and artifact output: cookies.json (credential persistence: writes session cookies)
5Second-Pass Verification
- [ok] 逆向 API 而非官方 API(red 主因之一) — constants.ts 直指 gemini.google.com 的 StreamGenerate 私有路径;SKILL.md/description 自述 reverse-engineered,并设 consent 门禁。
- [ok] 读取浏览器会话 cookie(red 主因之二) — load-browser-cookies.ts 探测 127.0.0.1 调试端口并按需 spawn 浏览器;SKILL.md 自述 First run opens browser for Google auth。
- [ok] 凭据落盘 — cookie-file.ts 的 writeFile(p, JSON.stringify(payload, null, 2)) 与 rotate-1psidts.ts 的 writeFile(cachePath, v) 两处写盘,路径由 paths.ts 解析。
- [ok] 无 TLS 降级 / 无 stealth 伪装 / 无任意代码执行 — 相关行为在 bundle 正文与 §3 风险扫描中均零命中;调度只有 init 重试与 sleep。
- [ok] consent 门禁存在但为“软门禁” — SKILL.md 要求先建 consent.json 再使用;但脚本自身不校验该文件,属文档级约束,已写入 risks。
- [ok] 功能声明与实现相符 — 文本/图像/vision/多轮四项在 SKILL.md Options 与 main.ts/client.ts 均有对应实现,未见夸大。
6Verdict & Scenarios
a98a97c1f7c81879…