Skip to content

fix(permissions): handle invalid IDs in feature and project permissions - #9148

Open
aplatogg wants to merge 5 commits into
Flagsmith:mainfrom
aplatogg:fix/6809-validate-project-and-feature-permission-ids
Open

aplatogg wants to merge 5 commits into
Flagsmith:mainfrom
aplatogg:fix/6809-validate-project-and-feature-permission-ids

Conversation

@aplatogg

Copy link
Copy Markdown

Changes

Handles non-integer / malformed ID inputs (ValueError, TypeError) in features/permissions.py and projects/permissions.py so permission checks return False (or raise PermissionDenied in IsProjectAdmin) instead of raising an unhandled 500 ValueError during ORM lookup or int() conversion:

  • FeaturePermissions.has_permission (api/features/permissions.py:57): Catch (ValueError, TypeError) alongside Project.DoesNotExist when resolving Project.objects.get(id=project_id) (directly addresses the FLAGSMITH-API-5J6 Sentry stack trace in URL/query/data input lacking validation #6809).
  • FeatureStatePermissions.has_permission & EnvironmentFeatureStatePermissions.has_permission: Catch/suppress (ValueError, TypeError) when looking up Feature.objects.get(id=feature_id).
  • ProjectPermissions.has_permission (api/projects/permissions.py:20): Catch (TypeError, ValueError) when parsing int(request.data.get("organisation")) on create.
  • IsProjectAdmin._get_project & NestedProjectPermissions.has_permission: Catch (ValueError, TypeError) alongside Project.DoesNotExist.
  • Added unit tests in test_unit_features_permissions.py and test_unit_projects_permissions.py.

Contributes to #6809

@aplatogg
aplatogg requested a review from a team as a code owner November 27, 2026 15:32
@aplatogg
aplatogg requested review from emyller and removed request for a team November 27, 2026 15:32
@vercel

vercel Bot commented Nov 27, 2026

Copy link
Copy Markdown

@aplatogg is attempting to deploy a commit to the Flagsmith Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the api Issue related to the REST API label Nov 27, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review completed against the latest diff

Reply to a comment to ask cubic a question or push back. It learns from your replies.

Re-trigger cubic

Comment thread api/features/permissions.py Resolved
Comment thread api/features/permissions.py Resolved
Comment thread api/projects/permissions.py Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 4 files

Requires human review: Auto-approval blocked because this review re-detected 3 unresolved issues already reported by Cubic.

Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 4 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

0 issues found across 1 file (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval skipped because this PR is from an external contributor.

Re-trigger cubic

This branch has not been deployed

No deployments
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant