Skip to content

Commit

Permalink
feat(pdf_upload): Add MIME type validation to ensure data integrity
Browse files Browse the repository at this point in the history
  • Loading branch information
ERosendo committed Oct 1, 2024
1 parent 43b6a8a commit dbb4b31
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/pdf_upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ const downloadDataFromIframe = async(match, tabId) => {
? fetch
: window.fetch;
const blob = await browserSpecificFetch(match[2]).then((res) => res.blob());
const fileType = blob.type;
// Allow only specific file types (e.g., PDF) to be stored in the tab storage.
// This ensures data integrity.
const allowedTypes = ['application/pdf'];
if (!allowedTypes.includes(fileType)) return;
const dataUrl = await blobToDataURL(blob);
// store the blob in chrome storage for the background worker
await updateTabStorage({ [tabId]: { ['pdf_blob']: dataUrl } });
Expand Down Expand Up @@ -211,6 +216,7 @@ const showAndUploadPdf = async function (
history.replaceState({ content: previousPageHtml }, '');

let blob = await downloadDataFromIframe(match, this.tabId);
if (!blob) return document.documentElement.innerHTML = html_elements;
let blobUrl = URL.createObjectURL(blob);
let pacer_case_id;

Expand Down

0 comments on commit dbb4b31

Please sign in to comment.