mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-15 19:32:20 +03:00
Merged as part of the 39-PR owner batch of 2026-09-11, validated as a unit. Boarded into one consolidated worktree cut from `release/v3.8.51` with the other 38 — zero conflicts between them. - ESLint over every changed file: no errors (the only finding was one suppression entry the batch emptied, pruned on #13243) - `typecheck:core` clean; `check:dashboard-typecheck` OK (206 pre-existing, within baseline); `check:changelog-integrity` OK - complexity 2821 / baseline 3218 and cognitive-complexity 1272 / baseline 1437 — both under baseline - 256 assertions green: 246 under node:test and 10 under vitest, which is where `tests/unit/**/*.test.tsx` actually runs - `check-file-size`: `chatCore.ts` rebaselined 6144 → 6146 for #13278 and #13276, annotated and landed on #13243 ⚠️ base-red inherited: #12732 — the provider count (356 in the docs vs the 358 the modules define) and `open-sse/utils/stream.ts` at 3115 > frozen 3098 both reproduce on the pure tip with zero contribution from this batch.
26 lines
1.1 KiB
TypeScript
26 lines
1.1 KiB
TypeScript
/**
|
|
* Shared helpers for persisting credential/session material (tokens, cookie jars) to disk
|
|
* with restrictive permissions — 0700 directories, 0600 files — instead of inheriting the
|
|
* process umask (typically 0755/0644).
|
|
*
|
|
* Mirrors the established pattern in src/lib/vncSession/service.ts::createProfileDir.
|
|
* `chmodSync` is applied even on an already-existing directory so a dir created before this
|
|
* hardening (or by any looser writer) is tightened rather than silently trusted.
|
|
*/
|
|
|
|
import { chmodSync, mkdirSync, writeFileSync } from "node:fs";
|
|
|
|
const SECURE_DIR_MODE = 0o700;
|
|
const SECURE_FILE_MODE = 0o600;
|
|
|
|
/** Create `dir` (recursively) with 0700 permissions, tightening it if it already exists. */
|
|
export function ensureSecureDir(dir: string): void {
|
|
mkdirSync(dir, { recursive: true, mode: SECURE_DIR_MODE });
|
|
chmodSync(dir, SECURE_DIR_MODE);
|
|
}
|
|
|
|
/** Write `data` to `path` as utf8 with 0600 permissions. */
|
|
export function writeSecureFile(path: string, data: string): void {
|
|
writeFileSync(path, data, { encoding: "utf8", mode: SECURE_FILE_MODE });
|
|
}
|