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

Fallback to <img> loading on XHR failure #65

Closed
VeryStrongFingers opened this issue Jul 25, 2020 · 3 comments
Closed

Fallback to <img> loading on XHR failure #65

VeryStrongFingers opened this issue Jul 25, 2020 · 3 comments

Comments

@VeryStrongFingers
Copy link

VeryStrongFingers commented Jul 25, 2020

Would it be worthwhile to attempt the loading of the fallback pixel image, in the case of XHR failure?

xhr.send(
JSON.stringify({
idempotency: Shynet.idempotency,
referrer: document.referrer,
location: window.location.href,
loadTime:
window.performance.timing.domContentLoadedEventEnd -
window.performance.timing.navigationStart,
})
);
} catch (e) { }
},

The pixel CORS header will always allow any host to connect

resp = HttpResponse(data, content_type="image/gif")
resp["Cache-Control"] = "no-cache"
resp["Access-Control-Allow-Origin"] = "*"
return resp

so in the event of a CORS (or other) failure on XHR - falling back to loading the <img src="..../pixel.gif"> would theoretically work.

I'm happy to do a PR for it, if deemed appropriate

@milesmcc
Copy link
Owner

Hmm. Thanks for pointing this out. You may have honestly found a bug — the CORS headers of the image shouldn’t be * always. Instead, they should match that of the script.

Hmm.

@VeryStrongFingers
Copy link
Author

@milesmcc CORS doesn't apply to <img> tags according to https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#What_requests_use_CORS
Might not even need that header at all

@milesmcc
Copy link
Owner

Thanks for pointing out this issue. I realize the fix may have been the exact opposite of what you expected---origin checking is now enforced for images too---but that's ultimately a security consideration. I thought that CORS was enforced for images, so when you pointed out that it wasn't, I realized that meant there was a way to get around origin enforcement!

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

2 participants