Skip to content

feat(secrets): validate device identifier format before use in paths - #2874

Open
rsdmike wants to merge 1 commit into
mainfrom
validate-device-identifier-format
Open

feat(secrets): validate device identifier format before use in paths#2874
rsdmike wants to merge 1 commit into
mainfrom
validate-device-identifier-format

Conversation

@rsdmike

@rsdmike rsdmike commented Aug 19, 2026

Copy link
Copy Markdown
Member

Device identifiers arriving on the websocket were only checked for length. Add a format check so identifiers are limited to alphanumerics, dots, hyphens, and underscores before they are used to build secret-provider and MPS device paths.

The format check is kept separate from the length check so a future identifier scheme can change the expected length without affecting it. A matching guard in VaultService validates the path it receives so a bad value surfaces immediately.

PR Checklist

  • Unit Tests have been added for new changes
  • API tests have been updated if applicable
  • All commented code has been removed
  • If you've added a dependency, you've ensured license is compatible with Apache 2.0 and clearly outlined the added dependency.

What are you changing?

Anything the reviewer should know when reviewing this PR?

If the there are associated PRs in other repositories, please link them here (i.e. device-management-toolkit/repo#365 )

Device identifiers arriving on the websocket were only checked for length.
Add a format check so identifiers are limited to alphanumerics, dots,
hyphens, and underscores before they are used to build secret-provider and
MPS device paths.

The format check is kept separate from the length check so a future
identifier scheme can change the expected length without affecting it. A
matching guard in VaultService validates the path it receives so a bad
value surfaces immediately.
Copilot AI lite review requested due to automatic review settings August 19, 2026 21:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens handling of device identifiers received over the RPC WebSocket by validating the identifier format before it’s used to construct secret-provider (Vault) paths, and adds a Vault-side guard to fail fast on unsafe secret paths.

Changes:

  • Add a SAFE_IDENTIFIER regex check (plus a consecutive-dot guard) to Validator.verifyPayload for payload.uuid.
  • Add a assertSafeSecretPath guard in VaultService and call it before all Vault secret operations.
  • Add/extend unit tests covering valid UUIDs and multiple invalid-character/path-injection patterns.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/Validator.ts Adds identifier-format validation for payload.uuid beyond length checks.
src/validator.test.ts Adds tests for valid UUID and invalid-character UUID inputs.
src/secrets/vault/index.ts Introduces assertSafeSecretPath and applies it to Vault secret operations.
src/secrets/vault/index.test.ts Adds coverage for assertSafeSecretPath allow/deny behavior and provider rejection of malformed paths.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +20 to +24
path.startsWith('/') ||
path.includes('#') ||
path.includes('?') ||
path.includes('\\') ||
path.includes('%') ||
Comment thread src/Validator.ts
import { type Configurator } from './Configurator.js'
import { type DeviceCredentials } from './interfaces/ISecretManagerService.js'

// device identifiers are alphanumerics, dots, hyphens, and underscores
Comment thread src/validator.test.ts
Comment on lines +233 to +237
['../profiles/default#xxxxxxxxxxxxxxxx', 'slash and hash'],
['../certs/acm-domain#xxxxxxxxxxxxxxxx', 'slash characters'],
['..%2fprofiles%2fdefault#xxxxxxxxxxxx', 'percent character'],
['4bac9510-04a6-4321-bae2-d45ddf07b6#4', 'hash character'],
['4bac9510-04a6-4321-bae2-d45ddf07b6?4', 'question mark']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants