Skip to content

improve: add granular error handling and expand WAF detection#2931

Open
mohamedsolaiman wants to merge 1 commit intosherlock-project:masterfrom
mohamedsolaiman:improve/error-handling
Open

improve: add granular error handling and expand WAF detection#2931
mohamedsolaiman wants to merge 1 commit intosherlock-project:masterfrom
mohamedsolaiman:improve/error-handling

Conversation

@mohamedsolaiman
Copy link
Copy Markdown
Contributor

Summary

Improves error handling granularity in get_response() and expands WAF (Web Application Firewall) detection to reduce false positives from WAF-blocked responses.

Changes to get_response()

Added SSLError handling

  • requests.exceptions.SSLError is a subclass of ConnectionError but represents a distinctly different problem (TLS certificate validation failure vs network connectivity)
  • Previously, SSL errors fell through to the generic "Error Connecting" message
  • Now reports "SSL Error" with the exception text, giving users actionable feedback about certificate issues
  • Placed before ConnectionError catch since it is a more specific subclass

Added ChunkedEncodingError handling

  • requests.exceptions.ChunkedEncodingError occurs when a server sends an incomplete chunked transfer encoding response
  • Previously fell through to the generic "Unknown Error" catch-all
  • Now reports "Chunked Encoding Error" which helps distinguish transient server issues from client-side problems

Added ContentDecodingError handling

  • requests.exceptions.ContentDecodingError occurs when response body decompression fails (e.g., corrupted gzip/deflate content)
  • Previously fell through to the generic "Unknown Error" catch-all
  • Now reports "Content Decoding Error" which helps identify encoding-related issues

Changes to WAF Detection

Added case-insensitive WAF fingerprint matching

  • Some WAF challenge pages use varying capitalization that the existing case-sensitive patterns miss
  • New WAFHitMsgsCaseInsensitive list for patterns that need case-insensitive matching

New WAF fingerprints:

  • cf-browser-verification: Cloudflare browser verification class
  • just a moment...: Cloudflare interstitial challenge page title (e.g., "Just a moment...")
  • enable javascript and cookies to continue: Cloudflare challenge instruction text
  • attentionrequired: Cloudflare Turnstile challenge attribute
  • why do i have to complete a captcha: Generic WAF captcha explanation text

These fingerprints help catch WAF challenge pages that were previously missed, reducing false positives where Sherlock would incorrectly report a username as "Claimed" when the response was actually a WAF block page.

Testing

  • Verified Python syntax is valid
  • Exception hierarchy is correct (SSLError before ConnectionError, specific errors before RequestException)
  • All existing exception handlers remain unchanged

get_response() improvements:
- Add SSLError as a distinct exception handler before ConnectionError,
  providing clearer "SSL Error" context instead of the generic
  "Error Connecting" message for TLS/certificate failures.
- Add ChunkedEncodingError handling for incomplete chunked responses
  from servers, which previously fell through to "Unknown Error".
- Add ContentDecodingError handling for gzip/deflate decompression
  failures, which previously fell through to "Unknown Error".

WAF detection improvements:
- Add case-insensitive WAF fingerprint matching for patterns that may
  vary in capitalization across different WAF challenge pages.
- Add fingerprints for Cloudflare browser verification, Turnstile, and
  challenge page titles ("Just a moment...").
- Add fingerprint for generic WAF captcha pages.
- These help reduce false positives from sites that serve WAF challenge
  pages with varying text formatting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant