Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

258
Visualizações
How to sanitize the readFileSync node js function input

I am trying to sanitize the input source JSON data in the below function. However, the Checkmarx tool still complains no matter where I add the sanitizeObject(). Appreciate any pointers

const fs = require('fs')
const config = require('config')
var _require = require('jsdom'),
    JSDOM = _require.JSDOM;

var window = new JSDOM('').window;
var DOMPurify = createDOMPurify(window);


function sanitizeValue(value){
      return DOMPurify.sanitize(value);

}

function sanitizeObject(obj) {
  var sanitizedObject = {};
  Object.keys(obj).forEach(function (key) {
    sanitizedObject[key] = sanitizeValue(obj[key]);
  });
  return sanitizedObject;
};

const getMyData = () => {

 let myData = JSON.parse(sanitizeObject(fs.readFileSync('./my/dist/path/mydata.json')))

return myData
}

Checkmarx error: Stored-CSS error as follows

complains at readFileSync

The application's = embeds untrusted data in the generated output with send, at Xx of module.js. This untrusted data is embedded straight into the output without proper sanitization or encoding, enabling an attacker to inject malicious code into the output.

The attacker would be able to alter the returned web page by saving malicious data in a data-store ahead of time. The attacker's modified data is then read from the database by the = method with readFileSync, at line 11 of module.js. This untrusted data then flows through the code straight to the output web page, without sanitization.

This can enable a Stored Cross-Site Scripting (XSS) attack

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda