The Origin Header

The Origin header is a vital security feature in HTTP requests. It conveys the essential information about the source (origin) of a request to the server that receives it. This origin is comprised of three parts:

  • Scheme: This indicates the protocol used, like HTTP or HTTPS.
  • Hostname: This is the domain name of the website making the request (e.g., "www.example.com").
  • Port (optional): If a non-standard port is used (usually 80 for HTTP and 443 for HTTPS), it's also included in the Origin header.

Key Points:

  • Origin vs. Referer: The Origin header differs from the Referer header in a crucial way. While the Referer includes the entire URL with the path, the Origin omits the path information. This is done to prevent sensitive data, potentially within the path, from being revealed.
  • Browser-controlled: The browser automatically adds the Origin header to specific requests. Users cannot modify it directly.
  • When is it Sent? The Origin header is primarily included in two scenarios:
    • Cross-Origin Requests: Whenever a web page requests resources (scripts, images, etc.) from a different domain than its own, the Origin header is mandatory. This helps enforce security restrictions between domains (covered in CORS).
    • Same-Origin Requests (Modern Browsers): In some modern browsers, the Origin header might also be included in same-origin requests, particularly for methods like PUT, POST, and DELETE.

Role in CORS (Cross-Origin Resource Sharing)

The Origin header plays a central role in CORS, a security mechanism that governs how browsers handle requests between different domains. By including the Origin header, the browser informs the server about the request's origin. The server can then check its CORS configuration (using Access-Control-Allow-Origin header) to determine whether to allow or restrict the request based on its origin.



See

HTTP协议中的“X-Real-IP”头字段的作用是什么?底层原理是什么?-阿里云开发者社区

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin

http - X-Original-For header: what's its purpose? - Stack Overflow

  • 11
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

P("Struggler") ?

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值