chore: Better enforcement of masking#7967
Conversation
Greptile OverviewGreptile SummaryThis PR introduces a comprehensive static-time enforcement mechanism for masking sensitive fields by wrapping all encrypted database fields in a Key Changes:
Impact: Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant API as API Endpoint
participant DB as Database Layer
participant Model as SQLAlchemy Model
participant SV as SensitiveValue
participant Enc as Encryption Utils
participant Consumer as Backend Consumer
Note over API,Consumer: Writing Sensitive Data Flow
API->>Model: Set credential_json = {"api_key": "secret"}
Model->>Enc: encrypt_string_to_bytes(json_str)
Enc-->>Model: encrypted_bytes
Model->>DB: Store encrypted_bytes
Note over API,Consumer: Reading Sensitive Data Flow (API Response)
DB->>Model: Load encrypted_bytes
Model->>SV: Create SensitiveValue(encrypted_bytes, decrypt_fn)
SV-->>Model: SensitiveValue wrapper
Model-->>API: credential.credential_json (SensitiveValue)
API->>SV: get_value(apply_mask=True)
SV->>Enc: mask_credential_dict(decrypted_value)
Enc-->>SV: masked_value
SV-->>API: Return masked credentials
API-->>API: Send to client (safe)
Note over API,Consumer: Reading Sensitive Data Flow (Backend Use)
DB->>Model: Load encrypted_bytes
Model->>SV: Create SensitiveValue(encrypted_bytes, decrypt_fn)
SV-->>Model: SensitiveValue wrapper
Model-->>Consumer: credential.credential_json (SensitiveValue)
Consumer->>SV: get_value(apply_mask=False)
SV->>Enc: decrypt_bytes_to_string(encrypted_bytes)
Enc-->>SV: decrypted_value
SV-->>Consumer: Return raw credentials
Consumer-->>Consumer: Use for API calls
Note over API,Consumer: Error Prevention
API->>SV: str(sensitive_value) ❌
SV-->>API: SensitiveAccessError
API->>SV: sensitive_value["key"] ❌
SV-->>API: SensitiveAccessError
|
There was a problem hiding this comment.
1 issue found across 61 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="backend/onyx/tools/tool_implementations/mcp/mcp_tool.py">
<violation number="1" location="backend/onyx/tools/tool_implementations/mcp/mcp_tool.py:147">
P2: Filter denylisted headers from connection config before updating `headers`; otherwise a user-supplied Host header can still bypass the denylist.
(Based on your team's feedback about denying Host headers in MCP headers.) [FEEDBACK_USED]</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
evan-onyx
left a comment
There was a problem hiding this comment.
make sure u fix tests before merging but approach looks fine
ad8dbab to
6ce1c4a
Compare
ce9227f to
9358a84
Compare
e8ee796 to
11d4036
Compare
Description
Standardizing masking of sensitive fields. This static time check now prevents developers from forgetting to mask fields as the value is unusuable and will now raise an error if not explicitly extracted with either a mask applied or not.
How Has This Been Tested?
Test setting/updating LLM keys
Test setting/updating web search keys
Test setting/updating connector credentials
Test Inference flow with tools
Additional Options
Summary by cubic
Enforces explicit masking for all secrets by wrapping encrypted columns with SensitiveValue. Backend code unwraps for internal use; API responses mask by default across connectors, OAuth, bots, KV, MCP, tools, and manage/federated APIs.
New Features
Migration
Written for commit c6bb925. Summary will update on new commits.