[PR #8886] [MERGED] fix(server): close the open code scanning alerts before v2.5.2 #8861

Closed
opened 2026-11-07 17:40:18 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: staging ← Head: fix/v252-codeql-hardening


📝 Commits (1)

  • 5302ba0 fix(server): keep two upload paths inside their folders and two text cleanups linear

📊 Changes

4 files changed (+20 additions, -9 deletions)

View changed files

📝 packages/server/src/routes/characters.routes.ts (+5 -1)
📝 packages/server/src/routes/sprites.routes.ts (+4 -3)
📝 packages/server/src/services/image/image-generation.ts (+2 -1)
📝 packages/shared/src/utils/sprite-labels.ts (+9 -4)

📄 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 #8885

Part of the v2.5.2 release (#8877).

Why this change

The promotion PR #8878 fails its CodeQL check. The open alerts are already on staging and would carry into main. Each one was traced from source to sink before changing anything:

  • #680, character gallery folders: the folder is built from the stored character id with no check, unlike persona gallery folders. Stored ids aren't always app-made, because a profile import or Mari can store any id. The file was written before the later image check refused it.
  • #712 and #713, sprite rename: the route relied only on its zod check, which CodeQL doesn't model. The sprite upload and delete routes beside it use basename and assertInsideDir. No request reached outside DATA_DIR/sprites in testing, so this brings the route in line with its siblings.
  • #714 and #715, text cleanup: the NovelAI V4 prompt cleanup (\s*\n\s*) and the sprite label trim (^[.\s_-]+|[.\s_-]+$) take time that grows with the square of a long run. A 50,000-character run blocks the server for about 1.5 s on an Apple M4. Both patterns predate this release.

What changed

  • ensureCharacterGalleryDir refuses an unsafe id and checks containment, the same way ensurePersonaGalleryDir does. That covers gallery upload and bake.
  • The sprite rename route uses basename on the owner id and checks the folder with assertInsideDir, the same pattern as the upload and delete routes.
  • Sprite labels: the edge trim matches each separator run once and drops a run only at either end.
  • NovelAI V4 prompts: each whitespace run that contains a line break becomes one \n, matched once.
  • #681 is unchanged: a false positive, because the global rate-limit hook covers that route (the same as #433 and #434). It will be dismissed with that reason.

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

Manual verification notes

  • Manually verify that uploading a picture to a character's gallery, renaming a sprite and generating a NovelAI V4.5 image all still work.
  • Manually verify after merge that code scanning closes #680, #712, #713, #714 and #715 on staging.

Agent-run checks:

  • Server tsc --noEmit and Prettier on the four files: pass.
  • node ./scripts/run-regressions.mjs with the sprite (7/7), gallery (7/7), novelai (2/2), image (30/30) and character (31/31) filters: all pass.
  • The old and new cleanup patterns give the same output on 200,000 generated inputs. At 50,000 characters, the sprite label trim goes from 1,475 ms to under 1 ms, and the NovelAI cleanup from 1,457 ms to under 1 ms.
  • Independent review of #680 and #712/#713: both patches judged minimal and correct. The reviewer also showed that the gallery guard refuses a traversal id that stays inside the gallery folder, which the old check let through.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) 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)

🤖 Generated with Claude Code


🔄 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/8886 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 11/5/2026 **Status:** ✅ Merged **Merged:** 11/5/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/v252-codeql-hardening` --- ### 📝 Commits (1) - [`5302ba0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5302ba0f2ac40044c9a41f0a23bdfd436b6fa81c) fix(server): keep two upload paths inside their folders and two text cleanups linear ### 📊 Changes **4 files changed** (+20 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/characters.routes.ts` (+5 -1) 📝 `packages/server/src/routes/sprites.routes.ts` (+4 -3) 📝 `packages/server/src/services/image/image-generation.ts` (+2 -1) 📝 `packages/shared/src/utils/sprite-labels.ts` (+9 -4) </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 #8885 Part of the v2.5.2 release (#8877). ## Why this change The promotion PR #8878 fails its CodeQL check. The open alerts are already on staging and would carry into main. Each one was traced from source to sink before changing anything: - **#680, character gallery folders:** the folder is built from the stored character id with no check, unlike persona gallery folders. Stored ids aren't always app-made, because a profile import or Mari can store any id. The file was written before the later image check refused it. - **#712 and #713, sprite rename:** the route relied only on its zod check, which CodeQL doesn't model. The sprite upload and delete routes beside it use `basename` and `assertInsideDir`. No request reached outside `DATA_DIR/sprites` in testing, so this brings the route in line with its siblings. - **#714 and #715, text cleanup:** the NovelAI V4 prompt cleanup (`\s*\n\s*`) and the sprite label trim (`^[.\s_-]+|[.\s_-]+$`) take time that grows with the square of a long run. A 50,000-character run blocks the server for about 1.5 s on an Apple M4. Both patterns predate this release. ## What changed - `ensureCharacterGalleryDir` refuses an unsafe id and checks containment, the same way `ensurePersonaGalleryDir` does. That covers gallery upload and bake. - The sprite rename route uses `basename` on the owner id and checks the folder with `assertInsideDir`, the same pattern as the upload and delete routes. - Sprite labels: the edge trim matches each separator run once and drops a run only at either end. - NovelAI V4 prompts: each whitespace run that contains a line break becomes one `\n`, matched once. - #681 is unchanged: a false positive, because the global rate-limit hook covers that route (the same as #433 and #434). It will be dismissed with that reason. ## Validation <!-- These are human tasks. Never tick a box for a check that was not actually performed. --> - [ ] `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` ### Manual verification notes - Manually verify that uploading a picture to a character's gallery, renaming a sprite and generating a NovelAI V4.5 image all still work. - Manually verify after merge that code scanning closes #680, #712, #713, #714 and #715 on staging. Agent-run checks: - Server `tsc --noEmit` and Prettier on the four files: pass. - `node ./scripts/run-regressions.mjs` with the `sprite` (7/7), `gallery` (7/7), `novelai` (2/2), `image` (30/30) and `character` (31/31) filters: all pass. - The old and new cleanup patterns give the same output on 200,000 generated inputs. At 50,000 characters, the sprite label trim goes from 1,475 ms to under 1 ms, and the NovelAI cleanup from 1,457 ms to under 1 ms. - Independent review of #680 and #712/#713: both patches judged minimal and correct. The reviewer also showed that the gallery guard refuses a traversal id that stays inside the gallery folder, which the old check let through. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) 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) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 17:40:18 +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#8861
No description provided.