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

Cross origin issue when 'use-credentials' is used. Solution suggestion inside. #519

Closed
liesahead opened this issue May 10, 2019 · 0 comments

Comments

@liesahead
Copy link

liesahead commented May 10, 2019

Describe the bug
Image cannot be loaded if caching is turned on when image crossorigin option is set to 'use-credentials'

To Reproduce
Should be clear from description, but well. Steps to reproduce the behavior:

  1. Set checkCrossOrigin to true
  2. Set image 'crossorigin' attribute to 'use-credentials', like <img crossorigin='use-credentials' src=...>
  3. Set server configuration to allow cors requests only from specific domains.
  4. See error (:

Expected behavior
No cross-origin error should occur

More detailed description
So, I've been fighting this bug whole day, was trying to understand if problem is in server configuration or somewhere else. But this error never occurred before, only with this library, so I went through the source code.

  1. If browser caching is disabled (through developer options, for example), then everything works fine.

  2. If image is cached and no timestamp is added to url (take a look at red area in screenshot), then cropper will fail on line 219 (blue area in screenshot) due to cross origin error (if settings are set like described in 'to reproduce' section).

SUGGESTED SOLUTION
There is my used solution, we just add the timestamp to crossOriginUrl every time:

crossOriginUrl = addTimestamp(url);

if(!crossOrigin) {
    crossOrigin = 'anonymous';
}

Screenshots
Here's a screenshot of code block in cropper.js file

image

@liesahead liesahead changed the title Cross origin issue when 'use-credentials' is used. Cross origin issue when 'use-credentials' is used. Solution suggestion inside. May 10, 2019
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

No branches or pull requests

1 participant