-
-
Notifications
You must be signed in to change notification settings - Fork 541
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
Images fail to load if the base64-encoded path contains multiple slashes #11176
Comments
I had ran into this issue recently and forgot to report it, so, thank you. My gut reaction was to urlencode the base64 chunk, but looking at the Laravel thread you referenced, it seems like that probably won't work either. There are "base64url" variants, which avoid using slashes. This example is from php.net. Maybe we can use this or something similar. function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
function base64url_decode($data) {
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
} |
Sure, no problem :) Yea, I tried to use the encoded version I also thought about this and it seems like a doable workaround to me, although it might break some images at first, as long as the static cache is not cleared. Would you implement these functions as a global helper (in It also seems to me, that this code is fine as well (without the padding): function base64url_encode($data)
{
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
function base64url_decode($data)
{
return base64_decode(strtr($data, '-_', '+/'));
} |
Could probably do |
I had similar issues where the |
Bug description
I encountered a special case, where images won't load, if the base64-encoded path of the generated Glide image URL contains multiple strings, like in
/img/asset/YXNzZXRzLzgwMF/DvGJlci11bnMvbWEtZm90by12b24tb2Jlbl8yMDE3LmpwZw==/ma-foto-von-oben_2017.jpg
.This URL is technically correct, but Laravel somehow doesn't use the correct portion of the URL to decode the base64 part. Laravel ends up only decoding
YXNzZXRzLzgwMF
, but not the wholeYXNzZXRzLzgwMF/DvGJlci11bnMvbWEtZm90by12b24tb2Jlbl8yMDE3LmpwZw==
string. The whole string would result in the decoded string800_über-uns/ma-foto-von-oben_2017.jpg
.I know, that Statamic converts german Umlaute to usual characters, but this came from an older project. It is only an example to demonstrate the issue with the special base64 string. The problematic base64 string can be generated from other values as well.
I made a fix in the
GlideController
which solves this issue (although it doesn't seem like the best solution to me):There is also a Laravel issue (laravel/framework#22125) which makes me think, that this is not possible to get fixed from Laravels side.
How to reproduce
image
public/assets
named800_über-uns
(need to use CLI because in newer versions Statamic would convert anü
tou
ma-foto-von-oben_2017.jpg
(the naming here is only important to make sure, that the generated base64 string contains multiple/
)resources/views/home.antlers.html
and insert this line:<img src="{{ glide:image }}" /
404
error.Another way is to clone https://github.com/morhi/statamic-glide-base64-path-bug
Logs
No response
Environment
Installation
Other (please explain)
Additional details
No response
The text was updated successfully, but these errors were encountered: