Highlights
This patch release hardens how the secrets sources read files from secrets_dir, and fixes several cases where a lower-priority source, or input that should have been rejected, could set a value in the CLI source, CliApp and the GCP Secret Manager source. These issues were reported by Anthropic's OSS Scanner.
Hardening
- The secrets sources read exactly the file they checked (#1189).
SecretsSettingsSourceandNestedSecretsSettingsSourcechecked that a secret file stays insidesecrets_diron one path but then read another, so in some cases a file outsidesecrets_dircould still be loaded despite the fixes in 2.14.2 and 2.16.3. Paths are now resolved strictly and the resolved path is read; on POSIX, files are opened belowsecrets_dirwithout following symlinks. secrets_dir_max_sizeis enforced on the bytes actually read byNestedSecretsSettingsSource(#1189). The limit was only checked in an earlier pass, so a file that grew after that check was read whole.- The nested secrets walk is bounded (#1189). Hidden entries now count toward the 10,000-entry limit, and link chains longer than the OS follows are skipped, so a crafted tree can no longer stall loading.
CliApp.runhonorshide_input_in_errorson pydantic dataclasses (#1185). Validation errors showed the rejected input, which could include secrets.- A nested AliasPath CLI option can no longer set sibling fields (#1185). The option's value is now required to be a single JSON value.
Behavior changes
- An explicit empty CLI argument (
--x ''or--x=) is kept as an empty value whenenv_ignore_empty=True, instead of falling back to the environment or the default (#1185). For a non-string field this now fails validation. - A value for a nested AliasPath-only CLI option that isn't a single JSON value raises
SettingsError(#1185). - With
case_sensitive=False, the GCP Secret Manager source uses an exactly named secret over its case variants, as documented. The mapping also lists each secret once, under its lower-cased name (#1186). Settings(_env_prefix=...),_case_sensitive,_env_nested_delimiter,_env_prefix_targetand_env_nested_max_splitnow apply toNestedSecretsSettingsSource, as they already did toSecretsSettingsSource(#1189).- In
SecretsSettingsSource, a broken or unresolvable link now warns that it "could not be resolved" instead of raisingAssertionError, and a link pointing outsidesecrets_dirwarns that it "resolves outside" it. Hidden entries count towardNestedSecretsSettingsSource's 10,000-entry limit (#1189).
Bug fixes
CLI
CliApp.runwith a plain model or dataclass no longer lets environment, dotenv or secrets values override a CLI or init value that equals a nested default (#1185).
GCP Secret Manager
- With
case_sensitive=Falseandenv_nested_delimiter, a differently cased secret no longer overrides the exactly named one for nested fields (#1186). - A secret that is listed but can't be read is treated as unset for nested fields, as it already was for top-level ones, instead of setting the field to
None. A listed secret with nolatestversion no longer makesSettings()fail withKeyErrorin case-sensitive mode (#1188).
Secrets
NestedSecretsSettingsSourcereads secret files named with the prefix passed toSettings()(#1189).
Credits
Reported by Anthropic's OSS Scanner (ANT-2026-03GATVJT, ANT-2026-KXOQMCIZ, ANT-2026-QBDWOPPZ, ANT-2026-Q9SXL4RQ, ANT-2026-J8TUO8VX, ANT-2026-KEND8WE6, ANT-2026-AR6U1329, ANT-2026-0SIM76GZ, ANT-2026-KCDOIFJQ, ANT-2026-WTKAUT7V, ANT-2026-1HJFYVIH).
Full Changelog: v2.16.3...v2.16.4
All changes
What's Changed