CWE-42 Variante Incomplet

Path Equivalence: 'filename.' (Trailing Dot)

This vulnerability occurs when a system accepts file or directory paths that end with a dot (like 'file.txt.' or 'folder.') without properly checking them. Attackers can exploit this to bypass…

Définition

What is CWE-42?

This vulnerability occurs when a system accepts file or directory paths that end with a dot (like 'file.txt.' or 'folder.') without properly checking them. Attackers can exploit this to bypass security checks, potentially accessing files or directories they shouldn't be able to reach.
Many operating systems, particularly Windows, treat a trailing dot in a path as functionally equivalent to the same path without the dot. For example, 'secret.txt.' might resolve to 'secret.txt'. This happens because the file system APIs often normalize the path by stripping the trailing dot before processing it. However, security checks—like those verifying file extensions or path permissions—might be performed before this normalization, or might treat 'file.txt' and 'file.txt.' as different strings. This creates a mismatch where the security logic sees one path, but the underlying system accesses another. As a developer, you can prevent this by consistently normalizing and canonicalizing all file paths before using them in any security-critical operations. Always use the same system APIs for both validation and the final file access. Never rely on simple string comparison for path validation. Implement strict allow-lists for permitted file extensions and directories, and ensure your validation logic accounts for all possible operating system path equivalencies.
Impact réel

Real-world CVEs caused by CWE-42

Comment les attaquants l'exploitent

Parcours de l'attaquant étape par étape

  1. 1

    Identifier un chemin de code qui traite des entrées non fiables sans validation.

  2. 2

    Élaborer une charge utile qui exploite le comportement non sécurisé — injection, traversal, débordement ou abus de logique.

  3. 3

    Délivrer la charge utile via une requête normale et observer la réaction de l'application.

  4. 4

    Itérer jusqu'à ce que la réponse divulgue des données, exécute le code de l'attaquant ou élève les privilèges.

Exemple de code vulnérable

Vulnerable pseudo

MITRE n'a pas publié d'exemple de code pour ce CWE. Le motif ci-dessous est illustratif — voir Ressources pour les références canoniques.

Vulnérable pseudo
// Example pattern — see MITRE for the canonical references.
function handleRequest(input) {
  // Untrusted input flows directly into the sensitive sink.
  return executeUnsafe(input);
}
Exemple de code sécurisé

Secure pseudo

Sécurisé 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.
Liste de contrôle de prévention

How to prevent CWE-42

  • Architecture Use safe-by-default frameworks and APIs that prevent the unsafe pattern from being expressible.
  • Implementation Validate input at trust boundaries; use allowlists, not denylists.
  • Implementation Apply the principle of least privilege to credentials, file paths, and runtime permissions.
  • Testing Cover this weakness in CI: SAST rules + targeted unit tests for the data flow.
  • Operation Monitor logs for the runtime signals listed in the next section.
Signaux de détection

How to detect CWE-42

SAST High

Exécuter une analyse statique (SAST) sur le code source à la recherche du motif non sécurisé dans le flux de données.

DAST Moderate

Exécuter des tests de sécurité applicative dynamique (DAST) contre le point de terminaison en ligne.

Runtime Moderate

Surveiller les journaux runtime pour détecter des traces d'exception inhabituelles, des entrées malformées ou des tentatives de contournement d'autorisation.

Code review Moderate

Revue de code : signaler tout nouveau code qui traite les entrées de cette surface sans utiliser les helpers du framework validés.

Correction automatique Plexicus

Plexicus détecte automatiquement CWE-42 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.

Questions fréquentes

Frequently asked questions

Qu'est-ce que CWE-42 ?

This vulnerability occurs when a system accepts file or directory paths that end with a dot (like 'file.txt.' or 'folder.') without properly checking them. Attackers can exploit this to bypass security checks, potentially accessing files or directories they shouldn't be able to reach.

Quelle est la gravité de CWE-42 ?

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

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

Use safe-by-default frameworks, validate untrusted input at trust boundaries, and apply the principle of least privilege. Cover the data-flow signature in CI with SAST.

Comment Plexicus détecte et corrige CWE-42 ?

Le moteur SAST de Plexicus reconnaît la signature de flux de données de CWE-42 à 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-42 ?

MITRE publie la définition canonique à https://cwe.mitre.org/data/definitions/42.html. Vous pouvez également consulter la documentation OWASP et NIST pour des conseils adjacents.

Faiblesses associées

Weaknesses related to CWE-42

CWE-41 Parent

Improper Resolution of Path Equivalence

This vulnerability occurs when an application fails to properly handle different text representations that refer to the same file or…

CWE-44 Frère

Path Equivalence: 'file.name' (Internal Dot)

This vulnerability occurs when an application accepts file paths containing internal dots (like 'file.ordir') without properly checking…

CWE-46 Frère

Path Equivalence: 'filename ' (Trailing Space)

This vulnerability occurs when an application processes file paths that end with a space character (like 'document.txt ') without properly…

CWE-47 Frère

Path Equivalence: ' filename' (Leading Space)

This vulnerability occurs when an application accepts file or directory paths that begin with a space character (like ' filename'),…

CWE-48 Frère

Path Equivalence: 'file name' (Internal Whitespace)

This vulnerability occurs when an application accepts file paths containing internal spaces (like 'file name') without proper validation.…

CWE-49 Frère

Path Equivalence: 'filename/' (Trailing Slash)

This vulnerability occurs when an application accepts file or directory paths that end with a slash (e.g., 'documents/') without properly…

CWE-50 Frère

Path Equivalence: '//multiple/leading/slash'

This vulnerability occurs when an application accepts file or directory paths containing multiple leading slashes (like…

CWE-51 Frère

Path Equivalence: '/multiple//internal/slash'

This vulnerability occurs when an application accepts file or directory paths containing multiple consecutive forward slashes (e.g.,…

CWE-52 Frère

Path Equivalence: '/multiple/trailing/slash//'

This vulnerability occurs when an application accepts file or directory paths containing multiple consecutive forward slashes (like…

Prêt quand vous l'êtes

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.