Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion

How to prevent redirect if image is embedded?
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

How to prevent redirect if image is embedded?

I currently have setup to redirect if a user direct access the image by browser. However I do not want to redirect if a image is embedded on the page using <img src=""/>

this is my nginx conf

location ~ "^/c/600x1200_90_webp/img-master/img/\d+/\d+/\d+/\d+/\d+/\d+/((?<filenum>\d+)[^/]+\.(jpg|png|webp))$" {
proxy_pass http://xxx.xxx.xxx.xxx:8081;
valid_referers server_names;
if ($invalid_referer = "1") {
return 301 http://example.com/detail?id=$filenum; }
}

How can I fix this?

Comments

  • jmgcaguiclajmgcaguicla Member
    edited February 2022

    In the spirit of not being a Stack Exchange cucklord who will explain why X is better than Y instead of answering the question:

    Instead of checking for valid referrers (via server_names), you should just be checking against blank referrers. A request from an embed usually™ has a non-empty Referer header as opposed to a direct link.

    Again, this is not water-tight as people can just spoof but I'm assuming you just need a "works most of the times" solution so here you go.

    Thanked by 1bulbasaur
Sign In or Register to comment.