http://ha.ckers.org/blog/20070604/passing-...h-getimagesize/
Cytat(Josh)
Converting the file to a jpeg (or png, etc.), resizing it, essentially making a minor change and rewriting the image data should effectively ’safe’ your image file.
“PHP start tag” might be a valid sequence in an image, so you can’t filter by it.
“PHP start tag” might be a valid sequence in an image, so you can’t filter by it.
Cytat
To make Josh’s comment a bit more complete:
- validate user supplied filename (replace all chars except [a-z0-9] with underscore)
- validate file suffix (allow only image suffixes - jpg, jpeg, gif, png)
- open and re-save image (to avoid IE “js inside image” bug)
I think this procedure fixes all of the bugs / vulnerabilities I have found. YMMV.
YMMV - your mileage may vary //rozwinięcie skrótu
- validate user supplied filename (replace all chars except [a-z0-9] with underscore)
- validate file suffix (allow only image suffixes - jpg, jpeg, gif, png)
- open and re-save image (to avoid IE “js inside image” bug)
I think this procedure fixes all of the bugs / vulnerabilities I have found. YMMV.
YMMV - your mileage may vary //rozwinięcie skrótu
Mam taką sytuacje że użytkownicy wgrywają swoje awatary 100x100 wyłącznie image/png.
Przesyłam to na serwer AJAX jako data:image/png;base64.
Oczywiście po stronie serwera sprawdzam obrazek i mime:
if( $image['mime'] == 'image/png' ) //obrazek jest awatarem więc jest zapisywany w publicznym folderze
Z linku który wkleiłem na początku jasno wynika że ten kod nie zabezpiecza mnie w 100% przed injection. Rozwiązaniem jest przeskalowanie obrazka. Przeskalowanie jest tutaj kluczową operacją, bo domyślam się, że chodzi o to aby zmodyfikować każdy bit w którym potencjalnie może znajdować się kod.
I tutaj jest problem bo dostaje gotowe obrazki 100x100. Skalowanie ich do 101x101 i powrotnie do 100x100 przyniesie oczekiwany rezultat ?