Skip to content

Use of externally-controlled format string

Description

The application allows user input to control format string parameters. By passing invalid format string specifiers an adversary could cause the application to throw exceptions or possibly leak internal information depending on application logic.

Examples

Insecure Code

java
String formatStr = "User input: " + userInput; System.out.printf(formatStr);

Secure Code

java
String formatStr = "User input: %s"; System.out.printf(formatStr, userInput);

Remediation

Replace all format string arguments with hardcoded format strings containing the necessary specifiers.

Rule Details

FieldValue
IDCODE-0725
CategoryInjection
SeverityMEDIUM
CWECWE-134
ConfidenceHIGH
ImpactMEDIUM
LikelihoodHIGH
ExploitabilityEASY
Tagsformat string injection, user input
OWASPA1:2017-Injection, A03:2021-Injection