beakerbrowser / hashbase

A Dat-hosting service for multiple users
https://hashbase.io
MIT License
239 stars 38 forks source link

Allows CORS on PSA Document? #118

Open DougAnderson444 opened 5 years ago

DougAnderson444 commented 5 years ago

@pfrazee I am trying to use beakerbrowser/dat-pinning-service-client to access hashbase.io/.well-known/psa from a non-beaker origin domain, but I am getting the error:

blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

I see #43 allowed CORS, but what about the PSA Document?

Has this issue already been addressed elsewhere or do we need a fix?

DougAnderson444 commented 5 years ago

Opened PR #119

pfrazee commented 5 years ago

Hmm... is there any possible reason we wouldn't want to allow this?

DougAnderson444 commented 5 years ago

Paul, Is that a trick question? ...I guess if you want to restrict programmatic pinning to hashbase to only beakerbrowser?

pfrazee commented 5 years ago

Eaaaasy man, I'm not trying to be a jerk. I couldn't remember off the top of my head whether CORS would send credentials from another origin or if there was any other security concern. You just dumped a PR on me and I think it's fair for me to ask.

AFAICT the answer is no. Existing credentials (cookies) are never sent if we set allow to *. That said, I'm not sure if you can get your own origin's cookies sent, which will be needed if you want to go through the pinning API's login session. Can you confirm that for me before we merge this?

DougAnderson444 commented 5 years ago

Ah, ok no worries I thought you might have wanted me to think deeper before asking for what I thought was needed. I'll look into the cookies and try to test it out first, it's just not my area of expertise.

If we need to pass cookies, from what I understand we may need to add:

res.header("Access-Control-Allow-Credentials", "true") // only if you want use client cookies

pfrazee commented 5 years ago

🍻 Appreciate it! If we have to set allow-credentials, we should make sure that doesn't allow credentials to get attached across origins.

pfrazee commented 5 years ago

If it turns out we can't get cookies to be sent without breaking session-isolation of SOP, we should look into sending the Authorization header instead of using cookies.

DougAnderson444 commented 5 years ago

See, I'm glad I asked then. I only got so far as trying to get the PSA Document, for which no credentials are required. I'm sure I would have hit this wall once the PSA doc was fetched and tried to log in. I'll continue to pick away at it.

pfrazee commented 5 years ago

For sure. I'm sorry my original response was short; tail end of the day.

RangerMauve commented 5 years ago

Anything I can do to help push this forward? 😁

DougAnderson444 commented 5 years ago

Oh yeah @RangerMauve ! Do you have a pinning server up?

I've been trying to bring one up to test this, but I've been running into challenges so far.

RangerMauve commented 5 years ago

A pinning server with the proper CORS headers? I can set one up for you tomorrow. 😁

I'll just expose my dat-store instance on Digital Ocean and see if that works.

DougAnderson444 commented 5 years ago

Oh, I thought if we were going to edit the hashbase code, we would need an instance of hashbase up and running?

Although, in looking at dat-store, that seems pretty straightforward. Is it really as easy as dat-share url?

RangerMauve commented 5 years ago

Oh, k. I'll see what I can do there. Hashbase requires a bunch more config, so that might take more time, but I think I can figure it out. 😁

dat-store should behave the same as an unauthenticated hashbase.

RangerMauve commented 5 years ago

Bleh. While getting the CORS stuff into dat store I got some sort of error with folder sync. 😭 Hopefully I'll have something this evening.

RangerMauve commented 5 years ago

of course it's a Windows problem. 😭

RangerMauve commented 5 years ago

K, lost most of my day to fixing some weird bugs in dat-store. I'll need to figure out setting up a CORS enabled store tomorrow instead. 😅