Alfresco 5 Community Edition で使用するモジュール拡張を作成しました。すべてがうまく機能し、.get メソッドが処理され、適切に表示されます。
ページには、結果を表示するためにサーバーにポストバックするボタンがあります (現在はテスト用に空です)。ボタンをクリックすると、サーバーエラーが発生します。
javax.servlet.ServletException: Possible CSRF attack noted when comparing token in session and request header. Request: POST /share/service/components/console/reset-dashboards
at org.alfresco.web.site.servlet.CSRFFilter$AssertTokenAction.run(CSRFFilter.java:827)
at org.alfresco.web.site.servlet.CSRFFilter.doFilter(CSRFFilter.java:312)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2466)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2455)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
で Webscripts uri を確認すると、http://localhost:8080/share/page/index/uri/components/console/reset-dashboards
すべてが適切に登録されていることがわかります
Reset Dashboards
GET /share/page/components/console/reset-dashboards
Description: Dashboard Tools - Reset All Dashboards To Default
Authentication: none
Transaction: none
Format Style: any
Default Format: html
Id: com/company/components/console/dashboard-tools/reset-dashboards.get
Description: classpath:alfresco/site-webscripts/com/company/components/console/dashboard-tools/reset-dashboards.get.desc.xml
Reset Dashboards POST
POST /share/page/components/console/reset-dashboards
Description: Dashboard Tools - Reset All Dashboards To Default POST
Authentication: user
Transaction: required
Format Style: any
Default Format: json
Id: com/company/components/console/dashboard-tools/reset-dashboards.post
Description: classpath:alfresco/site-webscripts/com/company/components/console/dashboard-tools/reset-dashboards.post.desc.xml
これは、GET Web スクリプトの情報です。
Script Properties
Id: com/company/components/console/dashboard-tools/reset-dashboards.get
Short Name: Reset Dashboards
Description: Dashboard Tools - Reset All Dashboards To Default
Authentication: none
Transaction: none
Method: GET
URL Template: /components/console/reset-dashboards
Format Style: any
Default Format: html
Negotiated Formats: [undefined]
Implementation: class org.springframework.extensions.webscripts.DeclarativeWebScript
Extensions: [undefined]
Store: classpath:alfresco/site-webscripts
File: com/company/components/console/dashboard-tools/reset-dashboards.get.desc.xml
<webscript>
<shortname>Reset Dashboards</shortname>
<description>Dashboard Tools - Reset All Dashboards To Default</description>
<url>/components/console/reset-dashboards</url>
<family>admin-console</family>
</webscript>
File: com/company/components/console/dashboard-tools/reset-dashboards.get.html.ftl
<@markup id="css" >
<#-- CSS Dependencies -->
<@link href="${url.context}/res/components/console/application.css" group="console"/>
</@>
<@markup id="js">
<#-- JavaScript Dependencies -->
<@script src="${url.context}/res/components/console/consoletool.js" group="console"/>
<#--<@script src="${url.context}/res/components/console/application.js" group="console"/>-->
</@>
<@markup id="widgets">
<@createWidgets group="console"/>
</@>
<@markup id="html">
<#assign el=args.htmlid?html>
<form id="${el}-options-form" action="${url.context}/service/components/console/reset-dashboards" method="post">
<div class="buttons">
<button id="${el}-apply-button" name="apply">${msg("button.reset")}</button>
</div>
</form>
</@>
File: com/company/components/console/dashboard-tools/reset-dashboards.get.js
function main()
{
}
main();
Store: classpath:surf/webscripts
[No implementation files]
Store: classpath:webscripts
[No implementation files]
これは、POST Web スクリプトの情報です。
Script Properties
Id: com/company/components/console/dashboard-tools/reset-dashboards.post
Short Name: Reset Dashboards POST
Description: Dashboard Tools - Reset All Dashboards To Default POST
Authentication: user
Transaction: required
Method: POST
URL Template: /components/console/reset-dashboards
Format Style: any
Default Format: json
Negotiated Formats: [undefined]
Implementation: class org.springframework.extensions.webscripts.DeclarativeWebScript
Extensions: [undefined]
Store: classpath:alfresco/site-webscripts
File: com/company/components/console/dashboard-tools/reset-dashboards.post.desc.xml
<webscript>
<shortname>Reset Dashboards POST</shortname>
<description>Dashboard Tools - Reset All Dashboards To Default POST</description>
<format default="json" />
<url>/components/console/reset-dashboards</url>
<authentication>user</authentication>
</webscript>
File: com/company/components/console/dashboard-tools/reset-dashboards.post.json.ftl
{
"success": ${success?string},
"message": "<#if errormsg??>${errormsg}</#if>"
}
File: com/company/components/console/dashboard-tools/reset-dashboards.post.json.js
function main()
{
model.success = true;
}
main();
Store: classpath:surf/webscripts
[No implementation files]
Store: classpath:webscripts
[No implementation files]
繰り返しますが、ページのボタンをクリックして Webscript に投稿すると、Possible CSRF attack
例外が発生します。これを修正するにはどうすればよいですか? jar
モジュール拡張ファイル内でそれを行うことは可能ですか?
アップデート
Alfresco-CSRFToken
Alfresco の一部として投稿される他のすべてのスクリプトには、同じ名前のヘッダーと Cookie が含まれていることに気付きました。私のスクリプトにAlfresco-CSRFToken
は Cookie としてのみ含まれており、ヘッダーとして欠落しています。ただし、これがヘッダーとして存在することを確認する方法がわかりません。