fix: skip plaintext fallback lookup for secret-based virtual key values - #4927
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughSecret reference parsing now happens without side effects, and virtual key lookups in the config store return ChangesSecret reference lookup fix
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Comment |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
b407486 to
3c3e488
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
framework/configstore/rdb.go (2)
3300-3311: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd table-driven test coverage for the new short-circuit branch.
No test changes accompany this behavior change. This is a security/auth-adjacent lookup path (virtual key resolution), and the new early-return branch (secret-referenced value → immediate
ErrNotFound, skipping plaintext fallback) is exactly the kind of behavior change that should have dedicated coverage — e.g. cases for: secret-formatted value with no hash match, plain legacy value with no hash match (still falls back), and a value matching both hash and legacy row.As per path instructions,
framework/**changes should include "tests that cover edge cases and failure paths," and per coding guidelines,**/*.gochanges should have "table-driven coverage for behavior changes."Also applies to: 3330-3341
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@framework/configstore/rdb.go` around lines 3300 - 3311, Add table-driven tests for the virtual key lookup behavior in rdb.go around the virtual key resolution path, especially the new early-return branch in the value_hash lookup flow. Cover at least: a secret-formatted value with no hash match returning ErrNotFound without falling back to plaintext, a plain legacy value with no hash match still falling back to the value lookup, and a value that can match both hashed and legacy rows preferring the hash match. Place the coverage near the existing lookup tests for the relevant resolver/query logic so the behavior of the short-circuit branch is locked in.Sources: Coding guidelines, Path instructions
3302-3302: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueLocal variable
sshadows the method receivers *RDBConfigStore.Both
GetVirtualKeyByValueandGetVirtualKeyQuotaByValueusesas the receiver name; the newif s := schemas.NewSecretVar(value); ...redeclaressinside that scope. Harmless today since onlyreturnexecutes in that block, but it's a common source of confusion/bugs if the branch is extended later.♻️ Suggested rename to avoid shadowing
- if s := schemas.NewSecretVar(value); s != nil && s.IsFromSecret() { + if sv := schemas.NewSecretVar(value); sv != nil && sv.IsFromSecret() { return nil, ErrNotFound }Also applies to: 3332-3332
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@framework/configstore/rdb.go` at line 3302, The new local variable named s in GetVirtualKeyByValue and GetVirtualKeyQuotaByValue shadows the RDBConfigStore receiver s, which makes the block harder to read and can cause confusion if the branch grows later. Rename the local result from schemas.NewSecretVar(value) to a non-conflicting identifier in both methods and keep the existing secret check/return behavior unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@framework/configstore/rdb.go`:
- Around line 3302-3304: Add table-driven tests for GetVirtualKeyByValue and
GetVirtualKeyQuotaByValue to cover secret-backed inputs and the plaintext
fallback path. Verify that env.* and vault.* values are treated as secret-backed
via schemas.NewSecretVar and return ErrNotFound without falling back to
plaintext matching, while a normal plaintext virtual key row still resolves
successfully. Use the existing lookup helpers and virtual key/quota lookup
functions to keep the test anchored to the current behavior.
---
Nitpick comments:
In `@framework/configstore/rdb.go`:
- Around line 3300-3311: Add table-driven tests for the virtual key lookup
behavior in rdb.go around the virtual key resolution path, especially the new
early-return branch in the value_hash lookup flow. Cover at least: a
secret-formatted value with no hash match returning ErrNotFound without falling
back to plaintext, a plain legacy value with no hash match still falling back to
the value lookup, and a value that can match both hashed and legacy rows
preferring the hash match. Place the coverage near the existing lookup tests for
the relevant resolver/query logic so the behavior of the short-circuit branch is
locked in.
- Line 3302: The new local variable named s in GetVirtualKeyByValue and
GetVirtualKeyQuotaByValue shadows the RDBConfigStore receiver s, which makes the
block harder to read and can cause confusion if the branch grows later. Rename
the local result from schemas.NewSecretVar(value) to a non-conflicting
identifier in both methods and keep the existing secret check/return behavior
unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: ff2bd17f-0efc-4ca1-94e1-983f41640297
📒 Files selected for processing (1)
framework/configstore/rdb.go
3c3e488 to
87a6943
Compare

Summary
Prevents plaintext database fallback lookups when a virtual key value appears to be a secret reference (e.g., a vault or environment variable reference). Without this guard, a value like
vault.my-secretorenv.MY_VARwould be passed as a raw string into aWHERE value = ?query, which could never match a real row but still leaks information about the lookup path and wastes a database round-trip.Changes
GetVirtualKeyByValue, when a hash-based lookup returns no record, the value is parsed as aSecretVar. If it originates from a secret reference, the function returnsErrNotFoundimmediately instead of falling back to a plaintext query.GetVirtualKeyQuotaByValue, the same early-exit behavior is applied by checking forvault.andenv.prefixes directly, consistent with the rationale inGetVirtualKeyByValue.Type of change
Affected areas
How to test
go test ./framework/configstore/...vault.<secret-name>orenv.<VAR_NAME>.Breaking changes
Security considerations
Secret references (vault/env-style values) should never be stored or queried as plaintext in the database. Allowing them to reach a
WHERE value = ?clause could expose the reference string in query logs or slow query logs. This change ensures such values are short-circuited before any plaintext lookup occurs.Checklist
docs/contributing/README.mdand followed the guidelines