-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix: prevent ORM field injection via segment parameter in analytics (GHSA-93x3-ghh7-72j3) #8864
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,7 @@ | |
| Module, | ||
| ) | ||
|
|
||
| from plane.utils.analytics_plot import build_graph_plot | ||
| from plane.utils.analytics_plot import build_graph_plot, VALID_ANALYTICS_FIELDS, VALID_YAXIS | ||
| from plane.utils.issue_filters import issue_filters | ||
| from plane.app.permissions import allow_permission, ROLE | ||
|
|
||
|
|
@@ -41,32 +41,15 @@ def get(self, request, slug): | |
| y_axis = request.GET.get("y_axis", False) | ||
| segment = request.GET.get("segment", False) | ||
|
|
||
| valid_xaxis_segment = [ | ||
| "state_id", | ||
| "state__group", | ||
| "labels__id", | ||
| "assignees__id", | ||
| "estimate_point__value", | ||
| "issue_cycle__cycle_id", | ||
| "issue_module__module_id", | ||
| "priority", | ||
| "start_date", | ||
| "target_date", | ||
| "created_at", | ||
| "completed_at", | ||
| ] | ||
|
|
||
| valid_yaxis = ["issue_count", "estimate"] | ||
|
|
||
| # Check for x-axis and y-axis as thery are required parameters | ||
| if not x_axis or not y_axis or x_axis not in valid_xaxis_segment or y_axis not in valid_yaxis: | ||
| if not x_axis or not y_axis or x_axis not in VALID_ANALYTICS_FIELDS or y_axis not in VALID_YAXIS: | ||
| return Response( | ||
| {"error": "x-axis and y-axis dimensions are required and the values should be valid"}, | ||
| status=status.HTTP_400_BAD_REQUEST, | ||
| ) | ||
|
|
||
| # If segment is present it cannot be same as x-axis | ||
| if segment and (segment not in valid_xaxis_segment or x_axis == segment): | ||
| if segment and (segment not in VALID_ANALYTICS_FIELDS or x_axis == segment): | ||
| return Response( | ||
| {"error": "Both segment and x axis cannot be same and segment should be valid"}, | ||
| status=status.HTTP_400_BAD_REQUEST, | ||
|
|
@@ -214,13 +197,20 @@ def get(self, request, slug, analytic_id): | |
| x_axis = analytic_view.query_dict.get("x_axis", False) | ||
| y_axis = analytic_view.query_dict.get("y_axis", False) | ||
|
|
||
| if not x_axis or not y_axis: | ||
| if not x_axis or not y_axis or x_axis not in VALID_ANALYTICS_FIELDS or y_axis not in VALID_YAXIS: | ||
| return Response( | ||
| {"error": "x-axis and y-axis dimensions are required"}, | ||
| {"error": "x-axis and y-axis dimensions are required and the values should be valid"}, | ||
| status=status.HTTP_400_BAD_REQUEST, | ||
| ) | ||
|
|
||
| segment = request.GET.get("segment", False) | ||
|
|
||
| if segment and (segment not in VALID_ANALYTICS_FIELDS or x_axis == segment): | ||
| return Response( | ||
| {"error": "Both segment and x axis cannot be same and segment should be valid"}, | ||
| status=status.HTTP_400_BAD_REQUEST, | ||
| ) | ||
|
|
||
| distribution = build_graph_plot(queryset=queryset, x_axis=x_axis, y_axis=y_axis, segment=segment) | ||
| total_issues = queryset.count() | ||
| return Response( | ||
|
|
@@ -236,32 +226,15 @@ def post(self, request, slug): | |
| y_axis = request.data.get("y_axis", False) | ||
| segment = request.data.get("segment", False) | ||
|
|
||
| valid_xaxis_segment = [ | ||
| "state_id", | ||
| "state__group", | ||
| "labels__id", | ||
| "assignees__id", | ||
| "estimate_point", | ||
| "issue_cycle__cycle_id", | ||
| "issue_module__module_id", | ||
| "priority", | ||
| "start_date", | ||
| "target_date", | ||
| "created_at", | ||
| "completed_at", | ||
| ] | ||
|
|
||
| valid_yaxis = ["issue_count", "estimate"] | ||
|
|
||
| # Check for x-axis and y-axis as thery are required parameters | ||
| if not x_axis or not y_axis or x_axis not in valid_xaxis_segment or y_axis not in valid_yaxis: | ||
| if not x_axis or not y_axis or x_axis not in VALID_ANALYTICS_FIELDS or y_axis not in VALID_YAXIS: | ||
| return Response( | ||
| {"error": "x-axis and y-axis dimensions are required and the values should be valid"}, | ||
| status=status.HTTP_400_BAD_REQUEST, | ||
| ) | ||
|
Comment on lines
229
to
234
|
||
|
|
||
| # If segment is present it cannot be same as x-axis | ||
| if segment and (segment not in valid_xaxis_segment or x_axis == segment): | ||
| if segment and (segment not in VALID_ANALYTICS_FIELDS or x_axis == segment): | ||
| return Response( | ||
| {"error": "Both segment and x axis cannot be same and segment should be valid"}, | ||
| status=status.HTTP_400_BAD_REQUEST, | ||
|
|
||
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.
build_graph_plot()now raisesValueErrorfor invalidx_axis/y_axis, but this endpoint takes those values fromanalytic_view.query_dict(not the request) and doesn’t validate/catch errors before callingbuild_graph_plot(). A malformed/legacy/malicious saved analytic could now produce a 500. Consider validatingx_axis/y_axisagainst the allowlists here and/or catchingValueErrorand returning a 400 response.