[#1090][FIX] alerts: support updating IOCs via alert update routes - #1101
Open
Romil2112 wants to merge 1 commit into
Open
[#1090][FIX] alerts: support updating IOCs via alert update routes#1101Romil2112 wants to merge 1 commit into
Romil2112 wants to merge 1 commit into
Conversation
…routes POST /alerts/update/<id> and PUT /api/v2/alerts/<id> silently dropped alert_iocs because the field never reached the ORM — it was absorbed by the schema's unknown=EXCLUDE policy before the relationship could be set. Pop alert_iocs before schema load, then assign ioc_schema.load(iocs_list) to the alert's iocs relationship when the caller explicitly supplies the field. Omitting alert_iocs leaves existing IOCs unchanged; passing an empty list clears them.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1090.
POST /alerts/update/<id>andPUT /api/v2/alerts/<id>both silently ignoredalert_iocsin the request body. The field never reached the ORM:AlertSchemahasunknown = EXCLUDE, soalert_iocs— which doesn't match the schema'siocskey — was stripped before any relationship assignment could happen. IOCs were effectively immutable after alert creation.Root cause:
alert_iocsin the payload is never mapped toalert.iocson update, unlike at creation wherealerts_add_routeexplicitly popsalert_iocs, deserializes it withIocSchema, and passes the result directly toalerts_create.Fix: Mirror the creation pattern in both update routes:
alert_iocsfrom the request data before schema load (so theunknown=EXCLUDEpolicy doesn't swallow it and it doesn't pollute the activity log).alert_iocswas present in the payload, deserialize the list withIocSchemaand assign it toupdated_alert.iocs.Omitting
alert_iocsfrom the payload leaves existing IOCs unchanged. Passing an empty list ("alert_iocs": []) clears all IOCs on the alert.Changes
source/app/blueprints/rest/alerts_routes.py— legacyPOST /alerts/update/<id>source/app/blueprints/rest/v2/alerts.py— v2PUT /api/v2/alerts/<id>Test plan
POST /alerts/update/<id>withalert_iocs: verify IOCs are updated on the alertPUT /api/v2/alerts/<id>withalert_iocs: same verification on the v2 endpointalert_iocsfield: existing IOCs must remain unchanged"alert_iocs": []: existing IOCs must be clearedioc_type_id, missingioc_value): verify 400 / validation error is returned