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

HLS CORS not working #415

Closed
2 of 7 tasks
dorinclisu opened this issue Jun 4, 2021 · 10 comments
Closed
2 of 7 tasks

HLS CORS not working #415

dorinclisu opened this issue Jun 4, 2021 · 10 comments
Labels
bug Something isn't working

Comments

@dorinclisu
Copy link
Contributor

dorinclisu commented Jun 4, 2021

Which version are you using?

v0.16.2

Which operating system are you using?

OS

  • Linux
  • Windows
  • macOS

Architecture

  • amd64
  • arm64
  • arm7
  • arm6

Describe the issue

JavaScript console:

Access to XMLHttpRequest at 'http://localhost:8888/test' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Server logs:

2021/06/04 16:20:50 I [0/0] [path test] [rtsp source] ready
2021/06/04 16:22:09 I [0/0] [HLS] [conn 172.18.0.1:64260] GET /test
2021/06/04 16:22:10 I [0/0] [HLS] [conn 172.18.0.1:64260] GET /test

Describe how to replicate the issue

Copy paste the source URL in this HLS player: https://hls-js.netlify.app/demo/

@dorinclisu
Copy link
Contributor Author

Perhaps it could be useful to add "allowedOrigins" field in config.yml, with "*" being the default.

@Prakash2101
Copy link

I'm also facing the same issue.

@dorinclisu
Copy link
Contributor Author

dorinclisu commented Jun 8, 2021

Upon more investigation, I think the problem is because the initial request to /test is redirected to /test/ with a 301 response instead of the expected 200 for CORS.
If we try to access http://localhost:8888/test/ directly there is no more CORS issue, but this is not an acceptable workaround because now the HTTP Basic auth is failing since /test/ is considered a different path than /test so it falls back to default path (all) which can have other credentials.

@dorinclisu
Copy link
Contributor Author

dorinclisu commented Jun 8, 2021

Actually my understanding of HLS was incomplete.
The correct src url would be http://localhost:8888/test/stream.m3u8. And this plays the video if there is no read authentication.

But with auth, it doesn't work anymore.
config.yml:

paths:
  test:
    source: rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov
    readUser: user
    readPass: pass
    sourceOnDemand: false
    sourceProtocol: tcp

Player logs:

Status:
0.071 | Loading http://user:pass@localhost:8888/test/stream.m3u8
0.102 | Loading manifest and attaching video element...
0.193 | Media element attached

Error:
Cannot load http://user:pass@localhost:8888/test/stream.m3u8 HTTP response code:401 Unauthorized
0.178 | A network error occurred: manifestLoadError

@Prakash2101
Copy link

Prakash2101 commented Jun 9, 2021

When I play the HLS url https://164.22.4.77:8888/demo/stream.m3u8 on vlc player it is playable but when I try to access on browser/any online player it is giving me an CORS issue. Is there any workaround to run the HLS on any of the online player?

@aler9 aler9 added the bug Something isn't working label Jun 23, 2021
aler9 added a commit that referenced this issue Jun 23, 2021
@aler9
Copy link
Member

aler9 commented Jun 23, 2021

  • The Access-Control-Allow-Origin is now inserted into every HTTP response (even redirects)
  • a new parameter hlsAllowOrigin has been added to the configuration file

@dorinclisu
Copy link
Contributor Author

dorinclisu commented Jun 24, 2021

Thank you, can you provide a nightly build to test or how to use the Makefile to build on my own?

Edit: I managed to build using make release but is there any way to limit the build to only one platform? Building for 6 platforms including some cross builds is rather slow.

@dorinclisu
Copy link
Contributor Author

dorinclisu commented Jun 24, 2021

rtsp-simple-server_v0.16.3-2-gc900bc4_linux_amd64.tar.gz
rtsp-simple-server_v0.16.3-2-gc900bc4_linux_arm64v8.tar.gz
rtsp-simple-server_v0.16.3-2-gc900bc4_darwin_amd64.tar.gz
rtsp-simple-server_v0.16.3-2-gc900bc4_windows_amd64.zip

I tested and it still doesn't work properly with readUser and readPass.

2021/06/24 12:20:55 I [0/0] rtsp-simple-server v0.16.3-2-gc900bc4
2021/06/24 12:20:55 I [0/0] [RTSP] TCP listener opened on :8554
2021/06/24 12:20:55 I [0/0] [HLS] listener opened on :8888
2021/06/24 12:20:55 I [0/0] [path test] [rtsp source] started
2021/06/24 12:21:02 I [0/0] [path test] [rtsp source] ready
2021/06/24 12:21:26 I [0/0] [HLS] [conn 172.18.0.1:64704] OPTIONS /test/stream.m3u8
2021/06/24 12:21:26 I [0/0] [HLS] [converter test] opened
2021/06/24 12:21:26 I [0/1] [HLS] [converter test] is converting into HLS
2021/06/24 12:21:27 I [0/1] [HLS] [conn 172.18.0.1:64704] OPTIONS /test/stream.m3u8
2021/06/24 12:22:27 I [0/0] [HLS] [converter test] closed

Chrome devtools on custom HLS player page:

Request Headers

Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: ro-RO,ro;q=0.9,en-US;q=0.8,en;q=0.7,de;q=0.6
Access-Control-Request-Headers: authorization
Access-Control-Request-Method: GET
Cache-Control: no-cache
Connection: keep-alive
Host: localhost:8888
Origin: http://localhost:3000
Pragma: no-cache
Referer: http://localhost:3000/
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36

Response Headers

Access-Control-Allow-Origin: *
Content-Length: 0
Date: Thu, 24 Jun 2021 12:21:26 GMT
Www-Authenticate: Basic realm="rtsp-simple-server"

General

Request URL: http://localhost:8888/test/stream.m3u8
Request Method: OPTIONS
Status Code: 401 Unauthorized
Remote Address: [::1]:8888
Referrer Policy: strict-origin-when-cross-origin

I also tried with hlsAllowOrigin: http://localhost:3000 and also tried w.Header().Add("Access-Control-Allow-Credentials", "true") in server.go but the behavior is still the same.

@aler9
Copy link
Member

aler9 commented Jul 4, 2021

added in v0.16.4

@aler9 aler9 closed this as completed Jul 4, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Jan 1, 2023

This issue is being locked automatically because it has been closed for more than 6 months.
Please open a new issue in case you encounter a similar problem.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants