4848 check_security_txt ,
4949 get_capture_result ,
5050 get_recent_captures ,
51- check_dkim
51+ check_dkim ,
52+ extract_domain_from_url
5253)
5354from .models import DMARCRecord , DMARCReport , MailDomain , TestReport , CSPReport , CSPEndpoint
5455import json
@@ -137,7 +138,15 @@ def test_landing(request):
137138@csrf_exempt
138139def check_website_security (request ):
139140 if request .method == 'POST' :
140- domain = request .POST .get ('target' )
141+ domain = request .POST .get ('target' , '' ).strip ()
142+
143+ # Log the input for debugging
144+ logger .debug (f"Web security check requested for: { domain } " )
145+
146+ if not domain :
147+ return render (request , 'check_webapp.html' , {
148+ 'error' : 'Please enter a domain to check'
149+ })
141150
142151 csp_result = check_csp (domain )
143152 cookies_result = check_cookies (domain )
@@ -162,6 +171,17 @@ def check_website_security(request):
162171 'security_txt_result' : security_txt_result
163172 }
164173
174+ # Check if we had errors with any of the tests
175+ has_errors = any (
176+ isinstance (result , dict ) and result .get ('error' )
177+ for result in [csp_result , cookies_result , cors_result , https_redirect_result ,
178+ referrer_policy_result , sri_result , x_content_type_options_result ,
179+ hsts_result , security_txt_result ]
180+ )
181+
182+ if has_errors :
183+ context ['validation_error' ] = f"Some tests couldn't be completed for { domain } . Please verify the domain name."
184+
165185 try :
166186 test_report = TestReport .objects .get (tested_site = domain , test_ran = "web-test" )
167187 test_report .report = context
@@ -190,7 +210,14 @@ def email_test(request):
190210 "You reached the maximum number of tests. Please create an account." ,
191211 )
192212 return redirect ("signup" )
193- target = request .POST ["target" ]
213+
214+ target = request .POST ["target" ].strip ()
215+ # Log the input for debugging
216+ logger .debug (f"Email test requested for: { target } " )
217+
218+ # Extract domain from URL-like inputs without re-importing
219+ target = extract_domain_from_url (target )
220+
194221 if not check_soa_record (target ):
195222 context = {"status" : False , "statusmessage" : "The given domain is invalid!" }
196223 else :
@@ -253,8 +280,16 @@ def ipv6_test(request):
253280 "You reached the maximum number of tests. Please create an account." ,
254281 )
255282 return redirect ("signup" )
283+
284+ target = request .POST ["target" ].strip ()
285+ # Log the input for debugging
286+ logger .debug (f"IPv6 test requested for: { target } " )
287+
288+ # Extract domain from URL-like inputs without re-importing
289+ target = extract_domain_from_url (target )
290+
256291 context = {}
257- context .update (ipv6_check (request . POST [ " target" ] , None ))
292+ context .update (ipv6_check (target , None ))
258293 nb_tests += 1
259294 response = render (request , "check_ipv6.html" , context )
260295 response .set_cookie ("nb_tests" , nb_tests )
@@ -275,7 +310,14 @@ def web_server_test(request):
275310 "You reached the maximum number of tests. Please create an account." ,
276311 )
277312 return redirect ("signup" )
278- domain = request .POST ["target" ]
313+
314+ domain = request .POST ["target" ].strip ()
315+ # Log the input for debugging
316+ logger .debug (f"Web server test requested for: { domain } " )
317+
318+ # Extract domain from URL-like inputs without re-importing
319+ domain = extract_domain_from_url (domain )
320+
279321 context = {'domain' : domain }
280322 context .update (web_server_check (domain ))
281323
@@ -599,18 +641,32 @@ def url_test(request):
599641 lookyloo = Lookyloo ('https://lookyloo.circl.lu' )
600642 if request .method == 'POST' :
601643 url = request .POST .get ('target' )
644+
645+ # Ensure URL has a proper protocol prefix
646+ if url and not url .startswith (('http://' , 'https://' )):
647+ url = 'https://' + url
648+ logger .info (f"Added https:// prefix to URL: { url } " )
649+
602650 if lookyloo .is_up :
603651 context = {'lookyloo_status' : lookyloo .is_up }
604- capture_uuid = lookyloo .submit (url = url , quiet = True )
605- while lookyloo .get_status (capture_uuid )['status_code' ] != 1 :
606- if lookyloo .get_status (capture_uuid )['status_code' ] == - 1 :
607- context ['error' ] = 'Lookyloo has encountered an issue with the requested capture. Please try again.'
608- sleep (5 )
609- capture = get_capture_result (lookyloo , capture_uuid )
610- context ['capture' ] = capture
611- screenshot_stream = lookyloo .get_screenshot (capture_uuid )
612- screenshot = base64 .b64encode (screenshot_stream .read ()).decode ('utf-8' )
613- context ['screenshot' ] = screenshot
652+ try :
653+ capture_uuid = lookyloo .submit (url = url , quiet = True )
654+ while lookyloo .get_status (capture_uuid )['status_code' ] != 1 :
655+ if lookyloo .get_status (capture_uuid )['status_code' ] == - 1 :
656+ context ['error' ] = 'Lookyloo has encountered an issue with the requested capture. Please try again.'
657+ break
658+ sleep (5 )
659+
660+ if 'error' not in context :
661+ capture = get_capture_result (lookyloo , capture_uuid )
662+ context ['capture' ] = capture
663+ screenshot_stream = lookyloo .get_screenshot (capture_uuid )
664+ screenshot = base64 .b64encode (screenshot_stream .read ()).decode ('utf-8' )
665+ context ['screenshot' ] = screenshot
666+ except Exception as e :
667+ logger .error (f"Error in URL test for { url } : { str (e )} " )
668+ context ['error' ] = f"An error occurred during the capture: { str (e )} "
669+
614670 return render (request , 'check_lookyloo.html' , context )
615671 else :
616672 recent_captures = get_recent_captures (lookyloo )
0 commit comments