CWE-540 Base Incompleto

Inclusion of Sensitive Information in Source Code

This vulnerability occurs when sensitive information like passwords, API keys, or internal logic is exposed within source code that remains accessible on a web server or in a public repository.

Definição

What is CWE-540?

This vulnerability occurs when sensitive information like passwords, API keys, or internal logic is exposed within source code that remains accessible on a web server or in a public repository.
Leaving source code containing sensitive data on a live server creates a major security risk. Attackers can directly access these files to harvest credentials, encryption keys, or understand application logic, bypassing the intended security controls of the compiled or executed application. For example, if an attacker retrieves a Perl, Python, or PHP script's source, they can analyze it for bugs, hardcoded database logins, or business logic flaws. This information dramatically simplifies launching further attacks, as it provides a blueprint of the application's weaknesses and secret mechanisms.
Impacto no mundo real

Real-world CVEs caused by CWE-540

  • Server for Team Awareness Kit (TAK) application includes sensitive tokens in the JavaScript source code.

  • The LDAP password might be visible in the html code of a rendered page in an IT Asset Management tool.

  • Version numbers and internal hostnames leaked in HTML comments.

Como os atacantes a exploram

Trajeto do atacante passo a passo

  1. 1

    The following code uses an include file to store database credentials:

  2. 2

    database.inc

  3. 3

    login.php

  4. 4

    If the server does not have an explicit handler set for .inc files it may send the contents of database.inc to an attacker without pre-processing, if the attacker requests the file directly. This will expose the database name and password.

  5. 5

    The following comment, embedded in a JSP, will be displayed in the resulting HTML output.

Exemplo de código vulnerável

Vulnerable PHP

database.inc

Vulnerável PHP
<?php
  $dbName = 'usersDB';
  $dbPassword = 'skjdh#67nkjd3$3$';
  ?>
Exemplo de código seguro

Secure pseudo

Seguro pseudo
// Validate, sanitize, or use a safe API before reaching the sink.
function handleRequest(input) {
  const safe = validateAndEscape(input);
  return executeWithGuards(safe);
}
What changed: the unsafe sink is replaced (or the input is validated/escaped) so the same payload no longer triggers the weakness.
Lista de verificação de prevenção

How to prevent CWE-540

  • Architecture and Design / System Configuration Recommendations include removing this script from the web server and moving it to a location not accessible from the Internet.
Sinais de deteção

How to detect CWE-540

SAST High

Executar análise estática (SAST) na base de código à procura do padrão inseguro no fluxo de dados.

DAST Moderate

Executar testes dinâmicos de segurança de aplicações (DAST) contra o endpoint em execução.

Runtime Moderate

Monitorizar os registos em tempo de execução para traços de exceção invulgares, input malformado ou tentativas de contornar a autorização.

Code review Moderate

Revisão de código: sinalizar qualquer novo código que trate input desta superfície sem usar os ajudantes validados do framework.

Correção automática do Plexicus

O Plexicus deteta automaticamente o CWE-540 e abre um PR de correção em menos de 60 segundos.

O Codex Remedium analisa cada commit, identifica esta fraqueza exata e entrega um pull request pronto para revisão com o patch. Sem tickets. Sem transferências.

Perguntas frequentes

Frequently asked questions

O que é o CWE-540?

This vulnerability occurs when sensitive information like passwords, API keys, or internal logic is exposed within source code that remains accessible on a web server or in a public repository.

Qual a gravidade do CWE-540?

A MITRE não publicou uma classificação de probabilidade de exploração para esta fraqueza. Trate-a como impacto médio até o seu modelo de ameaças provar o contrário.

Que linguagens ou plataformas são afetadas pelo CWE-540?

A MITRE não especificou as plataformas afetadas por este CWE — pode aplicar-se à maioria das stacks de aplicações.

Como posso prevenir o CWE-540?

Recommendations include removing this script from the web server and moving it to a location not accessible from the Internet.

Como é que o Plexicus deteta e corrige o CWE-540?

O motor SAST do Plexicus correlaciona a assinatura de fluxo de dados do CWE-540 em cada commit. Quando é encontrada uma correspondência, o nosso agente Codex Remedium abre um PR de correção com o código corrigido, testes e um resumo de uma linha para o revisor.

Onde posso saber mais sobre o CWE-540?

A MITRE publica a definição canónica em https://cwe.mitre.org/data/definitions/540.html. Pode também consultar a documentação da OWASP e do NIST para orientações adjacentes.

Pronto quando você estiver

Pare de pagar por desenvolvedor.
Comece a fechar o ciclo.

O Plexicus é o ASPM nativo de IA que verifica, filtra, corrige, pentesta e explica — de forma autónoma. Programadores ilimitados, repos ilimitados, ações de IA de utilização justa. Nível gratuito real, €269/mo anual quando estiver pronto.