AEM提供了一个旨在防止跨站点请求伪造攻击的框架。 为了正确利用此框架,您需要对调度程序配置进行以下更改:
请务必根据现有配置更新以下示例中的规则编号。 请记住,调度程序将使用最后一个匹配规则授予允许或拒绝,因此将规则放在现有列表的底部附近。
/clientheaders
部分,在列表底部添加以下条目:CSRF-Token
author-farm.any
和publish-farm.any
或publish-filters.any
文件的/过滤器部分,添加以下行以允许通过调度程序请求/libs/granite/csrf/token.json
。/0999 { /type "allow" /glob " * /libs/granite/csrf/token.json*" }
publish-farm.any
的/cache /rules
部分下,添加一个规则以阻止调度程序缓存token.json
文件。 通常作者会绕过缓存,因此您不必将规则添加到author-farm.any
中。/0999 { /glob "/libs/granite/csrf/token.json" /type "deny" }
要验证配置是否正在工作,请在DEBUG模式下观察dispatcher.log以验证token.json文件是否未缓存且未被过滤器阻止。 您应当看到类似以下内容的消息:
... checking [/libs/granite/csrf/token.json]
... request URL not in cache rules: /libs/granite/csrf/token.json
... cache-action for [/libs/granite/csrf/token.json]: NONE
您还可以验证apache access_log
中的请求是否成功。 “/libs/granite/csrf/token.json”的请求应返回HTTP 200状态代码。