# Verbose Error Messages and Stack Traces

## Overview

Applications often inadvertently leak information from the web server due to verbose error messages. These error messages and stack traces reveal useful backend information that is normally not available to the user, such as libraries in use, web framework type, server versions, expected data input type, etc. This is useful information in forming an attack on the application and or organization.&#x20;

As an example I once found a Local File Inclusion vulnerability that I was attempting to exploit but unable to pull source code from the application due to not knowing the directory paths. Verbose error messages revealed the directories in use and I was able to use that information to form the correct LFI payloads to extract the source code of the application.&#x20;

## Example

This example from Appsecco's DVNA illustrates the vulnerability. When inputing invalid input, in this case `XD` , in the calculator page of the application `http://127.0.0.1/app/calc` it returns a verbose error message with stack traces revealing the web framework in use (Node) as well as the modules in use.&#x20;

![](https://4166910944-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M6GgEQGJyt_GNdNEMG7%2F-MRS2HerQPOFUV92onTG%2F-MRSAf-byr2mzipOIVK8%2FScreen%20Shot%202021-01-19%20at%207.23.09%20PM.png?alt=media\&token=c3affd0f-9758-4189-b1bd-8eb4fc54d71f)

There are two issues that are creating this vulnerability. First the NodeJS application is running in Development mode. Change the environment variable to production `NODE_ENV=production` .&#x20;

The source code that handles this functionality is /core/appHandler.js. The code checks if the HTTP request body has a value for the body parameters eqn, if so it renders the calculator and evaluates the math equation input (from the body parameter eqn).&#x20;

```
module.exports.calc = function (req, res) {
	if (req.body.eqn) {
		res.render('app/calc', {
			output: mathjs.eval(req.body.eqn)
		})
	} else {
		res.render('app/calc', {
			output: 'Enter a valid math string like (3+3)*2'
		})
	}
}
```

The solution to this is to catch error messages using a try catch exception handling block. The try catch block starts on line 3 and catches errors on line 13.&#x20;

```
module.exports.calc = function (req, res) {
	if(vh.vEqn(req.body.eqn)){
		try{
			if (req.body.eqn) {
				res.render('app/calc', {
					output: mathjs.eval(req.body.eqn)
				})
			} else {
				res.render('app/calc', {
					output: 'Enter a valid math string like (3+3)*2'
				})
			}
		}catch(err){
			res.render('app/calc', {
				output: 'Enter a valid math string like (3+3)*2'
			})				
		}		
	}else{
		res.render('app/calc', {
			output: 'Enter a valid math string like (3+3)*2'
		})
	}
}

```

For further reading:

{% embed url="https://owasp.org/www-community/Improper_Error_Handling" %}

{% embed url="https://cheatsheetseries.owasp.org/cheatsheets/Error_Handling_Cheat_Sheet.html" %}

{% embed url="https://appsecco.com/books/dvna-developers-security-guide/solution/a6-securty-misconfig.html" %}
Appsecco DVNA example used above
{% endembed %}
