Skip to content

vault: validate encrypted value size in request validator#21760

Open
prashantkumar1982 wants to merge 2 commits intorelease/2.40.0from
codex/vault-encrypted-value-size-validation-2.40.0
Open

vault: validate encrypted value size in request validator#21760
prashantkumar1982 wants to merge 2 commits intorelease/2.40.0from
codex/vault-encrypted-value-size-validation-2.40.0

Conversation

@prashantkumar1982
Copy link
Copy Markdown
Contributor

Summary

  • enforce VaultCiphertextSizeLimit in the Vault request validator for create/update requests
  • reject oversized EncryptedValue payloads before label verification
  • add validator unit tests covering boundary and oversized ciphertext cases

Testing

  • go test ./core/capabilities/vault ./core/services/gateway/handlers/vault

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 27, 2026

✅ No conflicts with other open PRs targeting release/2.40.0

@github-actions
Copy link
Copy Markdown
Contributor

I see you updated files related to core. Please run make gocs in the root directory to add a changeset as well as in the text include at least one of the following tags:

  • #added For any new functionality added.
  • #breaking_change For any functionality that requires manual action for the node to boot.
  • #bugfix For bug fixes.
  • #changed For any change to the existing functionality.
  • #db_update For any feature that introduces updates to database schema.
  • #deprecation_notice For any upcoming deprecation functionality.
  • #internal For changesets that need to be excluded from the final changelog.
  • #nops For any feature that is NOP facing and needs to be in the official Release Notes for the release.
  • #removed For any functionality/config that is removed.
  • #updated For any functionality that is updated.
  • #wip For any change that is not ready yet and external communication about it should be held off till it is feature complete.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 06563543e1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if err != nil {
return nil, fmt.Errorf("could not create request batch size limiter: %w", err)
}
ciphertextLimiter, err := limits.MakeUpperBoundLimiter(limitsFactory, cresettings.Default.VaultCiphertextSizeLimit)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Close ciphertext limiter in vault capability lifecycle

NewCapability now creates a ciphertextLimiter, but Capability.Close() still only closes MaxRequestBatchSizeLimiter; this leaves the new limiter open for the lifetime of each start/stop cycle. In deployments where limiters maintain background state (tenant maps/watchers), repeated capability restarts will accumulate leaked resources and stale limit subscriptions. Please close MaxCiphertextLengthLimiter alongside the existing limiter in Close().

Useful? React with 👍 / 👎.

if err != nil {
return nil, fmt.Errorf("could not create request batch size limiter: %w", err)
}
ciphertextLimiter, err := limits.MakeUpperBoundLimiter(limitsFactory, cresettings.Default.VaultCiphertextSizeLimit)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Close ciphertext limiter when vault gateway handler stops

NewHandler now allocates a ciphertextLimiter, but handler.Close() still only closes writeMethodsEnabled and MaxRequestBatchSizeLimiter. That means every handler restart can leak the newly added limiter instance and any associated internal state, which is especially problematic for long-running nodes that reload handlers. Add MaxCiphertextLengthLimiter.Close() to the shutdown join.

Useful? React with 👍 / 👎.

@prashantkumar1982 prashantkumar1982 enabled auto-merge (squash) March 27, 2026 21:01
@trunk-io
Copy link
Copy Markdown

trunk-io bot commented Mar 27, 2026

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 26a1afb6f0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +415 to +417
ciphertextLimiter, err := limits.MakeUpperBoundLimiter(limitsFactory, cresettings.Default.VaultCiphertextSizeLimit)
if err != nil {
return nil, fmt.Errorf("could not create ciphertext size limiter: %w", err)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Close batch limiter on ciphertext limiter init failure

When MakeUpperBoundLimiter fails here, NewCapability returns without closing the already-created request batch limiter. Since these limiters are closable and may hold settings/watcher state, repeated startup retries can accumulate leaked resources. Close limiter on this error path before returning.

Useful? React with 👍 / 👎.

Comment on lines +200 to +202
ciphertextLimiter, err := limits.MakeUpperBoundLimiter(limitsFactory, cresettings.Default.VaultCiphertextSizeLimit)
if err != nil {
return nil, fmt.Errorf("could not create ciphertext size limiter: %w", err)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Close batch limiter if ciphertext limiter creation fails

This early return leaks the request batch limiter created just above when ciphertext limiter construction errors. In environments that retry handler initialization, this can leave stale limiter resources subscribed across attempts. Close the previously allocated limiter before returning this error.

Useful? React with 👍 / 👎.

@cl-sonarqube-production
Copy link
Copy Markdown

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.

4 participants