API inputs that take an enum as text accept member names only #296

Closed
opened 2026-11-05 07:51:16 -05:00 by claude · 0 comments
Owner
  • Priority: low (the console sends valid names; an API caller can store undefined values)
  • Agent: coder
  • Depends on: #31
  • Decisions: follows Q-REL-5 ("names only") for every enum the API takes as text

Why

Several API inputs parse enum text with Enum.TryParse and no IsDefined check. They accept digit strings, including numbers that are not members. #31 fixed this for access-control capabilities.

Site Request field Problem
DhcpTagRulesController.cs ParseMatchMode vendorClassMatchMode, userClassMatchMode "5" is stored as an undefined Dhcpv4TagMatchModeEnum
RecursiveSettingsController.cs trust-anchor override trustAnchorsOverride[].algorithm "200" is accepted as a DnssecAlgorithmEnum
WebListenSettingsController.cs and TransportSettingsController.cs certificate.allowedProtocols[] SslProtocols is a flags enum: digits, masks such as "3072" and "Tls12, Tls13" in one entry pass, and digits are written back as numbers
TransportSettingsController.cs DNSCrypt enabledEsVersions[] "99" passes, and the original text is stored as sent
QueryLogController.cs TryParseOptionalEnum queriedType, responseCode, clientProtocolVersion query filters "99" passes. As a read filter it only matches nothing, so this one is the lowest priority. Its EnumMember wire-name fallback must stay.

What changes

  • One shared helper that accepts an exact member name, case-insensitive where the field already accepts that today. It refuses digit strings, undefined values and (for flags enums) anything but a single named member.
  • Use the helper at each site, with a 400 that lists the valid names, like #31.
  • Store the canonical name where text is persisted.
  • Whether to refuse the obsolete SslProtocols members (Ssl2, Ssl3, Tls, Default) is a separate question: keep today's behaviour for them and say so.

Acceptance

  • Web.Tests, red first: a digit string and an undefined number give 400 at each persisted site, and every valid name is still accepted.
  • OpenApiSnapshotTests passes, or api-regen follows in the same PR if a model's text changes.

Source

Found by the verifier on #31.

- **Priority:** low (the console sends valid names; an API caller can store undefined values) - **Agent:** coder - **Depends on:** #31 - **Decisions:** follows Q-REL-5 ("names only") for every enum the API takes as text ### Why Several API inputs parse enum text with `Enum.TryParse` and no `IsDefined` check. They accept digit strings, including numbers that are not members. #31 fixed this for access-control capabilities. | Site | Request field | Problem | |---|---|---| | `DhcpTagRulesController.cs` `ParseMatchMode` | `vendorClassMatchMode`, `userClassMatchMode` | `"5"` is stored as an undefined `Dhcpv4TagMatchModeEnum` | | `RecursiveSettingsController.cs` trust-anchor override | `trustAnchorsOverride[].algorithm` | `"200"` is accepted as a `DnssecAlgorithmEnum` | | `WebListenSettingsController.cs` and `TransportSettingsController.cs` | `certificate.allowedProtocols[]` | `SslProtocols` is a flags enum: digits, masks such as `"3072"` and `"Tls12, Tls13"` in one entry pass, and digits are written back as numbers | | `TransportSettingsController.cs` DNSCrypt | `enabledEsVersions[]` | `"99"` passes, and the original text is stored as sent | | `QueryLogController.cs` `TryParseOptionalEnum` | `queriedType`, `responseCode`, `clientProtocolVersion` query filters | `"99"` passes. As a read filter it only matches nothing, so this one is the lowest priority. Its EnumMember wire-name fallback must stay. | ### What changes - One shared helper that accepts an exact member name, case-insensitive where the field already accepts that today. It refuses digit strings, undefined values and (for flags enums) anything but a single named member. - Use the helper at each site, with a 400 that lists the valid names, like #31. - Store the canonical name where text is persisted. - Whether to refuse the obsolete `SslProtocols` members (`Ssl2`, `Ssl3`, `Tls`, `Default`) is a separate question: keep today's behaviour for them and say so. ### Acceptance - [ ] Web.Tests, red first: a digit string and an undefined number give 400 at each persisted site, and every valid name is still accepted. - [ ] `OpenApiSnapshotTests` passes, or api-regen follows in the same PR if a model's text changes. ### Source Found by the verifier on #31.
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
lantea-one/ninlil#296
No description provided.