react-player icon indicating copy to clipboard operation
react-player copied to clipboard

Query params dropped after initial HLS manifest request

Open paulcullin opened this issue 8 years ago • 3 comments

I'm encountering an issue attempting to play back secured HLS video (via CloudFront) using signed cookies passed through the video URL (instead of Cookie headers).

The initial (parent) m3u8 container is successfully retrieved (both CORS pre-flight OPTIONS request and GET request for the object return 200), but the subsequent GET requests to child m3u8 containers are failing with 403 because the URL parameters are somehow dropped from all subsequent requests, causing CloudFront to deny access.

Here is a snippet of my implementation, which illustrates how I have the player configured and the URL params being included in the video URL. I can provide a more detailed working example if necessary.

I have also tried this in the online test player, which results in the same behavior. The HLS.js test player doesn't appear to support CORS (not configured to pass the necessary request headers), so I wasn't able to get as far there.

<div className="video">
        {this.readyToPlay(state) && (
          <ReactPlayer
            ref={this.ref}
            controls={true}
            className="react-player"
            width="100%"
            height="auto"
            url="https://foo.cloudfront.net/bar.m3u8?Key-Pair-Id=<key-pair-id>&Policy=<policy>&Signature=<signature>"
            config={{
              file: {
                hlsOptions: {
                  xhrSetup: function(xhr, url) {
                    xhr.withCredentials = true; // send cookies
                    xhr.setRequestHeader(
                      "Access-Control-Allow-Headers",
                      "Content-Type, Accept, X-Requested-With"
                    );
                    xhr.setRequestHeader(
                      "Access-Control-Allow-Origin",
                      "http://moragram.com:3000"
                    );
                    xhr.setRequestHeader(
                      "Access-Control-Allow-Credentials",
                      "true"
                    );
                  }
                }
              }
            }}
            playing={this.state.showVideo}
            playbackRate={1.0}
            onError={e => console.log("onError", e)}
          />
        )}
        {!this.readyToPlay(state) && <video width="100%" />}
        {placeholder}
      </div>

paulcullin avatar Jul 12 '18 23:07 paulcullin

You basically want to set query params on the xhr instance during xhrSetup, but I'm not sure that's possible.

I'm assuming logging out url during xhrSetup returns the URL without query params?

I'm not sure I can be much help here. It might be worth opening a issue with hls.js, as I'm not sure this is specific to ReactPlayer.

cookpete avatar Jul 23 '18 07:07 cookpete

Closing this off as it seems to be an issue with hls.js rather than this library.

cookpete avatar Nov 17 '18 18:11 cookpete

Old thread, but it pointed me in a good direction. I ran into this issue today with CloudFront signed URLs and react-player. Since each URL must have a token appended, I've seen elsewhere in some players the ability to alter the URL before each request: i.e. hls.xhr.beforeRequest.

In lieu of that, this seems to work: Calling xhr.open() again within xhrSetup with an altered URL.

      file: {
        hlsOptions: {
          xhrSetup: function xhrSetup(xhr, url) {
            xhr.open('GET', url + token);
          }
        }
      }

cfaherty avatar Oct 27 '20 01:10 cfaherty