Course contentsShow
← Security
Lesson 970 of 3,05220. Web Security - File Upload and ProcessingFree lesson

Filename Length and Special Character Attacks

Learn how excessively long filenames or special characters cause parsing errors and security bypasses.

Filename Length and Special Character Attacks

What you'll learn: How attackers exploit excessively long filenames or unusual characters to break validation logic and bypass security controls during file uploads.


The Core Problem

When applications process uploaded files, they often assume filenames will be "normal"—short, readable, with standard characters. Attackers exploit these assumptions by crafting filenames that are extremely long or contain special characters that confuse parsers, break validation logic, or trigger unexpected behavior in the filesystem or application code.

Think of it like a form designed for a reasonable name like "John Smith," but someone writes a 5,000-character name filled with quotation marks, null bytes, and Unicode symbols. Systems expecting normal input can break in unpredictable ways.


Why This Works

Length Attacks:

  • Buffer overflows in legacy systems that don't handle long strings safely
  • Truncation that removes file extensions: malicious.php + 200 padding characters + .txt becomes malicious.php... (truncated before .txt)
  • Database or filesystem limits cause errors that bypass validation

Special Character Attacks:

  • Newlines (\n) can break log files or CSV parsers
  • Unicode homoglyphs make malicious.phр (Cyrillic 'р') look like .php but bypass extension checks
  • Control characters (\x00, tabs, carriage returns) confuse string handling
  • Quote marks, semicolons, or pipes can break shell commands if filenames are passed unsafely

Real-World Impact

An application might validate the last four characters as .jpg, but a 300-character filename gets truncated by the filesystem to 255 characters—chopping off .jpg and leaving .php exposed. Or special Unicode characters make a dangerous extension appear safe during validation but execute as code during processing.


Key Takeaway:
Always sanitize filenames by enforcing strict length limits, stripping special characters, and normalizing Unicode before validation—never trust that user-provided filenames are safe or reasonable.