Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Interpretation of Java format strings is stricter than in languages such as C [Seacord 2005]. The standard library implementations throw appropriate exceptions when any conversion argument fails to match the corresponding format specifier. This approach reduces opportunities for malicious exploits. Nevertheless, malicious user input can exploit format strings and can cause information leaks or denial of service. As a result, strings from an untrusted source should not be incorporated into format strings.

...

In the absence of proper input validation, an attacker can determine the date against which the input is being verified , perhaps by supplying an input that includes one of the format string arguments %1$tm, %1$te, or %1$tY.

...

Code Block
bgColor#ccccff
class Format {
  static Calendar c = 
    new GregorianCalendar(1995, GregorianCalendar.MAY, 23);
  public static void main(String[] args) {  
    // args[0] is the credit card expiration date
    // Perform comparison with c, 
    // if it doesn't match print the following line
    System.out.printf("The input did not match! "
        + " HINT: It was issued on %1$terd of some month", args[0],c);
  }
}

Risk Assessment

Allowing user input to taint a format string may cause information leaks or denial of service.

...

CERT C Secure Coding Standard

FIO30-C. Exclude user input from format strings

CERT C++ Secure Coding Standard

FIO30-CPP. Exclude user input from format strings

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="735ab1416b82790d-2ec678a0-4b66473d-b0848e45-86100293582de29aab75fc3e"><ac:plain-text-body><![CDATA[

[ISO/IEC TR 24772:2010

http://www.aitcnet.org/isai/]

Injection [RST]

]]></ac:plain-text-body></ac:structured-macro>

MITRE CWE

CWE-134. Uncontrolled format string

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="e21addbe3a7af073-f68a69be-487d4d6c-b79e8b44-688d79584a332ab61b1941ae"><ac:plain-text-body><![CDATA[

[[API 2006

AA. Bibliography#API 06]]

[Class Formatter

http://java.sun.com/javase/6/docs/api/java/util/Formatter.html]

]]></ac:plain-text-body></ac:structured-macro>

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="97ff1b1687360a8e-610b3094-470c4fc7-809a980c-be63bad8095553ecb6df9052"><ac:plain-text-body><![CDATA[

[[Seacord 2005

AA. Bibliography#Seacord 05]]

Chapter 6, Formatted Output

]]></ac:plain-text-body></ac:structured-macro>

...