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

Protected music & video files get 401 on CSS even if authenticated #373

Closed
timbl opened this issue Mar 15, 2023 · 9 comments · Fixed by #374
Closed

Protected music & video files get 401 on CSS even if authenticated #373

timbl opened this issue Mar 15, 2023 · 9 comments · Fixed by #374
Assignees
Labels

Comments

@timbl
Copy link
Contributor

timbl commented Mar 15, 2023

When you try to play misc files which need tyou to be logged in, CSS returns 401 error and the browwser does nothing about it. Just like the problem with images in IMG tags in the html.

eg fails:

https://timbl.com/timbl/Public/Test/Protected/Les_Hayden_-_01_-_Gift_Horse.mp3_.mp3

compare with public unprotected file does nt have the same problem

https://timbl.com/timbl/Public/Test/Music/Les%20Hayden/Proverbs/Les_Hayden_-_01_-_Gift_Horse.mp3_.mp3

@bourgeoa bourgeoa self-assigned this Mar 15, 2023
@bourgeoa bourgeoa added the bug label Mar 15, 2023
@josephguillaume
Copy link
Contributor

Presumably this is the line that needs to change:

audio.setAttribute('src', song.uri)

@bourgeoa
Copy link
Contributor

bourgeoa commented Mar 18, 2023

@josephguillaume yes
We used blob for images. But we may have a size issue with audio and surely video
Are you interested to make a PR.
https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_streams

I have created the https://github.com/SolidOS/solid-panes/tree/fetchMediaStreams branch

@bourgeoa bourgeoa transferred this issue from SolidOS/solidos Mar 18, 2023
@josephguillaume
Copy link
Contributor

I've never worked with ReadableStream before, so I might start by reading up and then see. Thanks!

@bourgeoa
Copy link
Contributor

bourgeoa commented Mar 18, 2023

@josephguillaume
Copy link
Contributor

Thanks. Everything I found so far was similarly involved.
I even found some that loaded their own codec libraries, e.g. https://github.com/AnthumChris/fetch-stream-audio

This one was the clearest but still ends up requiring specifying a codec, and the example uses split audio and video streams (hopefully not necessary!).

I'm not sure I'll get to it today, so if the solution becomes clear to you, please do go ahead...

The use of streams of variable quality was interesting too. I've already been thinking with slideshow that my photos are too large and take too long to load. Depending on bandwidth, the same concept applies to audio and video streaming. It'd be interesting to see what we can do about this, potentially even without server support. Definitely a new longer term issue though...

@josephguillaume
Copy link
Contributor

Given how simple the audio tag is and how complex the Mediasource is, I wonder whether we should be using this bug to explore the comment:

https://forum.solidproject.org/t/is-it-secure-for-pods-to-serve-html-files/6379/9
"For handling files, I do think that Solid will need a way to request from a Server a time boxed & authentication bound URL for a resource, such that that URL can be used directly via browser native elements (img, audio, video, etc)"

A currently possible client-side solution would involve temporarily granting public access to the resource.

If we had server-side support to specify redirects (solid/specification#136) then we could issue a temporary unguessable url to provide a level of indirection/discourage linking directly to the resource.

If we had server-side support to specify symlink-like behaviours within a pod, then the temporary URL could directly return the resource.

To avoid completely public access, the server could support cookie or other built-in auth beyond the spec??

I.e. If solving this bug is urgent then maybe we just use the ACL solution. If it's not urgent, maybe we let the spec catch up?

@bourgeoa bourgeoa linked a pull request Mar 19, 2023 that will close this issue
@bourgeoa bourgeoa changed the title Protected music files get 401 even if authenticated Protected music & video files get 401 on CSS even if authenticated Mar 20, 2023
@bourgeoa
Copy link
Contributor

Resolved with the authenticated fetch blob solution used for tag.
This is not a streaming solution. The file is fully loaded before reading.

@bourgeoa
Copy link
Contributor

For the records
I tried with new mediaSource but this did not add any reading while streaming and added mimeType complexity

      // https://stackoverflow.com/questions/39275481/chrome-to-play-a-video-that-is-being-downloaded-via-fetch-xhr/68778572#68778572
      const mediaSource = new MediaSource();
      mediaSource.addEventListener('sourceopen', async () => {
        const sourceBuffer = mediaSource.addSourceBuffer('video/mp4');      
        const response = await kb.fetcher._fetch(subject.uri)
        const body = response.body
        const reader = body.getReader()      
        let streamNotDone = true;      
        while (streamNotDone) {      
          const {value, done} = await reader.read();          
          if (done) {streamNotDone = false; break;}
          await new Promise((resolve, reject) => {
            sourceBuffer.appendBuffer(value)
            sourceBuffer.onupdateend = (() => {
              resolve(true);
            })
          }) 
        }
      })
    video.setAttribute('src', URL.createObjectURL(mediaSource))

@josephguillaume
Copy link
Contributor

Another possible solution came up that I wasn't aware of: apparently a service worker could be used to provide authenticated fetch behaviour, and it reportedly at least works on img tags.

solid/solid#143 (comment)

A fair bit of work would be needed still for the databrowser to install the service worker, and I believe we'd also need to confirm a secure way to pass tokens or an authenticated fetch function from the main thread to the service worker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging a pull request may close this issue.

3 participants