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

Question about CORS and Redirects for Widevine License Requests #1256

Closed
vzTrevorHunsaker opened this issue Jan 26, 2018 · 7 comments
Closed
Assignees
Labels
status: archived Archived and locked; will not be updated type: bug Something isn't working correctly
Milestone

Comments

@vzTrevorHunsaker
Copy link

vzTrevorHunsaker commented Jan 26, 2018

Due to a quirk of our backend, we sometimes have to re-direct Widevine license requests to a different server. I have attempted to do this by returning a 307 response with the proper Location header. Looks like CORS issues may be preventing this solution from working, (we use values from the cookie to do some processing before sending on the request to Widevine's servers). It looks like I may have to come to terms with the fact that a redirect-based solution will not work in this case, but before I do that I'm seeing something odd in the network pane of Chrome's dev tools that leads me to believe that we're successfully delivering a license to the browser, which makes me wonder why playback doesn't happen.

I have exported the networking tab's output as an .har file

You can see that the original requests to my Widevine endpoint go to content.uplynk.localhost/wv, and have been 307 redirected to content-dev.uplynk.localhost/wv. You can also see subsequent requests to the redirected domain successfully return a license with a 200 response.

However, there are a couple of requests that the browser apparently blocks because of CORS. A
screenshot from the network panel

In there, you can again see the initial requests, the redirected requests, as well as some requests that failed. The number of failed requests correspond with the number of CORS-related errors I find in my JS console:

Failed to load http://content-dev.uplynk.localhost:8000/wv: The 'Access-Control-Allow-Origin' header has a value 'http://localhost:8001' that is not equal to the supplied origin. Origin 'null' is therefore not allowed access. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Given that it appears as though we're successfully delivering a license via redirects, I'm hoping there's just some CORS-related magic I can work to convince the browser to actually accept and use them. Or am I just up in the night?

@chrisfillmore
Copy link
Contributor

You can circumvent CORS security a variety of ways for the purposes of testing:

  • Disable same-origin policy (for Chrome: https://stackoverflow.com/a/6083677)
  • Access-Control-Allow-Origin: * extension for Chrome
  • Rewrite response headers via Charles Proxy, Fiddler, etc

This would at least tell you if you had a CORS issue.

@TheModMaker
Copy link
Contributor

Since the license server is on a different origin (server) than the Shaka demo, you'll need to add CORS headers so the browser will allow the request. You can read more about CORS here.

Also note that the demo now uses a service worker for requests, which have different requirements for CORS settings. I have seen that even with --disable-web-security the request may fail because the service worker still requires CORS. In Chrome, you can go to the DevTools and in the "Application" tab select the "Service Worker" on the left and check the "Bypass for network" checkbox to see if this is CORS related.

Lastly, some browsers don't support cross-origin redirects. See #666 for more details about this.

@TheModMaker TheModMaker added type: question A question from the community status: waiting on response Waiting on a response from the reporter(s) of the issue labels Jan 29, 2018
@vzTrevorHunsaker
Copy link
Author

vzTrevorHunsaker commented Jan 30, 2018

We do insert CORS headers in our responses and they worked swimmingly up until we found a case where we needed to send a re-direct. It appears as though it's CORS + redirects specifically that's catching us out here.

I will try both of these suggestions to attempt to validate. Thanks!

@vzTrevorHunsaker
Copy link
Author

vzTrevorHunsaker commented Jan 31, 2018

So, I am able to successfully play this stream when I --disable-web-security and check the service workers' "Bypass for network" box. Which leads me to believe this is a CORS issue, but I also am under the impression that it's a CORS issue I shouldn't be seeing, given the headers that I'm returning in my responses.

I mean, the re-directed requests actually succeed, and deliver Widevine licenses. My question is, given that's the case, why is the browser refusing to use them? Browser bug? I'm misunderstanding something?

@joeyparrish
Copy link
Member

I think it may be a browser bug. I am surprised that the browser treats CORS differently in a service worker. My best suggestion is to file a bug on http://crbug.com/ and link to it here so we can follow along.

@vzTrevorHunsaker
Copy link
Author

Ok, I've filed a report against Chromium: https://bugs.chromium.org/p/chromium/issues/detail?id=807706

@TheModMaker TheModMaker added type: external An issue with an external dependency; not our issue; sometimes kept open for tracking and removed type: question A question from the community status: waiting on response Waiting on a response from the reporter(s) of the issue labels Feb 1, 2018
@joeyparrish joeyparrish added type: bug Something isn't working correctly and removed type: external An issue with an external dependency; not our issue; sometimes kept open for tracking labels Apr 29, 2019
@joeyparrish joeyparrish self-assigned this Apr 29, 2019
@joeyparrish
Copy link
Member

I believe we can fix our demo's service worker to avoid this browser behavior. I hope to have an update out soon.

@shaka-bot shaka-bot added this to the v2.5 milestone Apr 29, 2019
@shaka-project shaka-project locked and limited conversation to collaborators Jun 29, 2019
@shaka-bot shaka-bot added the status: archived Archived and locked; will not be updated label Apr 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: archived Archived and locked; will not be updated type: bug Something isn't working correctly
Projects
None yet
Development

No branches or pull requests

5 participants