[PR #7086] [MERGED] fix(bot-browser): harden the Pygmalion token login (#7074) #7465

Closed
opened 2026-10-23 04:20:03 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7086
Author: @SpicyMarinara
Created: 10/5/2026
Status: ✅ Merged
Merged: 10/5/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/pygmalion-login-7074


📝 Commits (5)

  • a57711f fix(bot-browser): harden the Pygmalion token login (#7074)
  • 1a425af Merge remote-tracking branch 'origin/staging' into fix/pygmalion-login-7074
  • c4d9372 fix(bot-browser): keep Pygmalion avatars and logins on safe paths (#7074)
  • 4573cc4 fix(bot-browser): handle an expired Pygmalion session in Import and Download (#7074)
  • 195272b Merge remote-tracking branch 'origin/staging' into fix/pygmalion-login-7074

📊 Changes

8 files changed (+526 additions, -143 deletions)

View changed files

📝 CHANGELOG.md (+2 -0)
📝 docs/characters/bot-browser.md (+6 -2)
➕ e2e/bot-browser-pygmalion-login.e2e.ts (+74 -0)
📝 packages/client/src/components/bot-browser/BotBrowserView.tsx (+76 -20)
📝 packages/client/src/localization/locales/en.json (+5 -0)
📝 packages/server/src/routes/bot-browser-pygmalion.routes.ts (+128 -120)
📝 packages/server/src/services/bot-browser/fetch-json.ts (+11 -1)
➕ scripts/regressions/bot-browser-pygmalion-login.regression.ts (+224 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #7074

Why this change

  • A security audit of the Card Browser's Pygmalion login found that the pasted token was stored without checking its shape, so a value with stray line breaks or control characters was kept. Later requests then failed with error text that included the whole token, which ended up in the server log and the login error message.
  • A token Pygmalion rejected was still stored and used.
  • Pygmalion requests weren't limited to Pygmalion's servers, response size, or redirects. The avatar proxy would fetch from any address it was given.
  • When Pygmalion stopped accepting the token during browsing, users saw a search error instead of being asked to log in again.
  • The token field showed the token in plain text, with spellcheck and autocomplete on.

What changed

  • Saving a token: the server trims it, drops an optional Bearer prefix and accepts only token characters. Anything else gets a 400 with a plain message, and nothing is stored or sent.
  • Checked before storing: the token is checked with Pygmalion first and stored only when Pygmalion accepts it. If the check fails, the previous login stays as it was, and the reply carries a fixed reason: couldn't reach Pygmalion, rejected the token, or busy.
  • No token in errors or logs: replies and logs for requests that carry the token never include upstream error text. Logs record only the HTTP status or error code.
  • Pinned host: search, character and token-check requests go only to server.pygmalion.chat, over https only, without following redirects, and with response size caps. The unneeded Origin/Referer headers are removed.
  • Expired login: a 401 on a signed-in search or character call clears the stored token. The client shows the existing "session expired — please log in again" toast and switches back to Log In. A 403, which means one item isn't allowed, keeps the login.
  • Avatar proxy: it accepts only https URLs on pygmalion.chat and its subdomains, and redirects must stay on the same host. Relative paths still work.
  • Login window:
    • The token field is masked, with spellcheck and autocomplete off, and is linked to its label.
    • One plain sentence, linked to the field, explains that the login stays in memory until restart or Log Out, and that fully signing out also needs a logout on pygmalion.chat.
    • Log Out shows whenever the server reports an active session.
  • Tests: a new node regression with all Pygmalion traffic stubbed, and a new Playwright e2e for the login window.
  • Docs: CHANGELOG entry and an update to the Pygmalion login part of docs/characters/bot-browser.md.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Agent-run checks (not a substitute for the boxes above):

  • pnpm check passed.
  • pnpm localization:check passed.
  • node scripts/run-regressions.mjs --filter bot-browser: 2/2 passed. The new bot-browser-pygmalion-login regression fails on staging's server code and passes with this branch.
  • Playwright bot-browser-pygmalion-login and bot-browser-download: 12/12 passed on desktop-chromium, mobile-chromium and mobile-webkit.
  • Local CodeRabbit review: not run yet.

Manual verification notes

  • Manually verify that pasting a real Pygmalion authn token (with and without Bearer ) logs in and shows NSFW results.
  • Manually verify that a wrong token shows "Pygmalion rejected the token." and leaves you logged out.
  • Manually verify that the token field hides its contents and the new sentence is readable in light and dark themes and on a phone-width window.
  • Manually verify that after restarting the server, reopening the Card Browser shows the "session expired" toast and Log In.
  • Manually verify that Pygmalion avatars still load in results and in the detail view. This change refuses redirects that leave the avatar's host.
  • Manually verify that Log Out clears the session and Log In appears again.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

Changed docs: CHANGELOG.md and docs/characters/bot-browser.md. The translated characters/bot-browser.md copies on docs-i18n still need updating, or a [docs-i18n] docs/characters/bot-browser.md follow-up issue.

UI evidence (if applicable)

  • Login window screenshot: attached by the e2e run as pygmalion-login-modal.png. Add a before/after screenshot here.

Summary by CodeRabbit

  • New Features

    • Added Pygmalion token validation with clear messages for rejected tokens, unavailable service, and busy service.
    • Prompt users to log in again when their Pygmalion session expires while browsing.
  • Bug Fixes

    • Improved token privacy in the login field and error messages.
    • Restricted Pygmalion requests and avatar loading to trusted Pygmalion servers.
    • Clarified that login remains in memory until restart or log out, and that full sign-out also requires logging out on pygmalion.chat.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/7086 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/5/2026 **Status:** ✅ Merged **Merged:** 10/5/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/pygmalion-login-7074` --- ### 📝 Commits (5) - [`a57711f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a57711f1e3fc846fb3eda61e8eaa598e7e0a1f10) fix(bot-browser): harden the Pygmalion token login (#7074) - [`1a425af`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1a425affb819e5c82e9254d103c7b295a8f2ca1f) Merge remote-tracking branch 'origin/staging' into fix/pygmalion-login-7074 - [`c4d9372`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c4d9372fb9e8fa6debe6d435aab21f56ebfb7274) fix(bot-browser): keep Pygmalion avatars and logins on safe paths (#7074) - [`4573cc4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4573cc4369e09e88083a907f5babbda3d855863c) fix(bot-browser): handle an expired Pygmalion session in Import and Download (#7074) - [`195272b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/195272b9f130de1b88a4d28c2d485bc37300eecc) Merge remote-tracking branch 'origin/staging' into fix/pygmalion-login-7074 ### 📊 Changes **8 files changed** (+526 additions, -143 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+2 -0) 📝 `docs/characters/bot-browser.md` (+6 -2) ➕ `e2e/bot-browser-pygmalion-login.e2e.ts` (+74 -0) 📝 `packages/client/src/components/bot-browser/BotBrowserView.tsx` (+76 -20) 📝 `packages/client/src/localization/locales/en.json` (+5 -0) 📝 `packages/server/src/routes/bot-browser-pygmalion.routes.ts` (+128 -120) 📝 `packages/server/src/services/bot-browser/fetch-json.ts` (+11 -1) ➕ `scripts/regressions/bot-browser-pygmalion-login.regression.ts` (+224 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Closes #7074 ## Why this change - A security audit of the Card Browser's Pygmalion login found that the pasted token was stored without checking its shape, so a value with stray line breaks or control characters was kept. Later requests then failed with error text that included the whole token, which ended up in the server log and the login error message. - A token Pygmalion rejected was still stored and used. - Pygmalion requests weren't limited to Pygmalion's servers, response size, or redirects. The avatar proxy would fetch from any address it was given. - When Pygmalion stopped accepting the token during browsing, users saw a search error instead of being asked to log in again. - The token field showed the token in plain text, with spellcheck and autocomplete on. ## What changed - **Saving a token:** the server trims it, drops an optional `Bearer ` prefix and accepts only token characters. Anything else gets a 400 with a plain message, and nothing is stored or sent. - **Checked before storing:** the token is checked with Pygmalion first and stored only when Pygmalion accepts it. If the check fails, the previous login stays as it was, and the reply carries a fixed reason: couldn't reach Pygmalion, rejected the token, or busy. - **No token in errors or logs:** replies and logs for requests that carry the token never include upstream error text. Logs record only the HTTP status or error code. - **Pinned host:** search, character and token-check requests go only to `server.pygmalion.chat`, over https only, without following redirects, and with response size caps. The unneeded Origin/Referer headers are removed. - **Expired login:** a 401 on a signed-in search or character call clears the stored token. The client shows the existing "session expired — please log in again" toast and switches back to **Log In**. A 403, which means one item isn't allowed, keeps the login. - **Avatar proxy:** it accepts only https URLs on `pygmalion.chat` and its subdomains, and redirects must stay on the same host. Relative paths still work. - **Login window:** - The token field is masked, with spellcheck and autocomplete off, and is linked to its label. - One plain sentence, linked to the field, explains that the login stays in memory until restart or **Log Out**, and that fully signing out also needs a logout on pygmalion.chat. - **Log Out** shows whenever the server reports an active session. - **Tests:** a new node regression with all Pygmalion traffic stubbed, and a new Playwright e2e for the login window. - **Docs:** CHANGELOG entry and an update to the Pygmalion login part of `docs/characters/bot-browser.md`. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` Agent-run checks (not a substitute for the boxes above): - `pnpm check` passed. - `pnpm localization:check` passed. - `node scripts/run-regressions.mjs --filter bot-browser`: 2/2 passed. The new `bot-browser-pygmalion-login` regression fails on staging's server code and passes with this branch. - Playwright `bot-browser-pygmalion-login` and `bot-browser-download`: 12/12 passed on desktop-chromium, mobile-chromium and mobile-webkit. - Local CodeRabbit review: not run yet. ### Manual verification notes - [ ] Manually verify that pasting a real Pygmalion `authn` token (with and without `Bearer `) logs in and shows NSFW results. - [ ] Manually verify that a wrong token shows "Pygmalion rejected the token." and leaves you logged out. - [ ] Manually verify that the token field hides its contents and the new sentence is readable in light and dark themes and on a phone-width window. - [ ] Manually verify that after restarting the server, reopening the Card Browser shows the "session expired" toast and **Log In**. - [ ] Manually verify that Pygmalion avatars still load in results and in the detail view. This change refuses redirects that leave the avatar's host. - [ ] Manually verify that **Log Out** clears the session and **Log In** appears again. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) Changed docs: `CHANGELOG.md` and `docs/characters/bot-browser.md`. The translated `characters/bot-browser.md` copies on `docs-i18n` still need updating, or a `[docs-i18n] docs/characters/bot-browser.md` follow-up issue. ## UI evidence (if applicable) - Login window screenshot: attached by the e2e run as `pygmalion-login-modal.png`. Add a before/after screenshot here. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added Pygmalion token validation with clear messages for rejected tokens, unavailable service, and busy service. * Prompt users to log in again when their Pygmalion session expires while browsing. * **Bug Fixes** * Improved token privacy in the login field and error messages. * Restricted Pygmalion requests and avatar loading to trusted Pygmalion servers. * Clarified that login remains in memory until restart or log out, and that full sign-out also requires logging out on pygmalion.chat. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:20:03 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#7465
No description provided.