Mobile app version of vmapp.org
Login or Join
Lee4591628

: 403 Error Fetching Image with JS I've read all the 403-related questions here and elsewhere and I can't find an answer to this question: When I try to get a particular image on a remote domain

@Lee4591628

Posted in: #403Forbidden #Javascript

I've read all the 403-related questions here and elsewhere and I can't find an answer to this question:
When I try to get a particular image on a remote domain via JavaScript I get a 403 error.
But if I type the same exact image URL in the same browser, the image is downloaded and displayed without errors. Same (success) if I try getting it via PHP.

Here is a fiddle with a live example of the 403 (visible in the debug console): jsfiddle.net/8VfrQ/ Then, just copy and paste the img.src link in the browser and you'll see the star displayed.

Thanks for any hints.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Lee4591628

2 Comments

Sorted by latest first Latest Oldest Best

 

@Nimeshi995

The site appears to be checking the referrer field.

curl -I mysticstars.net/gifs/star_bul.gif -e "*"
HTTP/1.1 403 Forbidden
Date: Wed, 25 Jun 2014 15:45:40 GMT
Server: Apache/2.2.27
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Length: 1007
Content-Type: text/html

curl -I mysticstars.net/gifs/star_bul.gif -e "http://mysticstars.net"
HTTP/1.1 200 OK
Date: Wed, 25 Jun 2014 15:46:37 GMT
Server: Apache/2.2.27
Last-Modified: Wed, 26 Sep 2007 20:56:22 GMT
ETag: "1a08a9c-e3-43b1016084980"
Accept-Ranges: bytes
Content-Length: 227
Content-Type: image/gif


As @Wayne Whitty points out, this is likely due to rewrite rules preventing hotlinking.

To my knowledge, javascript cannot pass the referrer field, so you may have to amend the hotlink rules.

10% popularity Vote Up Vote Down


 

@Gloria169

When I try to get a particular image on a remote domain via JavaScript
I get a 403 error.


Likely answer: The site in question has protection against "leeching" / hotlinking. i.e. It checks to see what host is requesting the file before serving it. If the request comes from an unrecognised website, they throw a 403 Forbidden error.

If you take a look at this updated fiddle you will see that it's not only JavaScript that is affected.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme