Skip to content

Commit 1188059

Browse files
committed
Refine API error response to avoid information exposure
Signed-off-by: tdruez <[email protected]>
1 parent d7d2429 commit 1188059

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
=========
33

4+
v35.4.2 (unreleased)
5+
--------------------
6+
7+
- Add arguments support for the reset action in REST API.
8+
https://github.com/aboutcode-org/scancode.io/issues/1948
9+
410
v35.4.1 (2025-10-24)
511
--------------------
612

scanpipe/api/views.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# Visit https://github.com/aboutcode-org/scancode.io for support and download.
2222

2323
import json
24+
import logging
2425

2526
from django.apps import apps
2627
from django.core.exceptions import ObjectDoesNotExist
@@ -58,6 +59,7 @@
5859
from scanpipe.pipes.compliance import get_project_compliance_alerts
5960
from scanpipe.views import project_results_json_response
6061

62+
logger = logging.getLogger(__name__)
6163
scanpipe_app = apps.get_app_config("scanpipe")
6264

6365

@@ -401,8 +403,11 @@ def add_webhook(self, request, *args, **kwargs):
401403
def destroy(self, request, *args, **kwargs):
402404
try:
403405
return super().destroy(request, *args, **kwargs)
404-
except RunInProgressError as error:
405-
return Response({"status": str(error)}, status=status.HTTP_400_BAD_REQUEST)
406+
except RunInProgressError:
407+
return Response(
408+
{"status": "Cannot delete project while a run is in progress."},
409+
status=status.HTTP_400_BAD_REQUEST,
410+
)
406411

407412
@action(detail=True, methods=["get", "post"])
408413
def archive(self, request, *args, **kwargs):
@@ -423,10 +428,13 @@ def archive(self, request, *args, **kwargs):
423428
remove_codebase=request.data.get("remove_codebase"),
424429
remove_output=request.data.get("remove_output"),
425430
)
426-
except RunInProgressError as error:
427-
return Response({"status": str(error)}, status=status.HTTP_400_BAD_REQUEST)
428-
else:
429-
return Response({"status": f"The project {project} has been archived."})
431+
except RunInProgressError:
432+
return Response(
433+
{"status": "Cannot archive project while a run is in progress."},
434+
status=status.HTTP_400_BAD_REQUEST,
435+
)
436+
437+
return Response({"status": f"The project {project} has been archived."})
430438

431439
@action(detail=True, methods=["get", "post"])
432440
def reset(self, request, *args, **kwargs):
@@ -442,8 +450,11 @@ def reset(self, request, *args, **kwargs):
442450
restore_pipelines=request.data.get("restore_pipelines", False),
443451
execute_now=request.data.get("execute_now", False),
444452
)
445-
except RunInProgressError as error:
446-
return Response({"status": str(error)}, status=status.HTTP_400_BAD_REQUEST)
453+
except RunInProgressError:
454+
return Response(
455+
{"status": "Cannot reset project while a run is in progress."},
456+
status=status.HTTP_400_BAD_REQUEST,
457+
)
447458
else:
448459
message = f"The {project} project has been reset."
449460
return Response({"status": message})

scanpipe/tests/test_api.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -909,10 +909,7 @@ def test_scanpipe_api_project_action_delete(self):
909909

910910
response = self.csrf_client.delete(self.project1_detail_url)
911911
self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code)
912-
expected = (
913-
"Cannot execute this action until all associated pipeline runs are "
914-
"completed."
915-
)
912+
expected = "Cannot delete project while a run is in progress."
916913
self.assertEqual(expected, response.data["status"])
917914

918915
run.set_task_ended(exitcode=0)

0 commit comments

Comments
 (0)