REST API calls with a browser User-Agent header may fail CSRF checks

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Fisheye および Crucible は除く

問題

Specifying a Browser User-Agent header in a REST API call makes it fail to be executed. Example:

curl -D- -u admin:admin -X POST -H "Content-Type: application/json" -d @"P:\UTIL\script\rest.json" http://localhost:8705/jira/rest/api/2/issue -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36"

診断

From the log, the following WARN is thrown:

2016-02-03 22:25:15,125 http-nio-8705-exec-15 WARN admin 1345x6598x1 1jbuio 0:0:0:0:0:0:0:1 /rest/api/2/issue [c.a.p.r.c.security.jersey.XsrfResourceFilter] Additional XSRF checks failed for request: http://localhost:8705/jira/rest/api/2/issue , origin: null , referrer: null , credentials in request: true , allowed via CORS: false

This is known to affect The RESTClient Firefox plugin. This is because Firefox plugins, unlike Chrome and Safari plugins, do not include an Origin header with a plugin origin.

tip/resting Created with Sketch.

This works in Postman where Access-Control-Allow-Origin is seen by the browser.

原因

Atlassian REST の先日の変更を受け、リクエストのオリジンが信頼されない場合に一部のブラウザ リクエストがブロックされるようになりました。

More information can be found in Cross Site Request Forgery(CSRF) protection changes in Atlassian Rest.

ソリューション

  1. Since REST API doesn't require a User-Agent header, removing the header works.

  2. Alternatively, adding an Origin or Referrer header to the call that specifies the same origin or a whitelisted one also works:

    curl -D- -u admin:admin -X POST -H "Origin: https://dc.andy.com" -H "Content-Type: application/json" -d @"P:\UTIL\script\rest.json" https://dc.andy.com/jira/rest/api/2/issue -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36"

説明 Specifying a Browser User-Agent header in a REST API call makes it fail to be executed
製品Jira
プラットフォームServer
最終更新日 2018 年 11 月 15 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.