OWASP WSTG v4.2 Explained

OWASP WSTG: Part 9 - Error Handling

WSTG v4.2 section 4.8 explained: improper error handling and stack traces, how error messages leak internal detail, how to trigger them, and how to fix them.

6 min read
views
visits
OWASP WSTG Part 9 - Error Handling
OWASP WSTG Part 9 - Error Handling

Errors are inevitable; leaking your internals through them is not. When an application returns a database error, a framework stack trace or a verbose debug page, it hands the tester a map of the technology stack, file paths, queries, library versions and sometimes credentials, exactly the information that makes every other attack easier.

Error Handling testing (WSTG section 4.8, IDs WSTG-ERRH-*) is a short category with two tests, but it pays off throughout an engagement: a single stack trace can reveal the database engine for your SQL injection or the framework version for a known CVE.

Source: WSTG v4.2 §4.8 Testing for Error Handling (CC BY-SA 4.0), explained and expanded. Only test systems you are authorised to test.


Key Takeaways

  • Error messages are reconnaissance for free: paths, versions, queries, internal IPs.
  • Trigger errors deliberately: malformed input, wrong types, oversized values, missing parameters, unexpected methods.
  • A generic error for the user, a detailed error for the logs: that is the whole fix.
  • This feeds the other categories: the engine, framework and structure you learn here sharpen injection and configuration tests.

How Errors Leak Information

flowchart LR
    IN["Unexpected input<br/>wrong type, too long,<br/>missing, malformed"] --> ERR["Unhandled error"]
    ERR --> LEAK["Verbose response<br/>stack trace, SQL error,<br/>file paths, versions,<br/>internal IPs"]
    LEAK --> USE["Sharper attacks:<br/>SQLi engine, framework CVEs,<br/>infrastructure map"]

WSTG-ERRH-01: Improper Error Handling

What it checks: whether the application and its servers return errors that disclose internal information or behave unsafely (for example, failing open instead of denying).

How to test: deliberately cause errors at every layer and read the responses.

Web server errors: request things that do not exist or are malformed.

1
2
3
curl -si https://example.com/this-does-not-exist-12345        # 404 page: server/version?
curl -si https://example.com/%2e%2e/%2e%2e/                    # malformed path
printf 'GET / HTTP/1.1\r\nHost:\r\n\r\n' | nc example.com 80   # missing/bad headers

Application errors: break the inputs you mapped in Part 2.

  • Wrong type: send a string where a number is expected, id=abc, qty=-1, date=notadate.
  • Oversized or malformed: a 10,000-character field, broken JSON ({"a":), broken XML, an invalid content type.
  • Missing parameters: remove a required field entirely.
  • Unexpected method / header: send PUT where POST is expected, or a bad Content-Type.

Watch for responses that leak:

Leak Example
Database errors ORA-00933, You have an error in your SQL syntax → engine + injection hint
Stack traces Java/.NET/Python traceback with class names and line numbers
File paths /var/www/app/includes/db.php on line 42
Framework/debug pages Django/Flask/Laravel/Rails debug screens, Spring whitelabel with trace
Internal hosts/IPs could not connect to 10.0.3.14:5432

Also check for failing open: if a component errors (auth service down, validation throws), does the request get denied or quietly allowed?

Fix: catch exceptions everywhere; return a generic error page/response to the user (an incident ID, no internals); log the full detail server-side; disable debug mode in production; and make sure failures deny access (fail closed).


WSTG-ERRH-02: Stack Traces

What it checks: specifically whether stack traces reach the user. A stack trace is the richest single error leak: it names the framework, its version, the file structure, method names and often the exact line and query.

How to test: provoke an unhandled exception (the malformed/wrong-type inputs above) and look for a traceback in the response body, in HTTP headers (some frameworks add X-Debug or error headers), or in error pages for 400/500.

1
2
3
java.sql.SQLException: ...
  at com.example.dao.UserDao.find(UserDao.java:88)
  at com.example.web.LoginServlet.doPost(LoginServlet.java:42)

That trace alone tells you the language, the data layer, the class names and where to look next.

Fix: never show stack traces to users; configure custom error pages for 4xx/5xx; turn off framework debug/trace in production (DEBUG=False, customErrors mode="On", APP_DEBUG=false, etc.); and send traces only to protected logs.


Worked Example: From Leaky Stack Trace to Safe Errors

Vulnerable (Flask with debug on) — an unhandled exception returns the interactive debugger, which prints the source, local variables and even an interactive console:

1
2
3
4
5
6
7
app = Flask(__name__)
app.config["DEBUG"] = True        # <- never in production

@app.get("/user/<int:uid>")
def user(uid):
    u = db.get_user(uid)
    return render_template("user.html", name=u["name"])   # KeyError if u is None

Exploit — the attacker just sends a value that breaks it and reads the response:

1
2
3
4
5
curl -s https://example.com/user/999999 | grep -iE 'Traceback|File "|line [0-9]'
# Traceback (most recent call last):
#   File "/srv/app/views.py", line 14, in user
#     return render_template("user.html", name=u["name"])
# TypeError: 'NoneType' object is not subscriptable

That one response reveals the framework, the file path, the exact line and the data layer, everything needed to sharpen a SQLi or a CVE search.

Fixed — debug off, generic responses to users, full detail only to the logs:

1
2
3
4
5
6
7
8
9
import logging, uuid
app.config["DEBUG"] = False

@app.errorhandler(Exception)
def handle(e):
    ref = uuid.uuid4().hex[:8]
    logging.exception("unhandled error ref=%s", ref)   # full trace -> protected log
    # user sees nothing internal, just a reference to quote to support
    return jsonify(error="Something went wrong.", ref=ref), 500

Set the equivalent in every stack: APP_DEBUG=false (Laravel), DEBUG=False (Django), customErrors mode="On" (ASP.NET), server.error.include-stacktrace=never (Spring Boot).


Hands-on Practice

  • PortSwigger Academy — the Information disclosure labs include error-message and debug-page leaks.
  • Juice Shop — the “Error Handling” challenge returns a verbose stack trace.
  • Try the wrong-type / malformed-input tricks above against a local DVWA or WebGoat and watch what each framework reveals by default.

Checklist: Error Handling

ID Test Approach
WSTG-ERRH-01 Improper error handling Trigger errors at every layer with malformed/wrong/missing input; read for leaks and fail-open behaviour
WSTG-ERRH-02 Stack traces Force unhandled exceptions; check body and headers for tracebacks

Previous: Part 8 - Input Validation · Next: Part 10 - Weak Cryptography


References

Comments

Questions, corrections or another approach? Comment with your GitHub account.

Open Research & Community Labs
صدقة جارية • Ongoing Charity

Empowering the Cybersecurity Community

All research, lab walkthroughs, and technical series on this platform remain 100% free. You can support server hosting, research environments, and lab infrastructure.

Support & Wall of Honor
اللهم اجعل هذا العمل علمًا نافعًا وصدقةً جارية، واكتب لي به الأجر والقبول، وانفع به كل من قرأه أو تعلّمه.
اللهم احفظ لي والديّ وأهلي، وبارك في أعمارهم وصحتهم، وأدم عليهم نعمة الصحة والعافية، ولا تريني فيهم بأسًا يبكيني.
Dedicated as ongoing charity and beneficial knowledge. May Allah bless my parents and family, protect them, and grant them lasting health and happiness.