LLima925770 (Community Member) asked a question.

How to fix CWE 201 to this code?
res.status(500).json({ error: err });
"...In this case, the message being sent appears to be considered private. " really?

context code:

router.route('/deleteByDocumentType')

   .post(verify.verifyOrdinaryUser, (req, res) => {

       DocumentFormField.deleteMany({documentType:req.body.documentType}, (err, doc) => {

           if (err) {

               res.status(500).json({ error: err });

               return

           }

           return res.status(200).json({ success: true, message: "campo removido da base"});

       });

   });

 

Veracode response: the application calls the express.Response.json() function, which will result in data being transferred out of the application (via the network or another medium). In this case, the message being sent appears to be considered private; this may include credentials such as usernames or passwords, data normally stored in cryptographically-protected vaults such as keychains, or other private information. Ensure that the transfer of the sensitive data is intended and that it does not violate application security policy. This flaw is categorized as low severity because it only impacts confidentiality, not integrity or availability. However, in the context of a mobile application, the significance of an information leak may be much greater, especially if misaligned with user expectations or data privacy policies. References: CWE (https://cwe.mitre.org/data/definitions/201.html) OWASP Security Misconfiguration


  • Hi @LLima925770 (Community Member)​ ,

     

    Exposing errors externally, such as returning detailed error messages to clients in a production environment, can pose security risks and may not be the best practice for several reasons:

    1. Security: Detailed error messages can reveal sensitive information about your application's internals, such as database schema, code structure, or potentially even API keys or credentials. Malicious actors can use this information to exploit vulnerabilities in your system.
    2. Information Leakage: Providing detailed error messages can leak information that could be valuable to attackers. For example, if a SQL error message is returned with specific table or column names, an attacker might attempt SQL injection attacks targeting those specific elements.
    3. User Experience: Exposing internal error messages to end-users can be confusing and frustrating. Users may not understand the technical details of the error and might be alarmed or discouraged from using your application.
    4. Security by Obscurity: Relying on the obscurity of your error messages as a security measure is not a good practice. It's better to have strong security practices in place, like input validation and proper authentication and authorization mechanisms, rather than hoping that error messages won't be exploited.
    5. Compliance: In some industries or regions, there are regulations like GDPR that require organizations to minimize data exposure, which includes not exposing unnecessary error details to end-users.

     

    Instead of exposing detailed error messages externally, you should follow these best practices:

    1. Log Errors: Always log errors on the server-side. This allows you to capture all necessary information for debugging and monitoring while keeping it hidden from end-users.
    2. Use Generic Error Messages: Return generic error messages to clients that do not disclose sensitive details. For example, you might return a 500 Internal Server Error without specific error details. You can include a reference code or error code that can be logged on the server side to help with debugging.
    3. Handle Errors Gracefully: Implement error-handling middleware or mechanisms to gracefully handle errors and provide a consistent user experience. You can log the detailed error on the server while showing a user-friendly error message to the client.
    4. Implement Rate Limiting and Security Measures: Implement rate limiting, request validation, and security measures to prevent malicious attacks like brute force, SQL injection, or cross-site scripting (XSS) attacks.
    5. Monitor and Alert: Set up monitoring and alerting systems to be notified of errors as they occur in your application. This enables you to proactively address issues before they become critical.

     

    In summary, the practice of exposing detailed error messages externally is discouraged due to security risks and the potential negative impact on user experience. Instead, you should log errors on the server, return generic error messages to clients, and implement strong security measures to protect your application.

     

    Thank you,

    Boy Baukema

    Expand Post

Topics (4)

No articles found
Loading

Ask the Community

Get answers, share a use case, discuss your favorite features, or get input from the community.