#5649: fix(security): harden file permissions and header merging
size: S
trusted-contributor
Cluster:
OpenClaw Plugin Enhancements
## Summary
Defensive security hardening for two low-severity issues.
## Changes
- Atomic file permissions in JSON writes (CWE-377)
- Filter prototype pollution keys in header merging (CWE-1321)
## Test plan
- [x] `pnpm lint` passes
- [x] `pnpm build` passes
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR hardens two security-sensitive areas:
- **JSON writes** (`src/infra/json-file.ts`): sets file mode during `writeFileSync` to reduce a race window where secrets could be briefly world-readable, with a best-effort `chmodSync` fallback.
- **Embedding client header merging** (`src/memory/embeddings*.ts`): replaces `Object.assign` with a dedicated `sanitizeHeaders()` helper that filters prototype-pollution keys when combining configured and remote header overrides.
The changes fit cleanly into existing infrastructure utilities (`saveJsonFile`) and the embeddings provider setup path (OpenAI/Gemini client resolution), without altering the higher-level provider selection logic.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- Changes are narrowly scoped, maintain existing behavior, and add defensive hardening in two well-defined places (file mode during writes and header merging). No functional regressions were identified in the modified code paths.
- No files require special attention
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#21964: Security: harden gateway and plugin trust boundaries
by Elormyevu · 2026-02-20
79.9%
#8988: fix: resolve security vulnerabilities in dependencies
by fotorpics · 2026-02-04
78.9%
#10745: feat: Security improvements and Windows compatibility fixes
by lluviaoscuradeldoce-design · 2026-02-06
78.5%
#8078: fix(config): add prototype pollution protection to deepMerge
by yubrew · 2026-02-03
78.3%
#23574: security: P0 critical remediation — plugin sandbox, password hashin...
by lumeleopard001 · 2026-02-22
78.2%
#17463: fix: write config files with explicit 0o600 mode instead of post-wr...
by miclaldogan · 2026-02-15
78.1%
#18924: fix(security): tighten permissions on cron/, browser/, settings/ dirs…
by rexlunae · 2026-02-17
77.8%
#22227: fix(security): harden gateway auth — audit logging, pairing, mode v...
by novalis133 · 2026-02-20
77.5%
#11048: fix: address repository issues (env, author, CI comments, security ...
by cavula · 2026-02-07
77.0%
#14197: fix(security): harden browser API auth, token comparisons, and hook...
by leecarollyn-gif · 2026-02-11
76.8%