feat(logging): add query parameter logging for /api/v2 requests - BED-8563#2895
feat(logging): add query parameter logging for /api/v2 requests - BED-8563#2895cami-specter wants to merge 7 commits into
Conversation
…uests - adds query parameters as structured slog attributes in LoggingMiddleware - only logs for /api/v2 endpoints with non-empty query strings - adds tests fixes: BED-8563
📝 WalkthroughWalkthrough
ChangesSSO Callback Query Parameter Logging Suppression
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@cmd/api/src/api/middleware/logging_test.go`:
- Line 28: The import statement in logging_test.go at line 28 references an
invalid module path `github.com/specterops/bloodhound/cmd/api/src/ctx` that does
not exist in the repository, causing compilation failures. Replace this import
statement with the correct request-context package path that is already used by
the middleware code in this repository. Additionally, update all references to
this context package in lines 105-109 to use the corrected import path so the
tests can compile successfully.
🪄 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: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: febec8aa-0b3e-483d-be6e-c7123e5de545
📒 Files selected for processing (2)
cmd/api/src/api/middleware/logging.gocmd/api/src/api/middleware/logging_test.go
superlinkx
left a comment
There was a problem hiding this comment.
This shows a lot of attention to detail and will make logging far more valuable
| return pathSegments[0] == "api" && | ||
| pathSegments[1] == "v2" && | ||
| pathSegments[2] == "sso" && | ||
| pathSegments[4] == "callback" | ||
| } |
There was a problem hiding this comment.
Wanted to note that there are old but still maintained due to still in use saml endpoints that likely also should be ignored and those are "versionless"
Further if sso is a concern, there is the sso/{id}/metadata endpoint as well. Might be worth considering a way to flag these in the route layer to be skipped 🤔 vs maintaining them here
mistahj67
left a comment
There was a problem hiding this comment.
Blocked to verify intent
mistahj67
left a comment
There was a problem hiding this comment.
approving to remove block. discussed offline. will likely benefit from a longer audit into logging queries. thank you for your patience and waiting 🙇
Description
Add query parameter logging for /api/v2 requests for easier Elastic/Kibana lookups. This logs the raw string and makes it easier to filter and search in Elastic without parsing the full request_uri field.
request_uri, it is probably better not to add them to the newquery_parametersfield.Note:
After some deliberation, decided not to add nested logging due to potential Elastic index mapping problems. (If we were to add a large list of parameters (in the hundreds) to our Elastic daily indexes mapping, that could cause issues – indexes are already > 1000).
Motivation and Context
Resolves BED-8563.
There's a general benefit to having query_parameters as a dedicated field since it makes it easier to filter and aggregate on query param usage across most endpoints.
Specifically, we were looking at non-default limit and skip parameters queries for the api/v2/search endpoint
How Has This Been Tested?
Screenshots (optional):
log output showing query_parameters field (/api/v2 request with a single parameter)
pretty print of the above log output (disabling text logging)
log output showing query_parameters field (/api/v2 request with multiple parameters)
Types of changes
Checklist:
Summary by CodeRabbit
Improvements
Tests