fix: use policy engine in oauth whitelist check#904
Conversation
📝 WalkthroughWalkthroughPolicyEngine becomes an explicit dependency of AuthService. A new EvaluateFunc helper method converts effect callbacks to access decisions. Email whitelist evaluation now delegates to PolicyEngine instead of direct filtering, with ErrFilterEmpty sentinel error consolidating filter validation. Service bootstrap and tests wire the policyEngine dependency into AuthService construction. ChangesPolicyEngine Dependency and AuthService Integration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 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 |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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 `@internal/service/auth_service.go`:
- Around line 105-106: The AuthService constructor accepts a policy parameter
but does not validate it, which allows auth.policyEngine to be nil and causes a
panic when auth.policyEngine.EvaluateFunc (and related calls like IsWhitelisted)
are invoked; fix by validating the incoming policy in the constructor that
builds AuthService: if policy is nil assign a safe default/no-op PolicyEngine
implementation (or return an error from the constructor if your API permits) so
that auth.policyEngine is never nil, and also add a defensive nil-check before
calling auth.policyEngine.EvaluateFunc (and any whitelist checks) to avoid
dereferencing a nil pointer at runtime.
🪄 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: db842da7-2c75-4e7b-9e8d-09bc31b362aa
📒 Files selected for processing (7)
internal/bootstrap/service_bootstrap.gointernal/controller/proxy_controller_test.gointernal/controller/user_controller_test.gointernal/middleware/context_middleware_test.gointernal/service/auth_service.gointernal/service/policy_engine.gointernal/utils/security_utils.go
Summary by CodeRabbit