Commit 057024f
committed
fix(models-config): fail closed on oversized fingerprint reads (review feedback)
Codex P2 / Aisle medium #1 on PR #73260 flagged that `safeHashRegularFile`
returned a deterministic `oversize:${lst.size}` sentinel when a file
exceeded the cap, so an attacker could swap the *contents* of an oversized
`auth-profiles.json` or `models.json` without changing its byte length and
still hit the readyCache via the size-only sentinel comparison (CWE-345).
Switch to fail-closed:
- `safeHashRegularFile` now returns `null` for oversize at lstat time and
for grow-past-cap mid-read (the latter was already caught via the
destroy-with-error path; the JSDoc/comment now states that explicitly).
- The return type narrows from `{ hash; raw: Buffer | null } | null` to
`{ hash; raw: Buffer } | null` — the `raw === null` branch in
`readAuthProfilesStableHash` is now unreachable and removed.
- JSDoc on the helper and `readAuthProfilesStableHash` now describes the
fail-closed semantics and links them back to the threat model.
Also:
- Add a regression test that warms the cache with a small, hashable
`auth-profiles.json`, then grows it past `MAX_AUTH_PROFILES_BYTES`
(8 MiB) and asserts the implicit-provider-discovery pipeline re-runs
(i.e. the fingerprint changed instead of stably hitting an
`oversize:<size>` sentinel).
- Add the missing `Unreleased` CHANGELOG entry covering the
content-hashed fingerprint, post-write models.json drift hash, the
oversize fail-closed change, and the existing `O_NOFOLLOW`/streaming/
prototype-pollution hardening (Codex P3 on the same review).
- Backfill the new `resolveProviderEnvAuthEvidence`/
`listProviderEnvAuthLookupKeys`/`resolveProviderEnvAuthLookupKeys`
exports in the fingerprint test's `model-auth-env-vars.js` mock so the
suite runs at all after the recent `origin/main` merge added those
call sites in `model-auth-env.ts` / provider secret-helpers.
Validation (from
~/projects/worktrees/openclaw/perf-models-config-cache-fingerprint):
pnpm vitest run src/agents/models-config.fingerprint-cache.test.ts
Test Files 2 passed (2)
Tests 12 passed (12)
pnpm tsgo:core # 0 errors
pnpm tsgo:core:test # 0 errors
pnpm oxlint src/agents/models-config.ts \
src/agents/models-config.fingerprint-cache.test.ts
Found 0 warnings and 0 errors.
git diff --check # clean
Beads: openclaw-9i01 parent 7cd2e8a commit 057024f
3 files changed
Lines changed: 78 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
21 | 24 | | |
22 | 25 | | |
23 | 26 | | |
| |||
256 | 259 | | |
257 | 260 | | |
258 | 261 | | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
259 | 314 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
96 | 103 | | |
97 | 104 | | |
98 | 105 | | |
| |||
101 | 108 | | |
102 | 109 | | |
103 | 110 | | |
104 | | - | |
| 111 | + | |
105 | 112 | | |
106 | 113 | | |
107 | 114 | | |
108 | 115 | | |
109 | 116 | | |
110 | 117 | | |
111 | 118 | | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
116 | 124 | | |
117 | 125 | | |
118 | 126 | | |
| |||
140 | 148 | | |
141 | 149 | | |
142 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
143 | 154 | | |
144 | 155 | | |
145 | 156 | | |
| |||
161 | 172 | | |
162 | 173 | | |
163 | 174 | | |
164 | | - | |
165 | | - | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
166 | 180 | | |
167 | 181 | | |
168 | 182 | | |
169 | 183 | | |
170 | 184 | | |
171 | 185 | | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | 186 | | |
177 | 187 | | |
178 | 188 | | |
| |||
0 commit comments