java - 如何防止独立 Java webapp 服务器上的热链接?

标签 java tomcat hotlinking

如何防止在像 Tomcat 这样的独立 Java web 应用程序服务器上进行热链接?

最佳答案

使用 Tuckey 的 URLRewriteFilter(其他人已经间接提及)。来自documentation :

<rule>
    <name>Blocked Inline-Images</name>
    <note>
        Assume we have under http://www.quux-corp.de/~quux/ some pages with inlined GIF graphics. These graphics are
        nice, so others directly incorporate them via hyperlinks to their pages. We don't like this practice because
        it adds useless traffic to our server.

        While we cannot 100% protect the images from inclusion, we can at least restrict the cases where the browser
        sends a HTTP Referer header.

        RewriteCond %{HTTP_REFERER} !^$
        RewriteCond %{HTTP_REFERER} !^http://www.quux-corp.de/~quux/.*$ [NC]
        RewriteRule .*\.gif$ - [F]
    </note>
    <condition name="referer" operator="notequal">^$</condition>
    <condition name="referer" operator="notequal">^http://www.quux-corp.de/~quux/.*$</condition>
    <from>.*\.gif$</from>
    <set type="status">403</set>
    <to>null</to>
</rule>

<rule>
    <name>Blocked Inline-Images example 2</name>
    <note>
        RewriteCond %{HTTP_REFERER} !^$
        RewriteCond %{HTTP_REFERER} !.*/foo-with-gif\.html$
        RewriteRule ^inlined-in-foo\.gif$ - [F]
    </note>
    <condition name="referer" operator="notequal">^$</condition>
    <condition name="referer" operator="notequal">.*/foo-with-gif\.html$</condition>
    <from>^inlined-in-foo\.gif$</from>
    <set type="status">403</set>
    <to>null</to>
</rule>

关于java - 如何防止独立 Java webapp 服务器上的热链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4051222/

相关文章:

java - 如何对 JWT Secured Rest API 进行负载测试

java - HTTP header 结束

php - 是否可以区分使用 .htaccess 的图像热链接和常规链接?

javascript - 框架集共享一个JavaScript库

java - 从java读取文件系统结构

java - 避免在 Java CMS GC 中升级失败

java - 无法在我的本地主机上运行 Apache Tomcat 服务器?

tomcat - 为 Tomcat 中的不同错误消息设置自定义 html 页面

java - JProfiler 7.2.2 远程 JVM 崩溃

asp.net - 如何防止来自您的 ASP.NET 站点的图像热链接?