mozilla / pdf.js

PDF Reader in JavaScript
https://mozilla.github.io/pdf.js/
Apache License 2.0
48.33k stars 9.97k forks source link

AWS S3 Storage Signed Key Issue #17001

Closed mikolajtutorum closed 1 year ago

mikolajtutorum commented 1 year ago

Configuration:

Steps to reproduce the problem:

  1. Create AWS S3 Storage Bucket without public access, generate signed key.
  2. Inject S3 URL with signed key into pdfjs

What is the expected behavior? PDF Viewer displays PDF file from S3 link with signed keys

What went wrong?

Original incoming signed key (shows as the same on console.log from javascript variable)

https://bucket-name.s3.eu-central-1.amazonaws.com/935ddbf8-b862-4391-9bba-dc54b53ae41a/Y-1-A-2-M-1-L-1.pdf?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=CREDENTIAL%2F20230921%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Date=20230921T153158Z&X-Amz-SignedHeaders=host&X-Amz-Expires=5&X-Amz-Signature=ec647cb015d7867ff5452efba8ced45d4bada02f8341fc02a54995a565487fb6

_When it reaches webpack://pdfjs-dist/build/pdf/src/display/fetch_stream.js it is disfigured with amp;_

https://bucket-name.eu-central-1.amazonaws.com/935ddbf8-b862-4391-9bba-dc54b53ae41a/Y-1-A-2-M-1-L-1.pdf?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=CREDENTIAL%2F20230921%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Date=20230921T153158Z&X-Amz-SignedHeaders=host&X-Amz-Expires=5&X-Amz-Signature=ec647cb015d7867ff5452efba8ced45d4bada02f8341fc02a54995a565487fb6

pdfjs viewer doesn't load it up, returns 400 Bad Request.

I have the exact same PDF loading up with just an embed feature:

<embed src="{{ $temporarySignedUrl }}" width="600" height="500" alt="pdf" pluginspage="http://www.adobe.com/products/acrobat/readstep2.html">

Snuffleupagus commented 1 year ago

PDF.js version: pdfjs-3.8.162-dist

That version is no longer supported, please find the latest releases at https://mozilla.github.io/pdf.js/getting_started/#download

Steps to reproduce the problem:

  1. Create AWS S3 Storage Bucket without public access, generate signed key.
  2. Inject S3 URL with signed key into pdfjs

Please see https://github.com/mozilla/pdf.js/blob/master/.github/CONTRIBUTING.md (emphasis mine):

If you are developing a custom solution, first check the examples at https://github.com/mozilla/pdf.js#learning and search existing issues. If this does not help, please prepare a short well-documented example that demonstrates the problem and make it accessible online on your website, JS Bin, GitHub, etc. before opening a new issue or contacting us in the Matrix room -- keep in mind that just code snippets won't help us troubleshoot the problem.

timvandermeij commented 1 year ago

Closing until a working example is provided, with a working URL we can test with, otherwise this is not actionable.