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

Add caching support and remove access control. Fixes #65 #64 #49 #17 #68

Closed
wants to merge 14 commits into from

Conversation

davidbarratt
Copy link
Contributor

@davidbarratt davidbarratt commented Apr 4, 2020

I have fixed everything. :)

Despite the number of changes, I don't think this is actually a breaking change (it's either a minor or a patch):

  • The way this library is used has not changed
  • The cross-origin interaction browsers have has not changed
  • Caching is now fixed

Fixes #65 #64 #49 #17

Copy link
Collaborator

@barryvdh barryvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are other libraries handling this? Is this the only one which actively blocks the requests?

src/Asm89/Stack/CorsService.php Outdated Show resolved Hide resolved
src/Asm89/Stack/CorsService.php Outdated Show resolved Hide resolved
@davidbarratt
Copy link
Contributor Author

How are other libraries handling this? Is this the only one which actively blocks the requests?

I have no idea, but a simple request shouldn't fail, otherwise you break cachability.

The simple request will not be read without the proper CORS headers.

If it's a non-simple request, the browser wont even send the request if it fails the preflight.

@davidbarratt
Copy link
Contributor Author

davidbarratt commented Apr 4, 2020

I suppose it's possible that someone was using this library to block simple requests, but that's a misuse of CORS (and a misuse of this library, imho). The purpose is to be more permissive, not less

@davidbarratt
Copy link
Contributor Author

All of the requests that are simple can be preformed with HTML (anchors, forms, etc.) which you cannot prevent because they will be same-origin when executed. A better way to prevent those would be to use the Referer header. I think using this library to attempt to block simple requests, may give the user a false sense of security.

@barryvdh
Copy link
Collaborator

barryvdh commented Apr 4, 2020

Yeah I think I agree, although it could warrant a new semver release.

@davidbarratt
Copy link
Contributor Author

Yeah I think I agree, although it could warrant a new semver release.

As long as it gets into Drupal before v9, it doesn't matter to me, but maybe @wimleers can help with that. :)

@davidbarratt
Copy link
Contributor Author

or maybe it can go in a minor release of Drupal... I'm not sure. :/

@barryvdh
Copy link
Collaborator

barryvdh commented Apr 5, 2020

First of all, thanks for the effort. But not sure if having a big PR like this is the best way. CORS is tricky and I want to make sure we don't break anything. I'm gonna look at this, and possibly cherry-pick a few commits, if that's okay with you.

@davidbarratt
Copy link
Contributor Author

No problem. :)

My problem was that I couldn't remove the the need to Vary the origin (#64) without also removing the access control (#65). Since the access control requires that the response be varried by the origin all the time (#49). Doing this removed the need for more helpful error messages (#17).

I'm not sure how to untangle that, so if have some ideas, go for it. :)

@davidbarratt
Copy link
Contributor Author

I suppose this could be done in reverse... so in this order:

  1. Always set Vary: Origin #49 Always set the Vary (do not add any new config, since the way it is now, this is always needed)
  2. Access control is unnecessary #65 Remove the access control, since this isn't necessary in the first place. Also resolves More helpful error response #17
  3. Only Vary the request when necessary #64 Add better cacheability (i.e. partially reverse Always set Vary: Origin #49)

Does that sound reasonable?

@barryvdh
Copy link
Collaborator

barryvdh commented Apr 5, 2020

See #70 also, which includes #69

@barryvdh
Copy link
Collaborator

barryvdh commented Apr 6, 2020

Yeah I was thinking about just modifying the existing response, but not sure how normal apps handle OPTIONS requests.

@davidbarratt
Copy link
Contributor Author

Yeah I was thinking about just modifying the existing response, but not sure how normal apps handle OPTIONS requests.

I don't think they normally do, so I think catching would be correct, but should probably test in some apps.

@davidbarratt
Copy link
Contributor Author

Yeah I was thinking about just modifying the existing response, but not sure how normal apps handle OPTIONS requests.

We could kick the can on the preflight by first checking if it's an OPTIONS request and then adding Vary: Access-Control-Request-Method to all of those requests. Then we can check to see if it has the header and if it does, takeover the request...

Though I think it would be better to add the heaqers to all OPTIONS requests (if possible).

@barryvdh
Copy link
Collaborator

So if this all covered with the latest version now?

@davidbarratt
Copy link
Contributor Author

So if this all covered with the latest version now?

Looks like it to me! :) Thank you so much!

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

Successfully merging this pull request may close these issues.

Access control is unnecessary
2 participants