Skip to content

Conversation

@gagantrivedi
Copy link
Member

@gagantrivedi gagantrivedi commented Dec 8, 2025

Thanks for submitting a PR! Please check the boxes below:

  • I have added information to docs/ if required so people know about the feature!
  • I have filled in the "Changes" section below?
  • I have filled in the "How did you test this code" section below?
  • I have used a Conventional Commit title for this Pull Request

Changes

Make the project field read-only during environment updates to prevent attackers from moving an environment to a different project they don't own.

The vulnerability allowed an attacker with access to their own environment to modify the project field in the PUT request body, effectively moving their environment into a victim's project.

Fix: Override init in CreateUpdateEnvironmentSerializer to set project field as read-only when instance exists (update operation).

How did you test this code?

Adds unit test

@gagantrivedi gagantrivedi requested a review from a team as a code owner December 8, 2025 08:45
@gagantrivedi gagantrivedi requested review from khvn26 and removed request for a team December 8, 2025 08:45
@vercel
Copy link

vercel bot commented Dec 8, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
docs Ignored Ignored Preview Dec 8, 2025 11:39am
flagsmith-frontend-preview Ignored Ignored Preview Dec 8, 2025 11:39am
flagsmith-frontend-staging Ignored Ignored Preview Dec 8, 2025 11:39am

@github-actions github-actions bot added api Issue related to the REST API fix labels Dec 8, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2025

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-api-test:pr-6384 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-e2e:pr-6384 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-6384 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api:pr-6384 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-6384 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-6384 Finished ✅ Results

Comment on lines 133 to 137
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs) # type: ignore[no-untyped-call]
# Prevent IDOR: project cannot be changed after creation
if self.instance is not None:
self.fields["project"].read_only = True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A neater option here is probably just to separate the Create and Update serializers?

@codecov
Copy link

codecov bot commented Dec 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.02%. Comparing base (f7ca9cd) to head (d29b554).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6384   +/-   ##
=======================================
  Coverage   98.02%   98.02%           
=======================================
  Files        1282     1282           
  Lines       45498    45514   +16     
=======================================
+ Hits        44600    44617   +17     
+ Misses        898      897    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gagantrivedi gagantrivedi force-pushed the fix/idor-environment-project-validation branch from 90b1762 to cd0e004 Compare December 8, 2025 10:33
@github-actions github-actions bot added fix and removed fix labels Dec 8, 2025
Make the `project` field read-only during environment updates to prevent
attackers from moving an environment to a different project they don't own.

The vulnerability allowed an attacker with access to their own environment
to modify the `project` field in the PUT request body, effectively moving
their environment into a victim's project.

Fix: Override __init__ in CreateUpdateEnvironmentSerializer to set
project field as read-only when instance exists (update operation).
@gagantrivedi gagantrivedi force-pushed the fix/idor-environment-project-validation branch from cd0e004 to d29b554 Compare December 8, 2025 11:38
@github-actions github-actions bot added fix and removed fix labels Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants