CWE-134: Use of Externally-Controlled Format String

What is CWE-134?

CWE-134 is Use of Externally-Controlled Format String. The flaw arises when the product passes an externally sourced string to a function that accepts a format string argument. The database currently holds 51 vulnerabilities mapped to CWE-134 and none of them are in the CISA Known Exploited Vulnerabilities catalog.

OWASP Top 10 Rank-
Related CVES (365 days)51
AbstractionBase
Likelihood of exploitHigh

Vulnerabilities mapped to CWE-134

51 vulnerabilities292% increase year over year

No data

No vulnerability data in CISA KEV for CWE-134

Official definition

ByMitre CWE

The product uses a function that accepts a format string as an argument, but the format string originates from an external source.

Detailed description

The flaw occurs when untrusted data is mixed with the control syntax of a formatting function. If the external string is interpreted as the format template rather than ordinary text, its format specifiers can alter how the function reads or writes data, change the representation of output, or trigger unintended behavior. The issue is commonly introduced in logging and error-message code, and can also involve localization or internationalization message repositories when those repositories are controllable.

Characteristics

This weakness arises when externally sourced data is placed directly in the format-string position of a formatting function instead of being passed only as data to format. It is often introduced unintentionally when code constructs log messages or error messages but omits a constant format string; localization and internationalization repositories can also provide a source of format-string control when an attacker can modify them. The record identifies C and C++ as common affected languages, Perl as rare, and Python as undetermined, while the weakness itself is not language-specific.

Common consequences

A format-string issue can disclose memory contents, which may substantially simplify further exploitation. It can also modify memory or lead to unauthorized code or command execution, and may cause buffer overflows, denial of service, or incorrect data representation. The recorded impact scopes are confidentiality, integrity, and availability.

ImpactScopeExplanation
Read MemoryConfidentialityFormat string problems allow for information disclosure which can severely simplify exploitation of the program.
Modify Memory, Execute Unauthorized Code or CommandsIntegrity, Confidentiality, AvailabilityFormat string problems can result in the execution of arbitrary code, buffer overflows, denial of service, or incorrect data representation.

Risk mitigations

At the requirements stage, choose a language that is not subject to this flaw. During implementation, pass every format-string function a static string that users cannot control, supply the correct number of arguments, and, where possible, use functions that do not support the %n operator in format strings. During build and compilation, use high compiler and linker warning levels because they may identify incorrect usage.

  1. RequirementsChoose a language that is not subject to this flaw.
  2. ImplementationEnsure that all format string functions are passed a static string which cannot be controlled by the user, and that the proper number of arguments are always sent to that function as well. If at all possible, use functions that do not support the %n operator in format strings. [REF-116] [REF-117]
  3. Build and CompilationRun compilers and linkers with high warning levels, since they may detect incorrect usage.

Detection methods

Automated static analysis can often identify this weakness, including through data-flow analysis or constraint-based techniques that reduce false positives. Recommended static approaches also include manual source review, automated source-code weakness analyzers, context-configured analyzers, compiler warning flags, and automated or manual binary and bytecode analysis; automated source analysis, manual source review, and automated binary or bytecode analysis are rated highly effective, while manual binary or bytecode analysis provides only partial coverage. Architecture and design review can use formal methods, correct-by-construction techniques, and IEEE 1028 inspection, with high effectiveness in the record. Dynamic approaches include web-application, web-services, and database scanners, as well as automated or framework-based fuzzers, but these provide only partial coverage; black-box testing is limited because format strings often occur in rare error-handling paths such as logging, and latent issues may remain in executables without associated source code.

MethodApproachEffectiveness
Automated Static AnalysisThis weakness can often be detected using automated static analysis tools. Many modern tools use data flow analysis or constraint-based techniques to minimize the number of false positives.-
Black BoxSince format strings often occur in rarely-occurring erroneous conditions (e.g. for error message logging), they can be difficult to detect using black box methods. It is highly likely that many latent issues exist in executables that do not have associated source code (or equivalent source.Limited
Automated Static Analysis - Binary or BytecodeAccording to SOAR [REF-1479], the following detection techniques may be useful: ``` Highly cost effective: ``` Bytecode Weakness Analysis - including disassembler + source code weakness analysis Binary Weakness Analysis - including disassembler + source code weakness analysis ``` Cost effective for partial coverage: ``` Binary / Bytecode simple extractor - strings, ELF readers, etc.High
Manual Static Analysis - Binary or BytecodeAccording to SOAR [REF-1479], the following detection techniques may be useful: ``` Cost effective for partial coverage: ``` Binary / Bytecode disassembler - then use manual analysis for vulnerabilities & anomaliesSOAR Partial
Dynamic Analysis with Automated Results InterpretationAccording to SOAR [REF-1479], the following detection techniques may be useful: ``` Cost effective for partial coverage: ``` Web Application Scanner Web Services Scanner Database ScannersSOAR Partial
Dynamic Analysis with Manual Results InterpretationAccording to SOAR [REF-1479], the following detection techniques may be useful: ``` Cost effective for partial coverage: ``` Fuzz Tester Framework-based FuzzerSOAR Partial
Manual Static Analysis - Source CodeAccording to SOAR [REF-1479], the following detection techniques may be useful: ``` Highly cost effective: ``` Manual Source Code Review (not inspections) ``` Cost effective for partial coverage: ``` Focused Manual Spotcheck - Focused manual analysis of sourceHigh
Automated Static Analysis - Source CodeAccording to SOAR [REF-1479], the following detection techniques may be useful: ``` Highly cost effective: ``` Source code Weakness Analyzer Context-configured Source Code Weakness Analyzer ``` Cost effective for partial coverage: ``` Warning FlagsHigh
Architecture or Design ReviewAccording to SOAR [REF-1479], the following detection techniques may be useful: ``` Highly cost effective: ``` Formal Methods / Correct-By-Construction ``` Cost effective for partial coverage: ``` Inspection (IEEE 1028 standard) (can apply to requirements, design, source code, etc.)High

Representative vulnerabilities

The following are representative examples, not an exhaustive list of vulnerabilities for this weakness:

  • CVE-2002-1825: a format string in a Perl program.
  • CVE-2001-0717 and CVE-2002-0573: a format string in an incorrect call to syslog.
  • CVE-2002-1788: format strings in NNTP server responses.
  • CVE-2006-2480: exploitation by triggering errors or warnings, with format-string specifiers supplied in a .bmp filename.
  • CVE-2007-2027: a resultant format-string issue after an untrusted search path enabled loading malicious internationalization messages.
Sources (2)

CWE™ Program, operated by The MITRE Corporation. Copyright © 2006–2026, The MITRE Corporation. The MITRE Corporation hereby grants you a non-exclusive, royalty-free license to use CWE for research, development, and commercial purposes. CWE Terms of Use.

Learn more

Run an in-depth assessment with complete web risk management

CyStack VulnScan continuously discovers assets, validates vulnerabilities, and helps security teams prioritize remediation across the organization.