[英]Best way to disarm user-uploaded PDFs
我接受 PDF 作為用戶輸入。 我知道上傳的 PDF 不應該/不需要包含任何可能被惡意使用的內容類型,如 JS 或 AA。 例如,這是一個干凈的 PDF 應該具有的(使用 Didier Stevens PDFiD檢查):
<Keyword Count="59" HexcodeCount="0" Name="obj"/>
<Keyword Count="59" HexcodeCount="0" Name="endobj"/>
<Keyword Count="19" HexcodeCount="0" Name="stream"/>
<Keyword Count="19" HexcodeCount="0" Name="endstream"/>
<Keyword Count="2" HexcodeCount="0" Name="xref"/>
<Keyword Count="2" HexcodeCount="0" Name="trailer"/>
<Keyword Count="2" HexcodeCount="0" Name="startxref"/>
<Keyword Count="12" HexcodeCount="0" Name="/Page"/>
<Keyword Count="0" HexcodeCount="0" Name="/Encrypt"/>
<Keyword Count="0" HexcodeCount="0" Name="/ObjStm"/>
<Keyword Count="0" HexcodeCount="0" Name="/JS"/>
<Keyword Count="0" HexcodeCount="0" Name="/JavaScript"/>
<Keyword Count="0" HexcodeCount="0" Name="/AA"/>
<Keyword Count="0" HexcodeCount="0" Name="/OpenAction"/>
<Keyword Count="0" HexcodeCount="0" Name="/AcroForm"/>
<Keyword Count="0" HexcodeCount="0" Name="/JBIG2Decode"/>
<Keyword Count="0" HexcodeCount="0" Name="/RichMedia"/>
<Keyword Count="0" HexcodeCount="0" Name="/Launch"/>
<Keyword Count="0" HexcodeCount="0" Name="/EmbeddedFile"/>
<Keyword Count="0" HexcodeCount="0" Name="/XFA"/>
<Keyword Count="0" HexcodeCount="0" Name="/Colors > 2^24"/>
我當前的用戶輸入驗證是查看所有內容類型,如果從“加密”向下計數為 != 0,則拒絕 PDF。
我相信有時當人們點擊“打印到 pdf”時,取決於使用的轉換器軟件,有時會添加其中一些內容類型。 所以我目前拒絕 PDF,即使可疑內容類型實際上是無辜的。 當然,我無法確定 JS 是否無辜,但我想解除 JS 並繼續處理文件。
有沒有一種方法可以讓我在內存中保存一個 PDF,然后自動解除/解除它,覆蓋以前的文件? 我想做這樣的事情
SuspectPDF = request.FILES['docfile'][0]
CleanPDF = disarmPDF(SuspectPDF)
我知道 PDFiD 具有解除武裝功能,但我不確定它能否在內存中完成我想要的操作。 我很想知道是否還有其他更常用的用戶輸入 PDF 驗證解決方案,以及這里是否還有其他需要注意的事項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.