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

180
Visualizações
Nodejs security best practice regarding string values

I need to get the IP address using nodejs/express. Below is the statement I use for this.

const ipAddress = String(req.ip || "unknown");

Since req.ip originates from an HTTP header, a malicious user could change it. Is this then the best way to get the user's IP address?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I suppose how "secure" it is depends on what you are trying to secure against.

Generally an IP should be considered transient - users on mobile can enter or exit wifi or different cell towers, and their IP can change. IPs can also be spoofed.

If you are using Express, req.ip does NOT normally come from a header but from the connection itself. The exception is if you are using a reverse proxy -- are you? In which case we'll need more details about the proxy being used and your proxy setup. Proxies should be configured to always overwrite the X-Forwarded-For sent by the client, such that the header can always be trusted.

about 4 years ago · Juan Pablo Isaza Relatório

0

Here's the code I changed the above to:

let ipAddress = "";
if (req.ip === undefined) ipAddress = "unknown";
else ipAddress = String(req.ip);
about 4 years ago · Juan Pablo Isaza Relatório
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