Flagsmith / Flagsmith/flagsmith
System segments can be overwritten via the change request API
- Dominant language
- Python
- Stars
- 6.6k
- Forks
- 567
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 121
Description
## Bug
`ProjectChangeRequestSerializer` (workflows_logic) accepts nested segment drafts with a writable `version_of`, and nothing validates the target segment. On commit, `_publish_segments` (`api/core/workflows_services.py`) copies the draft's name, description and rules onto the live segment. `SegmentViewSet`'s `is_system_segment=False` queryset filter never applies on this path — the draft is created by the change request API, not the segments API.
## Reproduction
1. Create a project change request with a nested segment whose `version_of` is a system segment's id (e.g. an experimentation rollout segment).
2. Approve and commit the change request.
3. The live system segment's name and rules are overwritten.
## Impact
System segments — including experimentation rollout segments, whose conditions control experiment percentage splits — can be modified through the change request flow, which the `is_system_segment` mechanism is meant to prevent.
Contributor guide
Research direction
Start with ProjectChangeRequestSerializer in the workflows_logic change request API, then trace _publish_segments in api/core/workflows_services.py and compare the path with SegmentViewSet's system-segment filter. Reproduce the nested version_of case using a system segment, and confirm that approving and committing the change request no longer overwrites its name, description, or rules.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100