确保将Google OpenID详细信息隐藏到请求网站

时间:2012-01-13 10:59:59

标签: php openid google-openid spoofing

我可能遗漏了一些非常愚蠢的内容,并在Google Federated Login文档中错过了它,但Google OpenID登录对请求网站的实际安全性如何?请求网站如何知道详细信息来自Google,而不仅仅是在URL中输入查询字符串参数?

为了说明这一点,我在PHP中实现了一个基本的OpenID登录序列,似乎返回的所有内容都是URL中的一堆查询字符串参数,我可以用它来获取OpenID详细信息,效果很好。问题是,如果我只是手动输入地址栏而没有实际登录谷歌,我的请求网站将如何知道差异?

首先,请求详细信息的表单:

<form method='post' action='https://www.google.com/accounts/o8/ud'>

    <input type='hidden' name='openid.return_to' value='http://www.example/com/logged-in' />

    <input type='hidden' name='openid.mode' value='checkid_setup' />
    <input type='hidden' name='openid.ns' value='http://specs.openid.net/auth/2.0' />
    <input type='hidden' name='openid.claimed_id' value='http://specs.openid.net/auth/2.0/identifier_select' />
    <input type='hidden' name='openid.identity' value='http://specs.openid.net/auth/2.0/identifier_select' />

    <input type='hidden' name='openid.ns.ax' value='http://openid.net/srv/ax/1.0' />
    <input type='hidden' name='openid.ax.mode' value='fetch_request' />
    <input type='hidden' name='openid.ax.required' value='email,firstname,lastname' />
    <input type='hidden' name='openid.ax.type.email' value='http://axschema.org/contact/email' />
    <input type='hidden' name='openid.ax.type.firstname' value='http://axschema.org/namePerson/first' />
    <input type='hidden' name='openid.ax.type.lastname' value='http://axschema.org/namePerson/last' />

    <input type='submit' value='Login With Google Account' />

</form>

...效果很好,通过一大堆网址参数将我发回http://www.example.com/logged-in的请求网站,如下所示(来自PHP print_r电话):

Array
(
    [openid_ns] => http://specs.openid.net/auth/2.0
    [openid_mode] => id_res
    [openid_return_to] => http://www.example.com/logged-in
    [openid_ext1_type_firstname] => http://axschema.org/namePerson/first
    [openid_ext1_value_firstname] => {user's first name}
    [openid_ext1_type_email] => http://axschema.org/contact/email
    [openid_ext1_value_email] => {user's e-mail address}
    [openid_ext1_type_lastname] => http://axschema.org/namePerson/last
    [openid_ext1_value_lastname] => {user's last name}
)

...这真棒,但我怎么知道这实际上是一个合法的请求,而不是有人在地址栏中输入上述参数?

感谢您提供任何帮助,如果已经提出过这样的问题,请道歉(找不到任何副本!),如果我遗漏了一些明显的东西!

1 个答案:

答案 0 :(得分:1)

如果不需要太多细节(如果需要详细信息,请阅读OpenID规范),OpenID协议为此提供了安全措施。您收到的断言是经过签名和验证的,并且ID的命名方式存在限制,以防止提供程序欺骗彼此的ID。如果您正在使用已建立的库(例如php-openid就好了),您不必过于担心这一点,因为它通常会在封面下进行处理。如果你正在尝试推出自己的实现......好吧,就是不要......

也就是说,协议中有一些的内容。例如,虽然在响应中签署了属性,但除非您信任特定提供者,否则您不能认为它们是准确的。某些应用程序将检查发出声明的提供程序的URL /主机名(在验证响应之后)并将已知身份提供程序列入白名单以进行正确的电子邮件验证。如果您需要经过验证的电子邮件,这样做可以提供更好的用户体验。但是,如果断言来自未知身份提供者,则不要认为电子邮件地址实际上属于用户,除非您自己验证拥有权。