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.)
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…
What is CWE-547?
Real-world CVEs caused by CWE-547
Aucune référence CVE publique n'est liée à ce CWE dans le catalogue MITRE pour le moment.
Parcours de l'attaquant étape par étape
- 1
The usage of symbolic names instead of hard-coded constants is preferred.
- 2
The following is an example of using a hard-coded constant instead of a symbolic name.
- 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
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.
Vulnerable C
The following is an example of using a hard-coded constant instead of a symbolic name.
char buffer[1024];
...
fgets(buffer, 1024, stdin); 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.
enum { MAX_BUFFER_SIZE = 1024 };
...
char buffer[MAX_BUFFER_SIZE];
...
fgets(buffer, MAX_BUFFER_SIZE, stdin); How to prevent CWE-547
- Implementation Avoid using hard-coded constants. Configuration files offer a more flexible solution.
How to detect CWE-547
Plexicus détecte automatiquement CWE-547 et ouvre une PR de correction en moins de 60 secondes.
Codex Remedium analyse chaque commit, identifie cette faiblesse précise et livre une pull request prête à être relue avec le correctif. Pas de tickets. Pas de transferts.
Frequently asked questions
Qu'est-ce que 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.
Quelle est la gravité de CWE-547 ?
MITRE n'a pas publié de note de probabilité d'exploitation pour cette faiblesse. Traitez-la comme un impact moyen jusqu'à ce que votre modèle de menace prouve le contraire.
Quels langages ou plateformes sont affectés par CWE-547 ?
MITRE n'a pas spécifié les plateformes affectées pour ce CWE — il peut s'appliquer à la plupart des stacks applicatives.
Comment puis-je prévenir CWE-547 ?
Avoid using hard-coded constants. Configuration files offer a more flexible solution.
Comment Plexicus détecte et corrige CWE-547 ?
Le moteur SAST de Plexicus reconnaît la signature de flux de données de CWE-547 à chaque commit. Lorsqu'une correspondance est trouvée, notre agent Codex Remedium ouvre une PR de correction avec le code corrigé, les tests et un résumé d'une ligne pour le relecteur.
Où puis-je en savoir plus sur CWE-547 ?
MITRE publie la définition canonique à https://cwe.mitre.org/data/definitions/547.html. Vous pouvez également consulter la documentation OWASP et NIST pour des conseils adjacents.
Weaknesses related to CWE-547
Inappropriate Source Code Style or Formatting
This weakness occurs when source code violates established style guidelines for formatting, indentation, whitespace, or commenting, making…
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…
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…
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…
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…
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…
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…
Inappropriate Whitespace Style
This weakness occurs when source code uses inconsistent or non-standard whitespace formatting, such as irregular indentation, spacing, or…
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…
Arrêtez de payer par développeur.
Commencez à fermer la boucle.
Plexicus est l'ASPM natif IA qui scanne, filtre, corrige, penteste et explique — de façon autonome. Développeurs illimités, dépôts illimités, actions IA à usage équitable. Vrai niveau gratuit, €269/mo annuel quand vous êtes prêt.