最近经常逛csdn

              最近经常逛csdn,这个学期寝室一直都没网,所以我的csdn账号一直没怎么更新。就前几天去隔壁寝室牵了根网线过来所以才能上网的。

    一直以来很喜欢csdn这个网站的,不仅可以在首页看到计算机方面的一些最新的资讯,更重要的是论坛,我比较喜欢论坛,以前在学mfc的时候就经常逛论坛,现在自学了java,还有web就更喜欢来论坛了,因为论坛里面关于这方面的东西比较多,有时我也可以回答一下别人提出的问题。

    但是唯一的一点就是,泡论坛好费时间啊,看一个板块,就只看一页差不多一上午时间就过去了。感觉时间过得好快,有时就直接在csdn上泡一整天了,这样一来没多少时间编程了,不能经常这样,经常泡论坛并不是一件好事情,泡一整天还不如自己多敲点程序。

   而且最近还有其它的事,额,如果时间和精力允许真的想一直泡在csdn的论坛上。

### Cookie 的不可跨域机制及其工作原理 #### 什么是 Cookie? Cookie 是一种存储在客户端的小型数据片段,通常由服务器生成并发送给浏览器。当浏览器再次向同一服务器发起请求时,会自动将这些 Cookie 数据随请求一起发送回去。 #### Cookie 的不可跨域特性 为了保护用户的隐私和安全,浏览器实现了严格的同源策略(Same-Origin Policy),其中就包括对 Cookie 的管理规则。具体来说: - **同源定义**:两个 URL 被认为是同源的,如果它们具有相同的协议、主机名和端口号。 - **不可跨域原则**:浏览器只会将某个域名下的 Cookie 发送到与其匹配的目标站点上[^1]。这意味着 A 网站无法读取或写入 B 网站的 Cookie。 #### 工作原理详解 以下是 Cookie 不可跨域特性的主要工作机制: 1. **设置 Domain 属性** 当服务器创建一个 Cookie 并将其返回到客户端时,可以通过 `setDomain` 方法指定该 Cookie 所属的有效域名范围。例如,在 Java 中可以这样操作: ```java cookie.setDomain(".b.com"); ``` 这表示 `.b.com` 及其子域名都可以共享此 Cookie。 2. **路径 Path 控制** 此外还可以通过设定 `Path` 来进一步限定哪些页面能够访问特定的 Cookie。比如 `/admin/*` 页面可能拥有独立于其他部分的功能所需的不同 Cookies 设置。 3. **Secure 和 HttpOnly 标志位的作用** - 如果设置了 `Secure` 参数,则只有 HTTPS 协议下才会传输这个 Cookie; - 使用 `HttpOnly` 后 JavaScript 就不能再直接获取或者修改它了,从而减少 XSS 攻击风险[^3]。 4. **SameSite 属性的影响** Modern browsers introduced the `SameSite` attribute to restrict how cookies are sent with cross-origin requests. - Setting it as `Strict`, no cookies will be attached when making third-party calls; - Choosing `Lax` allows some GET operations while still preventing others like POST submissions across different origins unless explicitly allowed via CORS headers such as Access-Control-Allow-Credentials set true alongside appropriate Origin values being accepted by server side logic.[^3] #### 实际案例分析——B站 & 优快云 示例说明 ##### 案例一:Bilibili (假设场景) 假如你在 bilibili 登录成功之后跳转到了合作方网站 dianying.bilibili.com ,此时虽然两者都属于同一个顶级域名体系之下(`*.bilibili.com`)但由于存在不同的二级甚至三级子域所以需要特别处理才能让登录状态得以延续: ```javascript // Vue.js 配置 Axios 请求携带凭证 import axios from 'axios'; axios.defaults.withCredentials = true; // Server-side code snippet in PHP ensuring proper header settings for allowing credentials sharing between domains under certain conditions only after verifying incoming request's origin matches expected whitelist entries beforehand... header('Access-Control-Allow-Origin: https://www.bilibili.com'); header('Access-Control-Allow-Credentials: true'); ``` 上述代码展示了如何利用现代 Web 技术克服传统意义上的“完全隔离”的局限性同时又不失安全性考虑[^2]. ##### 案例二:优快云 Blog Post Example Another illustrative example comes directly out of an actual blog post written specifically addressing similar concerns regarding maintaining session continuity over multiple subdomains within a single parent domain structure without compromising overall system integrity too much either programmatically or architecturally speaking... Here we see another practical demonstration involving both client-side adjustments made possible thanks largely due recent advancements brought forth through widespread adoption standards-based approaches combined together along best practices recommendations designed keep things running smoothly even amidst increasingly complex interconnected environments today’s digital landscape presents us daily basis regularly encounter during normal course business activities conducted online virtually everywhere around world wide web constantly evolving ever-changing fast pace manner indeed! --- ### 总结 综上所述,Cookies 的设计初衷即包含了防止恶意程序滥用个人信息的重要考量因素在里面,因此才会有如此严格的规定来约束它的行为表现形式等方面内容涉及到方方面面细节之处都需要格外留意才行哦!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值