CWE-547 Base Rascunho

Use of Hard-coded, Security-relevant Constants

This vulnerability occurs when code directly embeds security-critical values like passwords, cryptographic keys, or access levels as raw numbers or strings, instead of using named constants or…

Definição

What is CWE-547?

This vulnerability occurs when code directly embeds security-critical values like passwords, cryptographic keys, or access levels as raw numbers or strings, instead of using named constants or configuration files. This practice makes the code brittle and error-prone during updates or security reviews.
Hard-coding security values creates a maintenance nightmare. If a secret needs to be rotated or a permission level changed, developers must hunt through the entire codebase for every occurrence. Missing just one instance can introduce a security gap or break functionality. Once software is deployed, updating these embedded values often requires a full re-release, which may not even be possible in some environments. These constants also risk exposure if the code is ever leaked or reverse-engineered, turning a simple configuration change into a major breach. While SAST tools can flag the pattern, Plexicus uses AI to not only detect these hard-coded secrets but also suggest the specific code fix—like moving the value to a secure configuration manager—saving hours of manual refactoring and reducing human error.
Impacto no mundo real

Real-world CVEs caused by CWE-547

Ainda não há referências CVE públicas associadas a este CWE no catálogo da MITRE.

Como os atacantes a exploram

Trajeto do atacante passo a passo

  1. 1

    The usage of symbolic names instead of hard-coded constants is preferred.

  2. 2

    The following is an example of using a hard-coded constant instead of a symbolic name.

  3. 3

    If the buffer value needs to be changed, then it has to be altered in more than one place. If the developer forgets or does not find all occurrences, in this example it could lead to a buffer overflow.

  4. 4

    In this example the developer will only need to change one value and all references to the buffer size are updated, as a symbolic name is used instead of a hard-coded constant.

Exemplo de código vulnerável

Vulnerable C

The following is an example of using a hard-coded constant instead of a symbolic name.

Vulnerável C
char buffer[1024];
  ...
  fgets(buffer, 1024, stdin);
Exemplo de código seguro

Secure C

If the buffer value needs to be changed, then it has to be altered in more than one place. If the developer forgets or does not find all occurrences, in this example it could lead to a buffer overflow.

Seguro C
enum { MAX_BUFFER_SIZE = 1024 };
  ...
  char buffer[MAX_BUFFER_SIZE];
  ...
  fgets(buffer, MAX_BUFFER_SIZE, stdin);
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-547

  • Implementation Avoid using hard-coded constants. Configuration files offer a more flexible solution.
Sinais de deteção

How to detect CWE-547

Automated Static Analysis High

Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

Correção automática do Plexicus

O Plexicus deteta automaticamente o CWE-547 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-547?

This vulnerability occurs when code directly embeds security-critical values like passwords, cryptographic keys, or access levels as raw numbers or strings, instead of using named constants or configuration files. This practice makes the code brittle and error-prone during updates or security reviews.

Qual a gravidade do CWE-547?

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-547?

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-547?

Avoid using hard-coded constants. Configuration files offer a more flexible solution.

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

O motor SAST do Plexicus correlaciona a assinatura de fluxo de dados do CWE-547 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-547?

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

Fraquezas relacionadas

Weaknesses related to CWE-547

CWE-1078 Pai

Inappropriate Source Code Style or Formatting

This weakness occurs when source code violates established style guidelines for formatting, indentation, whitespace, or commenting, making…

CWE-1085 Irmão

Invokable Control Element with Excessive Volume of Commented-out Code

This weakness occurs when a callable function, method, or procedure contains a large amount of inactive, commented-out code within its…

CWE-1099 Irmão

Inconsistent Naming Conventions for Identifiers

This weakness occurs when a codebase uses mixed naming styles for elements like variables, functions, data types, or files, creating an…

CWE-1106 Irmão

Insufficient Use of Symbolic Constants

This weakness occurs when developers embed raw numbers or text strings directly in code instead of using named symbolic constants, making…

CWE-1107 Irmão

Insufficient Isolation of Symbolic Constant Definitions

This weakness occurs when a codebase uses symbolic constants (like named values for numbers or strings) but scatters their definitions…

CWE-1109 Irmão

Use of Same Variable for Multiple Purposes

This weakness occurs when a single variable is reused to handle multiple, unrelated tasks or to store different pieces of data throughout…

CWE-1113 Irmão

Inappropriate Comment Style

This weakness occurs when source code comments are written in a style or format that doesn't match the project's established standards or…

CWE-1114 Irmão

Inappropriate Whitespace Style

This weakness occurs when source code uses inconsistent or non-standard whitespace formatting, such as irregular indentation, spacing, or…

CWE-1115 Irmão

Source Code Element without Standard Prologue

This weakness occurs when source code files or modules lack a consistent, standardized header or prologue that the development team has…

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.