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

Ensure that the response-origin of range requests match the full request (issue 12744) #19028

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Snuffleupagus
Copy link
Collaborator

@Snuffleupagus Snuffleupagus commented Nov 12, 2024

The following cases are excluded in the patch:

  • The Firefox PDF Viewer, since it has been fixed on the platform side already; please see https://bugzilla.mozilla.org/show_bug.cgi?id=1683940

  • The PDFNodeStream-implementation, used in Node.js environments, since after recent changes that code only supports file://-URLs.

Note: The relevant unit-tests are updated to await the headersReady Promise before dispatching range requests, since that's consistent with the actual usage in the src/-folder.

Fixes #12744

@Snuffleupagus

This comment was marked as outdated.

@Snuffleupagus

This comment was marked as outdated.

@Snuffleupagus

This comment was marked as outdated.

@Snuffleupagus

This comment was marked as outdated.

@Snuffleupagus Snuffleupagus marked this pull request as ready for review November 12, 2024 14:57
@Snuffleupagus

This comment was marked as outdated.

@@ -121,6 +124,8 @@ class PDFFetchStreamReader {
createFetchOptions(headers, this._withCredentials, this._abortController)
)
.then(response => {
stream._responseOrigin.resolve(getResponseOrigin(response.url));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part may not be reached when the network request fails. Is it desirable to indefinitely postpone the resolution of the other responses?

Copy link
Collaborator Author

@Snuffleupagus Snuffleupagus Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully I've not misunderstood your comment, but please see below for why I don't believe this to be an issue in practice.

Ignoring the unit-tests here, please note that if the initial (i.e. full) request fails then we'll never actually get to a point where we dispatch any range requests.
More specifically, if the full request fails we'll end up here:

.catch(this._headersCapability.reject);
, which means that this message is rejected:

pdf.js/src/display/api.js

Lines 2654 to 2655 in 9bf9bbd

messageHandler.on("ReaderHeadersReady", async data => {
await this._fullReader.headersReady;

That message is then handled on the worker-thread:

this._headersReady = this._msgHandler
.sendWithPromise("ReaderHeadersReady")
.then(data => {
this._isStreamingSupported = data.isStreamingSupported;
this._isRangeSupported = data.isRangeSupported;
this._contentLength = data.contentLength;
});
, and finally we never actually try to load the document given:

pdf.js/src/core/worker.js

Lines 262 to 265 in 9bf9bbd

.catch(function (reason) {
pdfManagerCapability.reject(reason);
cancelXHRs = null;
});

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest version of the patch updates the unit-tests to agree with the "actual" usage, since that removes the need for the additional Promises in the code.

src/display/network_utils.js Show resolved Hide resolved
@@ -420,6 +430,14 @@ class PDFNetworkStreamRangeRequestReader {
this.>
}

_onHeadersReceived() {
this.#responseOrigin.resolve(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again this stage may never be reached. Shouldn't we resolve (or reject) earlier to avoid requests getting stuck?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be similar to the situation outlined for src/display/fetch_stream.js above.

@Snuffleupagus Snuffleupagus requested review from Rob--W and removed request for calixteman November 17, 2024 12:03
@mozilla mozilla deleted a comment from moz-tools-bot Nov 17, 2024
@mozilla mozilla deleted a comment from moz-tools-bot Nov 17, 2024
@mozilla mozilla deleted a comment from moz-tools-bot Nov 17, 2024
@mozilla mozilla deleted a comment from moz-tools-bot Nov 17, 2024
@mozilla mozilla deleted a comment from moz-tools-bot Nov 17, 2024
@mozilla mozilla deleted a comment from moz-tools-bot Nov 17, 2024
@mozilla mozilla deleted a comment from moz-tools-bot Nov 17, 2024
@mozilla mozilla deleted a comment from moz-tools-bot Nov 17, 2024
@mozilla mozilla deleted a comment from moz-tools-bot Nov 17, 2024
@mozilla mozilla deleted a comment from moz-tools-bot Nov 17, 2024
@mozilla mozilla deleted a comment from moz-tools-bot Nov 17, 2024
@mozilla mozilla deleted a comment from moz-tools-bot Nov 17, 2024
@mozilla mozilla deleted a comment from moz-tools-bot Nov 17, 2024
@mozilla mozilla deleted a comment from moz-tools-bot Nov 17, 2024
@mozilla mozilla deleted a comment from moz-tools-bot Nov 17, 2024
@mozilla mozilla deleted a comment from moz-tools-bot Nov 17, 2024
@mozilla mozilla deleted a comment from moz-tools-bot Nov 17, 2024
@mozilla mozilla deleted a comment from moz-tools-bot Nov 17, 2024
…est (issue 12744)

The following cases are excluded in the patch:
 - The Firefox PDF Viewer, since it has been fixed on the platform side already; please see https://bugzilla.mozilla.org/show_bug.cgi?id=1683940

 - The `PDFNodeStream`-implementation, used in Node.js environments, since after recent changes that code only supports `file://`-URLs.

*Note:* The relevant unit-tests are updated to await the `headersReady` Promise before dispatching range requests, since that's consistent with the actual usage in the `src/`-folder.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent cross-origin information leakage via range requests
2 participants