HTTP Web 安全

一般性 Web 校验

验证码 Captcha 机制

HTTP 标准认证

API 接口功能

其他实用功能

HTTP Referer 校验

HTTP Referer 校验(也称为“Referer 检查”)是一种常见的 Web 安全措施,其原理是:后端服务器在接收请求时检查请求头中的 Referer 字段,判断请求来源是否为信任的域名或页面。

基本原理

  1. 客户端(浏览器)在发起 HTTP 请求时,会在请求头里带上Referer,指明请求的来源页面地址。
  2. 服务器端在收到请求后,读取Referer,判断其是否为受信任的来源。
  3. Referer不符合要求,则拒绝请求或返回错误。

常用场景

注意事项

使用方式

yaml 配置

security:
  HttpReferer: # Referer 拦截
    globalCheck: false # 全局检查
    enabled: true
    allowedReferrers:
      - https://example.com
      - https://another-example.com
      - https://my-site.com

拦截校验

在使用的接口上添加@HttpRefererCheck注解:

@GetMapping("/HttpRefererCheck")
@HttpRefererCheck
int HttpRefererCheck();