Skip to content

Commit

Permalink
Add error handling for suggest subdomains
Browse files Browse the repository at this point in the history
  • Loading branch information
aequitas committed Nov 18, 2024
1 parent f7e07a0 commit a7eed69
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions dashboard/internet_nl_dashboard/logic/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def suggest_subdomains(domain: str, period: int = 370):

# ip address or garbage
if not extract.domain or not extract.suffix:
return []
raise ValueError("Invalid input")

# call SUBDOMAIN_SUGGESTION_SERVER_ADDRESS
response = requests.get(config.SUBDOMAIN_SUGGESTION_SERVER_ADDRESS,
Expand All @@ -43,7 +43,7 @@ def suggest_subdomains(domain: str, period: int = 370):

if response.status_code != 200:
log.error("Failed to retrieve subdomain suggestions from %s.", config.SUBDOMAIN_SUGGESTION_SERVER_ADDRESS)
return []
raise Exception("Failed to retrieve subdomain suggestions")

return response.json()

Expand Down
11 changes: 9 additions & 2 deletions dashboard/internet_nl_dashboard/views/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import List

from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
from django.http import HttpResponseBadRequest, HttpResponseServerError, JsonResponse
from django.views.decorators.http import require_http_methods
from websecmap.app.common import JSEncoder

Expand All @@ -20,7 +20,14 @@ def suggest_subdomains_(request) -> JsonResponse:
request = get_json_body(request)
domain = request.get("domain", "")
period = request.get("period", 370)
return JsonResponse(suggest_subdomains(domain, period), encoder=JSEncoder, safe=False)
try:
result = JsonResponse(suggest_subdomains(domain, period), encoder=JSEncoder, safe=False)
except ValueError as e:
result = HttpResponseBadRequest(str(e))

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.
except Exception:
result = HttpResponseServerError("Error occured while getting subdomain suggestions")

return result


@login_required(login_url=LOGIN_URL)
Expand Down
3 changes: 1 addition & 2 deletions dashboard/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
from sentry_sdk.integrations.redis import RedisIntegration

from . import __version__
from .settings_constance import CONSTANCE_ADDITIONAL_FIELDS # noqa # pylint: disable=unused-import
from .settings_constance import CONSTANCE_CONFIG_FIELDSETS # noqa pylint: disable=unused-import
from .settings_constance import (CONSTANCE_ADDITIONAL_FIELDS, # noqa # pylint: disable=unused-import
CONSTANCE_BACKEND, CONSTANCE_CONFIG)
# import all of this and don't auto-lint it away because there are no references here.
# most code refers to these settings.
from .settings_jet import JET_SIDE_MENU_COMPACT, JET_SIDE_MENU_ITEMS # noqa # pylint: disable=unused-import
Expand Down

0 comments on commit a7eed69

Please sign in to comment.