简体   繁体   English

Symfony2 - security.yml中`anonymous.key`的用途

[英]Symfony2 - Purpose of `anonymous.key` in security.yml

I was setting up a Symfony2 application earlier that included routes that are both anonymous and restricted by HTTP BasicAuth. 我之前正在设置一个Symfony2应用程序,其中包含匿名和HTTP BasicAuth限制的路由。 A basic firewall configuration using default values looks something like: 使用默认值的基本防火墙配置如下所示:

firewalls:
    main:
        anonymous: ~
        http_basic: ~

I could not find information on the options for the anonymous property, except in documentation for Symfony2's SecurityBundle Configuration, which presents a full default configuration . 我找不到有关anonymous属性选项的信息,但Symfony2的SecurityBundle配置文档除外,它提供了完整的默认配置

The anonymous property appears to have only one property: key , as shown on line 206 of the default configuration: anonymous属性似乎只有一个属性: key ,如默认配置的第206行所示:

some_firewall_listener:
    # ...
    anonymous:
        key: 4f954a0667e01

I dug into the core codebase and the accompanying unit tests a little, and it appears to be a constructor value for AnonymousToken and/or AnonymousAuthenticationListener but I haven't learned much from that so far. 我挖掘了核心代码库和附带的单元测试了一点,它似乎是AnonymousToken和/或AnonymousAuthenticationListener的构造函数值,但到目前为止我还没有学到很多东西。

There's a key property under remember_me also but I assume this has a different purpose. remember_me下还有一个key属性,但我认为这有不同的用途。

I cannot find any other information that describes what this particular key property is, and what its purpose is. 我找不到任何其他信息来描述这个特定的key属性是什么,以及它的目的是什么。 AnonymousToken::__construct() requires $key and $user arguments, so I assume this option is simply a manual override for a value that Symfony2 otherwise creates itself. AnonymousToken::__construct()需要$key$user参数,所以我假设这个选项只是对Symfony2自己创建的值的手动覆盖。

Can someone advise? 有人可以提供建议吗? Thanks :) 谢谢 :)

When authenticating an AnonymousToken , they key of the AnonymousAuthenticationProvider and the token are compared. 在验证AnonymousToken ,将比较AnonymousAuthenticationProvider密钥和令牌。 When they don't match, authentication fails. 如果它们不匹配,则身份验证失败。

The same applies to the RememberMeToken and RememberMeAuthenticationProvider . 这同样适用于RememberMeTokenRememberMeAuthenticationProvider When the key of the token and provider don't match, authentication fails. 当令牌和提供程序的密钥不匹配时,身份验证将失败。

The key is used to determine that the token currently authenticating was created by the application itself and not submitted by a malicious client. 密钥用于确定当前正在进行身份验证的令牌是由应用程序本身创建的,而不是由恶意客户端提交的。 This mostly comes from the fact that Symfony Security is based on Spring Security (Java) and Java has RMI (Remote Method Invocation) support. 这主要来自Symfony Security基于Spring Security(Java)和Java具有RMI(远程方法调用)支持的事实。 From the Spring docs : Spring文档

The use of the key property should not be regarded as providing any real security here. 关键属性的使用不应被视为在此提供任何真正的安全性。 It is merely a book-keeping exercise. 这只是一本簿记练习。 If you are sharing a ProviderManager which contains an AnonymousAuthenticationProvider in a scenario where it is possible for an authenticating client to construct the Authentication object (such as with RMI invocations), then a malicious client could submit an AnonymousAuthenticationToken which it had created itself (with chosen username and authority list). 如果您正在共享一个包含AnonymousAuthenticationProvider的ProviderManager,在这种情况下,身份验证客户端可以构造Authentication对象(例如使用RMI调用),那么恶意客户端可以提交它自己创建的AnonymousAuthenticationToken(已选中)用户名和权限列表)。 If the key is guessable or can be found out, then the token would be accepted by the anonymous provider. 如果密钥是可猜测的或可以找到,那么匿名提供者将接受该令牌。 This isn't a problem with normal usage but if you are using RMI you would be best to use a customized ProviderManager which omits the anonymous provider rather than sharing the one you use for your HTTP authentication mechanisms. 这不是正常使用的问题,但如果您使用的是RMI,最好使用自定义的ProviderManager,它省略了匿名提供程序,而不是共享您用于HTTP身份验证机制的提供程序。

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

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