Skip to content

fix: prevent IDOR vulnerability in environment update endpoint#6384

Merged
gagantrivedi merged 5 commits intomainfrom
fix/idor-environment-project-validation
Mar 16, 2026
Merged

fix: prevent IDOR vulnerability in environment update endpoint#6384
gagantrivedi merged 5 commits intomainfrom
fix/idor-environment-project-validation

Conversation

@gagantrivedi
Copy link
Copy Markdown
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 moving an environment to a different project

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
Copy Markdown

vercel bot commented Dec 8, 2025

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

3 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview Mar 12, 2026 6:44am
flagsmith-frontend-preview Ignored Ignored Preview Mar 12, 2026 6:44am
flagsmith-frontend-staging Ignored Ignored Preview Mar 12, 2026 6:44am

Request Review

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

github-actions bot commented Dec 8, 2025

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-e2e:pr-6384 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-6384 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api-test:pr-6384 Finished ✅ Skipped
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 thread api/environments/serializers.py Outdated
@codecov
Copy link
Copy Markdown

codecov bot commented Dec 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.31%. Comparing base (dbd66e9) to head (c2ac664).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6384   +/-   ##
=======================================
  Coverage   98.31%   98.31%           
=======================================
  Files        1335     1335           
  Lines       49717    49732   +15     
=======================================
+ Hits        48879    48895   +16     
+ Misses        838      837    -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
matthewelwell
matthewelwell previously approved these changes Dec 17, 2025
Copy link
Copy Markdown
Contributor

@matthewelwell matthewelwell left a comment

Choose a reason for hiding this comment

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

Approving with a couple of minor comments.

Comment thread api/environments/serializers.py Outdated
Comment thread api/environments/serializers.py Outdated
Address PR review comments by using explicit swagger_fake_view attribute
check instead of implicit project_id presence check.
@gagantrivedi gagantrivedi force-pushed the fix/idor-environment-project-validation branch from 733c2ae to 28e10e7 Compare December 25, 2025 08:36
@github-actions github-actions bot added fix and removed fix labels Dec 25, 2025
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This is the final PR Bugbot will review for you during this billing cycle

Your free Bugbot reviews will reset on January 10

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Comment thread api/environments/serializers.py
Resolve conflict in environments/serializers.py: incorporate
drf-spectacular schema generation guard from main into the new
CreateEnvironmentSerializer while keeping the separate
UpdateEnvironmentSerializer from this branch.
@cursor
Copy link
Copy Markdown

cursor bot commented Mar 12, 2026

You have run out of free Bugbot PR reviews for this billing cycle. This will reset on April 10.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@github-actions github-actions bot added fix and removed fix labels Mar 12, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 12, 2026

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  28.1 seconds
commit  2a4ffe4
info  🔄 Run: #15253 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  27.5 seconds
commit  2a4ffe4
info  🔄 Run: #15253 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  50.3 seconds
commit  3b2f15b
info  🔄 Run: #15254 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  28.3 seconds
commit  3b2f15b
info  🔄 Run: #15254 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  58.5 seconds
commit  2a4ffe4
info  🔄 Run: #15253 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  1 minute, 3 seconds
commit  2a4ffe4
info  🔄 Run: #15253 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  45.9 seconds
commit  c2ac664
info  🔄 Run: #15255 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  10 passed

Details

stats  10 tests across 7 suites
duration  28.9 seconds
commit  c2ac664
info  🔄 Run: #15255 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  16 passed

Details

stats  16 tests across 13 suites
duration  26.7 seconds
commit  c2ac664
info  🔄 Run: #15255 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  1 minute, 3 seconds
commit  c2ac664
info  🔄 Run: #15255 (attempt 1)

Replace .get("project") + None guard with direct dict access since
the swagger_fake_view check above already handles schema generation.

Applies review suggestion from PR #6384.
@github-actions github-actions bot added fix and removed fix labels Mar 12, 2026
@gagantrivedi gagantrivedi removed the request for review from khvn26 March 16, 2026 12:24
@gagantrivedi gagantrivedi merged commit 89f2477 into main Mar 16, 2026
33 checks passed
@gagantrivedi gagantrivedi deleted the fix/idor-environment-project-validation branch March 16, 2026 12:25
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.

2 participants