Rails 默认 CSRF 元标记未验证
我刚刚验证了一个新站点,这是我使用 Rails 3 编写的带有 W3C 标记验证的新站点,但我收到了有关 Rails 生成的 CSRF 标记的错误。
“元素元上的属性名称的 csrf-param 值错误:关键字 csrf-param 未注册。”
<meta name="csrf-param" content="authenticity_token"/>
和
“元素元上的属性名称的 csrf-token 值错误:关键字 csrf-token未注册。”
<meta name="csrf-token" content="{token}"/>
我已将 DOCTYPE 设置为
<!DOCTYPE html>
据我所知,我不必添加任何其他内容。有人能解释一下吗?
编辑
我正在使用 HAML,想知道这是否是一个促成因素,所以我设置了一个测试页面,它有一个控制器/操作/视图,并且只使用 Rails 默认的 erb 模板。问题仍然出现。
I've just validated a new site a new site that i've written using Rails 3 with the W3C markup validation and i'm getting errors about the CSRF tags that rails generates.
"Bad value csrf-param for attribute name on element meta: Keyword csrf-param is not registered."
<meta name="csrf-param" content="authenticity_token"/>
AND
"Bad value csrf-token for attribute name on element meta: Keyword csrf-token is not registered."
<meta name="csrf-token" content="{token}"/>
I have my DOCTYPE set to
<!DOCTYPE html>
As far as i was aware i shouldn't have to add anything else. Can anyone shed any light on this please?
EDIT
I'm using HAML and wondered whether that could be a contributing factor so i set up a test page which has a single controller/action/view and only uses the Rails default erb templates. The problem still occurs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你真的不应该担心这个。 HTML5 元标记的使用非常开放。所有这些验证表明,根据 W3C 规范,这些技术上不是“合法”的 HTML5 元数据名称,但它不会影响功能。以下是元标记的建议扩展列表:
http://wiki.whatwg.org/wiki/MetaExtensions
csrf-token 和 csrf-param 已在“提案”状态的列表中。如果这些被添加到 W3C 规范中,您将不会再看到此验证错误。
You shouldn't really worry about this. The HTML5 meta tag is pretty open with its use. All this validation is saying is that those technically aren't "legal" HTML5 metadata names according to the W3C spec, but it will not affect functionality. Here's a list of the proposed extensions for the meta tag:
http://wiki.whatwg.org/wiki/MetaExtensions
csrf-token and csrf-param are already on the list in "Proposal" status. If these get added to the W3C spec you shouldn't see this validation error anymore.