-
Notifications
You must be signed in to change notification settings - Fork 467
fix: prevent IDOR vulnerability in environment update endpoint #6384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 3 Skipped Deployments
|
Docker builds report
|
api/environments/serializers.py
Outdated
| 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 |
There was a problem hiding this comment.
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 Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6384 +/- ##
==========================================
+ Coverage 98.02% 98.07% +0.04%
==========================================
Files 1282 1292 +10
Lines 45498 46526 +1028
==========================================
+ Hits 44600 45629 +1029
+ Misses 898 897 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
90b1762 to
cd0e004
Compare
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).
cd0e004 to
d29b554
Compare
matthewelwell
left a comment
There was a problem hiding this 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.
api/environments/serializers.py
Outdated
| # handle `project` not being part of the data | ||
| # When request comes from yasg2(as part of schema generation) | ||
| project_id = view.request.data.get("project") | ||
| if not project_id: | ||
| return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another (perhaps more descriptive) option here would be:
| # handle `project` not being part of the data | |
| # When request comes from yasg2(as part of schema generation) | |
| project_id = view.request.data.get("project") | |
| if not project_id: | |
| return None | |
| if getattr(self.request, "swagger_fake_view", False): | |
| return Subscription.objects.none() | |
| project_id = self.request.data["project"] |
api/environments/serializers.py
Outdated
| if self.instance is None: | ||
| return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should never be the case, right? Is this to handle swagger again? If so, I prefer the explicit approach I suggested above.
Address PR review comments by using explicit swagger_fake_view attribute check instead of implicit project_id presence check.
733c2ae to
28e10e7
Compare
There was a problem hiding this 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.
Thanks for submitting a PR! Please check the boxes below:
docs/if required so people know about the feature!Changes
Make the
projectfield read-only during environment updates to prevent moving an environment to a different projectThe vulnerability allowed an attacker with access to their own environment to modify the
projectfield 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