Commit Graph
4 Commits
Author SHA1 Message Date
Atif Ali f79a36469e fix: relax OAuth2 app form validation for names and callback URLs (#29333)
## Problem

The OAuth2 application settings form rejects application names with
spaces and callbacks using native application schemes. A VS Code
extension client registered through DCR exposed this: `VS Code Coder
Extension` and `vscode://coder.coder-remote/oauth/callback` were already
stored, but the admin form prevented editing them.

## Fix

- Allow application names with spaces and punctuation, limited to 64
UTF-8 bytes on both client and server.
- Allow native callback schemes while rejecting dangerous schemes,
unsupported URNs, opaque callbacks such as `localhost:3000`, and empty
targets such as `vscode:`. HTTP(S) callbacks still require a host.
- Reuse the public-client registration policy when admins update public
clients, so `mailto`, `tel`, `sms`, external HTTP, and fragments remain
rejected.
- Trim surrounding whitespace from names and callbacks when submitting,
without stripping spaces while typing.
- Update the admin API request validators too, so accepted form values
can be saved.

The server remains authoritative for URL parsing. Public-client edits
reuse the existing DCR redirect validator using the stored client type;
confidential admin-created applications retain their existing HTTP
policy. Native host/path callbacks and the supported OOB URN remain
accepted.

## Validation

- Vitest component tests assert create/edit submission payloads,
whitespace normalization, Unicode byte limits, and rejection of unsafe
or malformed callbacks.
- Storybook stories cover accepted native-client values and invalid
callback states.
- Go tests cover name boundaries and accepted/rejected callback values
through both admin create and update requests.
- `make pre-commit` and targeted tests run before pushing; CI checked on
each revision.

<details>
<summary>Implementation decisions</summary>

- Replace the shared slug validator only for OAuth2 application names;
leave user, workspace, and template names unchanged.
- Share the backend's 64-byte name limit with the frontend through the
generated `OAuth2AppNameMaxBytes` constant.
- Reuse `codersdk.ValidateRedirectURIScheme` for common admin callback
validation. Public-client updates additionally call
`codersdk.ValidateRedirectURIs`; confidential admin HTTP behavior is
preserved.
- Normalize name and callback whitespace in the submitted payload rather
than on each keystroke.
- Keep behavior assertions in Vitest and use Storybook for visual
states.

</details>

Closes ENG-3342

> 🤖 This PR was created with the help of Coder Agents, and needs a human
review. 🧑💻
2026-09-16 21:06:31 +05:00
Zach 091d31224d fix: replace moby/moby namesgenerator with internal implementation (#21377)
Replace the external moby/moby/pkg/namesgenerator dependency with an
internal implementation using gofakeit/v7. The moby package has ~25k
unique name combinations, and with its retry parameter only adds a
random digit 0-9, giving ~250k possibilities. In parallel tests, this
has led to collisions (flakes).

The new internal API at coderd/util/namesgenerator eliminates the
external dependnecy and offers functions with explicit uniqueness
guarantees. This PR also consolidates fragmented name generation in a
few places to use the new package.

| Old (moby/moby)                     | New                    |
|-------------------------------------|------------------------|
| namesgenerator.GetRandomName(0)     | NameWith("_")          |
| namesgenerator.GetRandomName(>0)    | NameDigitWith("_")     |
| testutil.GetRandomName(t)           | UniqueName()           |
| testutil.GetRandomNameHyphenated(t) | UniqueNameWith("-")    |

namesgenerator package API:
- NameWith(delim): random name, not unique
- NameDigitWith(delim): random name with 1-9 suffix, not unique
- UniqueName(): guaranteed unique via atomic counter
- UniqueNameWith(delim): unique with custom delimiter

Names continue to be docker style `[adjective][delim][surname]`. Unique
names are truncated to 32 characters (preserving the numeric suffix) to
fit common name length limits in Coder.

Related test flakes:
https://github.com/coder/internal/issues/1212
https://github.com/coder/internal/issues/118
https://github.com/coder/internal/issues/1068
2026-01-09 15:40:26 -07:00
Bruno Quaresma 7f510051fb refactor: increase group name limit to 255 (#15377)
Close https://github.com/coder/coder/issues/15184
2024-11-06 14:39:50 -03:00
Ethan 01a904c133 feat(codersdk): export name validators (#14550)
* feat(codersdk): export name validators

* review
2024-09-04 18:17:53 +10:00