Skip to content

Latest commit

 

History

History
42 lines (34 loc) · 1.69 KB

exposure.md

File metadata and controls

42 lines (34 loc) · 1.69 KB

Sensitive Data Exposure

The code below is vulnureable to Sensitive Data Exposure

// This code is for the login form on the front end

// Read the user's input from the form
let username = document.getElementById("username").value;
let password = document.getElementById("password").value;

// Set the authentication token
let token = "1234567890abcdef";

// Send a request to the backend with the user's credentials and the token
fetch("http://example.com/login", {
  method: "POST",
  headers: {
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    username: username,
    password: password,
    token: token
  })
})
  .then(response => {
    // Handle the response from the server
  })
  .catch(error => {
    // Handle any errors
  });

Why it's vulnerable?

The code is sending a request to the backend with the user's credentials and an authentication token. However, the token is included in a comment in the code, which means it is potentially visible to anyone who has access to the JavaScript file.

Impact?

This could allow an attacker to see the token and potentially use it to gain unauthorized access to the backend.

How to fix?

To avoid this type of sensitive data exposure, it is important to handle sensitive information, such as authentication tokens, carefully and securely. In this case, the token should not be included in the code as a comment, and it should be stored in a secure location, such as a configuration file that is not accessible from the front end. Additionally, the token should be encrypted when it is transmitted to the backend, and a secure method, such as a token-based authentication scheme, should be used to verify its authenticity.