-
Notifications
You must be signed in to change notification settings - Fork 39
Sanitize gRPC API error responses to prevent exposure of internal error details in the logging interceptor #728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Warning Rate limit exceeded@mkysel has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 7 minutes and 35 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (3)
""" WalkthroughThe changes introduce a new error sanitization mechanism for gRPC server interceptors to prevent internal error details from being exposed to clients. A Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant gRPCServer
participant LoggingInterceptor
participant Metrics
Client->>gRPCServer: Send gRPC request
gRPCServer->>LoggingInterceptor: Handle request
LoggingInterceptor->>LoggingInterceptor: Process request
LoggingInterceptor->>LoggingInterceptor: If error, call sanitizeError()
LoggingInterceptor->>Metrics: EmitNewFailedGRPCRequest(code)
LoggingInterceptor->>gRPCServer: Return sanitized error
gRPCServer->>Client: Respond with sanitized error
Assessment against linked issues
Suggested reviewers
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Prevent exposure of internal error details by sanitizing gRPC API error responses in the logging interceptor
📍Where to StartStart with the Macroscope summarized 35c60d5. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (2)
pkg/metrics/api.go (1)
84-87: Guardrail: accept only valid gRPC codes or use the typed enum
EmitNewFailedGRPCRequesttakes a free‑form string. A mistyped value elsewhere would silently create a new label series, inflating cardinality.
Consider either:
- Accepting a
codes.Codeand calling.String()inside the function, or- Asserting/parsing the provided string against the small, fixed set of gRPC codes.
Example (option 1):
-func EmitNewFailedGRPCRequest(code string) { - apiFailedGRPCRequests.With(prometheus.Labels{"code": code}).Inc() +func EmitNewFailedGRPCRequest(code codes.Code) { + apiFailedGRPCRequests.WithLabelValues(code.String()).Inc() }This guarantees label values remain within the expected ~15‑code cardinality.
doc/metrics_catalog.md (1)
3-3: Update catalog after metric renameAfter renaming the metric to
xmtp_api_failed_grpc_requests_counter, reflect the change here to keep the documentation authoritative.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
doc/metrics_catalog.md(1 hunks)pkg/interceptors/server/logging.go(3 hunks)pkg/metrics/api.go(2 hunks)pkg/metrics/metrics.go(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
pkg/interceptors/server/logging.go (1)
pkg/metrics/api.go (1)
EmitNewFailedGRPCRequest(84-87)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: Push Docker Images to GitHub Packages (xmtpd-cli)
- GitHub Check: Push Docker Images to GitHub Packages (xmtpd)
- GitHub Check: Test (Node)
- GitHub Check: Upgrade Tests
🔇 Additional comments (1)
pkg/metrics/metrics.go (1)
89-90: Follow‑up required if metric is renamedIf you adopt the
_countersuffix (see earlier comment), remember to update this reference (apiFailedGRPCRequests) or you will panic at startup with “collector already registered” / “nil reference” errors.
Fixes #727
Summary by CodeRabbit
New Features
Documentation