Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving password protected PDF file without inputting the password saves an HTML page instead #15085

Open
ericonr opened this issue Jun 23, 2022 · 3 comments · May be fixed by #19632
Open

Saving password protected PDF file without inputting the password saves an HTML page instead #15085

ericonr opened this issue Jun 23, 2022 · 3 comments · May be fixed by #19632

Comments

@ericonr
Copy link

ericonr commented Jun 23, 2022

Attach (recommended) or Link to PDF file here:

05 - Amplificador diferencial.pdf

Configuration:

  • Web browser and its version: Firefox 101.0.1
  • Operating system and its version: Void Linux (rolling release)
  • PDF.js version: the one built into firefox
  • Is a browser extension: no, built-in

Steps to reproduce the problem:

  1. Open a link to a password protected PDF file
  2. Don't input the password, press ESC to close the password input prompt and access the rest of the UI
  3. Click the download button

What is the expected behavior? (add screenshot)

The downloaded file is the PDF file.

What went wrong? (add screenshot)

The downloaded file is an HTML file (but with the name and file extension of the PDF file) that appears to be equivalent to saving the current page via browser functionality.

This is especially annoying because I have password protected PDF files on Google Classroom, and the download button from their UI makes the PDF open in PDF.js automatically, and instead of simply saving it from there, I need to input the password first.

@Snuffleupagus
Copy link
Collaborator

Snuffleupagus commented Jun 23, 2022

My suspicion is that this actually goes wrong somewhere in the platform-code, when we try to download a PDF document from a URL-string that does not (clearly) end with .pdf.

Until the PDF document has loaded, which in this case requires entering a password, downloading triggers the following code-paths through the viewer/platform code:

  1. pdf.js/web/app.js

    Lines 998 to 1002 in c5dc082

    } catch (reason) {
    // When the PDF document isn't ready, or the PDF file is still
    // downloading, simply download using the URL.
    await this.downloadManager.downloadUrl(url, filename);
    }

  2. pdf.js/web/firefoxcom.js

    Lines 107 to 112 in c5dc082

    downloadUrl(url, filename) {
    FirefoxCom.request("download", {
    originalUrl: url,
    filename,
    });
    }
    where the url-parameter contains something like https://objects.githubusercontent.com/github-production-repository-file-5c1aeb/1663468/8963184?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20220623%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220623T123404Z&X-Amz-Expires=300&X-Amz-Signature=531edafe8105eb7743085ad1f806c9d1e8a39b2e5f1b9fb34284f4bb94f2f663&X-Amz-SignedHeaders=host&actor_id=2692120&key_id=0&repo_id=1663468&response-content-disposition=attachment%3Bfilename%3D05.-.Amplificador.diferencial.pdf&response-content-type=application%2Fpdf

  3. https://searchfox.org/mozilla-central/rev/6d0ba065e3d41822337c708c8c0aca334ddd9218/toolkit/components/pdfjs/content/PdfStreamConverter.jsm#347-364

  4. https://searchfox.org/mozilla-central/rev/6d0ba065e3d41822337c708c8c0aca334ddd9218/toolkit/components/pdfjs/content/PdfjsParent.jsm#100-117

  5. https://searchfox.org/mozilla-central/rev/6d0ba065e3d41822337c708c8c0aca334ddd9218/toolkit/content/contentAreaUtils.js#54-72

  6. My suspicion is thus that the following function isn't able to, in this particular case, determine that the URL-string actually points to a PDF document: https://searchfox.org/mozilla-central/rev/6d0ba065e3d41822337c708c8c0aca334ddd9218/toolkit/content/contentAreaUtils.js#194-263

Possibly a stupid suggestion, but: Maybe we could utilize the newly added aOriginalURL-parameter to help "inform" internalSave that this is actually a PDF document?

/cc @calixteman

@ericonr
Copy link
Author

ericonr commented Jun 25, 2022

Thank you for the in-depth look! I'm not at all familiar with web development or JavaScript, so I'm not sure I can help much.

@calixteman
Copy link
Contributor

I just tested in nightly, beta and release. I can reproduce the issue in either beta and release but not in nightly.
:ericonr, could you try on nightly to see if it is ok for you too ?

https://www.mozilla.org/en-US/firefox/channel/desktop/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants