简体   繁体   English

Symfony2会话固定如何工作?

[英]How does Symfony2 session fixation work?

According to the standard 2.4 documentation, the security.yml config file allows for the following configuration option: 根据标准2.4文档,security.yml配置文件允许以下配置选项:

session_fixation_strategy: none | migrate | invalidate

source: http://symfony.com/doc/current/reference/configuration/security.html 来源: http//symfony.com/doc/current/reference/configuration/security.html

However, I fail to find any details in the official documentation (or elsewhere) on what this option actually does, or how it works in practice. 但是,我没有在官方文档(或其他地方)中找到有关此选项实际执行的内容或其在实践中如何工作的任何详细信息。

So, if I set this option to either "migrate" or "invalidate", how will this affect session handling in my system? 因此,如果我将此选项设置为“migrate”或“invalidate”,这将如何影响我的系统中的会话处理? For example, if I set it to "invalidate", would this mean that a context-local session is invalidated when the user navigates to a different security context? 例如,如果我将其设置为“invalidate”,这是否意味着当用户导航到不同的安全上下文时,上下文本地会话无效?

In short: 简而言之:

  • NONE: the session is not changed NONE:会话未更改
  • MIGRATE: the session id is updated, attributes are kept MIGRATE:更新会话ID,保留属性
  • INVALIDATE: the session id is updated, attributes are lost INVALIDATE:会话ID更新,属性丢失

In detail: 详细地:

  1. None strategy: Nothing is (supposed to be) done in the default session implementation, thus the session is maintained from one context to the other. 无策略:在默认会话实现中没有(应该)完成任务,因此会话从一个上下文维护到另一个上下文。

  2. Migrate strategy: "Migrates the current session to a new session id while maintaining all session attributes." 迁移策略:“将当前会话迁移到新的会话ID,同时保留所有会话属性。” (The session storage should regenerate the current session.) "Regenerates id that represents this storage. This method must invoke session_regenerate_id($destroy) unless this interface is used for a storage object designed for unit or functional testing where a real PHP session would interfere with testing. Note regenerate+destroy should not clear the session data in memory only delete the session data from persistent storage." (会话存储应该重新生成当前会话。)“重新生成代表此存储的id。此方法必须调用session_regenerate_id($ destroy),除非此接口用于为单元或功能测试而设计的存储对象,其中真正的PHP会话会干扰注意,重新生成+销毁不应该清除内存中的会话数据,只能从持久存储中删除会话数据。“ Thus the session is retained from one context to the other. 因此,会话从一个上下文保留到另一个上下文。

  3. Invalidate strategy: "Clears all session attributes and flashes and regenerates the session and deletes the old session from persistence." 无效策略:“清除所有会话属性并闪烁并重新生成会话,并从持久性中删除旧会话。” Thus the session is regenerated from one context to the other. 因此,会话从一个上下文重新生成到另一个上下文。

It was not revealed by your question what kind of session data you are trying to fetch. 您的问题没有透露您尝试获取的会话数据类型。
But in any case, no separate session is generated for different security contexts: http://symfony.com/doc/current/reference/configuration/security.html#firewall-context 但无论如何,不​​会为不同的安全上下文生成单独的会话: http//symfony.com/doc/current/reference/configuration/security.html#firewall-context

Security (authentication) related data is stored under a separate key (based on the firewall name). 安全(身份验证)相关数据存储在单独的密钥下(基于防火墙名称)。 So for example if you have a firewall with a name 'main', the authentication token will be stored under '_security_main', if you have a firewall (a separate context) with a name 'foo', the user and related token data will be stored under '_security_foo', etc. 因此,例如,如果您的防火墙名称为“main”,则身份验证令牌将存储在“_security_main”下,如果您拥有名为“foo”的防火墙(单独的上下文),则用户和相关令牌数据将存储在'_security_foo'等下面

So besides ->getToken ->getUser (etc.) the rest of the session variables will be available in different contexts provided you use the 'none' or the 'migrate' session strategies. 因此,除了 - > getToken - > getUser(等)之外,如果您使用'none'或'migrate'会话策略,其余的会话变量将在不同的上下文中可用。

Take a look at the session interface for details (quotes are from these files) vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/SessionInterface.php 请查看会话界面以获取详细信息(引用来自这些文件)vendor / symfony / symfony / src / Symfony / Component / HttpFoundation / Session / SessionInterface.php

And the default implementation: vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Session/Session.php 默认实现:vendor / symfony / symfony / src / Symfony / Component / HttpFoundation / Session / Session.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM