feat: add secret value and file path validation (#24269)

Add secret value validation to reject null bytes and values exceeding 32KB.
The 32KB limit applies uniformly to both env var and file secrets because the
value field is shared and the destination can change after creation.

Add file path validation to also reject null bytes and paths exceeding 4096
bytes.

Wire up secret value validation into both POST and PATCH handlers.
This commit is contained in:
Zach
2026-04-13 07:24:34 -06:00
committed by GitHub
parent 6ab30123bf
commit 4854f33678
5 changed files with 161 additions and 5 deletions
+14
View File
@@ -4416,6 +4416,20 @@ export interface MatchedProvisioners {
*/
export const MaxChatFileIDs = 20;
// From codersdk/usersecretvalidation.go
/**
* MaxSecretValueSize is the maximum size of a user secret value
* in bytes. This limit applies uniformly to both env var and
* file-destined secrets because the value field is shared and
* the destination can change after creation. 32KB is generous
* for env vars (most are under 1KB) but necessary for file
* content like SSH keys, TLS certificate chains, and JSON
* configs. We are not trying to be overly restrictive here;
* users can use the full 32KB for env var values even though
* it would be unusual.
*/
export const MaxSecretValueSize = 32768; // 32KB
// From codersdk/organizations.go
export interface MinimalOrganization {
readonly id: string;