Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Opt-in process metrics (`PAPERCUT_METRICS=1`) — `GET /api/metrics` counters only (`pastes_created`, `unlocks_ok`, `rate_limited`); disabled by default; no content/IP logging
- Log canvas **wrap / no-wrap** toggle (dense horizontal scroll), sticky line-number gutter, preference in `localStorage`

### Fixed

- Theme FOUC boot script is a static string (no `JSON.stringify` interpolation) to clear CodeQL `js/bad-code-sanitization`

### Planned

See [ROADMAP.md](./ROADMAP.md) (dependency updates, canvas tools, scale features, etc.).
Expand Down
7 changes: 5 additions & 2 deletions server/lib/theme.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { isTheme, THEME_STORAGE_KEY } from "./theme";
import { isTheme, THEME_BOOT_SCRIPT, THEME_STORAGE_KEY } from "./theme";

describe("theme helpers", () => {
it("accepts only dark and light", () => {
Expand All @@ -10,7 +10,10 @@ describe("theme helpers", () => {
expect(isTheme(null)).toBe(false);
});

it("uses a stable storage key", () => {
it("uses a stable storage key shared by the FOUC boot script", () => {
expect(THEME_STORAGE_KEY).toBe("papercut-theme");
// Boot script embeds the key as a static literal (no code construction).
expect(THEME_BOOT_SCRIPT).toContain(`localStorage.getItem("${THEME_STORAGE_KEY}")`);
expect(THEME_BOOT_SCRIPT).toContain('setAttribute("data-theme"');
});
});
9 changes: 7 additions & 2 deletions server/lib/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,10 @@ export function resolveInitialTheme(): Theme {
return readStoredTheme() ?? "dark";
}

/** Inline script: set data-theme before paint (no FOUC). */
export const THEME_BOOT_SCRIPT = `(function(){try{var k=${JSON.stringify(THEME_STORAGE_KEY)};var t=localStorage.getItem(k);if(t!=="light"&&t!=="dark")t="dark";document.documentElement.setAttribute("data-theme",t);}catch(e){document.documentElement.setAttribute("data-theme","dark");}})();`;
/**
* Inline script: set data-theme before paint (no FOUC).
* Fully static string (no interpolation) so CodeQL js/bad-code-sanitization stays clean.
* The localStorage key literal must stay equal to THEME_STORAGE_KEY.
*/
export const THEME_BOOT_SCRIPT =
'(function(){try{var t=localStorage.getItem("papercut-theme");if(t!=="light"&&t!=="dark")t="dark";document.documentElement.setAttribute("data-theme",t);}catch(e){document.documentElement.setAttribute("data-theme","dark");}})();';
Loading