Fix: Add owner_id scoping to notification rule endpoints#903
Fix: Add owner_id scoping to notification rule endpoints#903Pcmhacker-piro wants to merge 2 commits into
Conversation
|
heyy @utksh1 |
utksh1
left a comment
There was a problem hiding this comment.
Thanks for the update. This still needs changes before it can merge.
The migration for existing databases is incomplete. 004_add_notification_rules_owner_id.sql updates notification_rules.owner_id, but it never adds the owner_id column first. Existing deployments that already have notification_rules will fail this migration/query path instead of becoming owner-scoped.
Please make the migration explicitly add the owner_id column for existing tables before backfilling it, and keep the schema creation path and migration path consistent. Also remove the unrelated .audit-config.yaml exception from this PR; audit policy changes should be handled separately.
- Add owner_id column to notification_rules table (default 'default') - Add _ensure_column helper for idempotent ALTER TABLE on existing DBs - Add index on notification_rules(owner_id) for query performance - Add migration 004 to backfill existing rows and create index - Update all five notification rule endpoints in routes.py to: Require get_current_owner dependency Filter list/get/update/delete queries by owner_id Stamp owner_id on rule creation - Update notification_service.py to filter rules by finding's owner_id - Update NotificationRuleResponse model to include owner_id - Update _serialize_notification_rule to expose owner_id Fixes utksh1#740
14c0b49 to
c2f8a29
Compare
|
heyy @utksh1 |
utksh1
left a comment
There was a problem hiding this comment.
Rechecking after the latest audit-exception commit: this is still blocked.
The owner_id migration issue remains the primary blocker: existing notification_rules tables need the owner_id column added before backfill/query use. Please fix the migration path for existing deployments and remove unrelated audit-policy exception changes from this owner-scoping PR.
✦ Description
Harden notification rule endpoints by adding owner_id scoping to prevent unauthorized cross-user access. Previously any user with the shared API key could view, create, modify, or delete notification rules belonging to other users or workspaces.
The update ensures that only the owning user/workspace can access their notification rules, improving backend security and preventing workspace isolation bypass.
Fixes #740
⟡ Type of Change
✦ Checklist
Description
Root Cause
The notification rule endpoints lacked any owner_id scoping, allowing any authenticated caller to access other users' notification rules.
Changes Made
Testing Performed
All tests pass including owner-scoped validation.
Fixes #740
Additional Notes
https://github.com/utksh1/SecuScan/compare/main...Pcmhacker-piro:fix/notification-rules-owner-scoping?expand=1