{"action":"created","comment":{"url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments/45582033","id":45582033,"diff_hunk":"@@ -28,6 +29,23 @@ var eventize = function (that) {\n     return that;\n };\n \n+// This is copy of csrf ajax utilities from hqwebapp/js/ajax_csrf_setup.js","path":"corehq/apps/hqwebapp/static/hqwebapp/js/main.js","position":12,"original_position":12,"commit_id":"7a5c3e50069bb1d98c7619f83b6a897f6ff5bb15","original_commit_id":"7a5c3e50069bb1d98c7619f83b6a897f6ff5bb15","user":{"login":"sravfeyn","id":829142,"avatar_url":"https://avatars.githubusercontent.com/u/829142?v=3","gravatar_id":"","url":"https://api.github.com/users/sravfeyn","html_url":"https://github.com/sravfeyn","followers_url":"https://api.github.com/users/sravfeyn/followers","following_url":"https://api.github.com/users/sravfeyn/following{/other_user}","gists_url":"https://api.github.com/users/sravfeyn/gists{/gist_id}","starred_url":"https://api.github.com/users/sravfeyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sravfeyn/subscriptions","organizations_url":"https://api.github.com/users/sravfeyn/orgs","repos_url":"https://api.github.com/users/sravfeyn/repos","events_url":"https://api.github.com/users/sravfeyn/events{/privacy}","received_events_url":"https://api.github.com/users/sravfeyn/received_events","type":"User","site_admin":false},"body":"Wait, I already did that. See [`ajax_csrf_setup.js`](https://github.com/dimagi/commcare-hq/pull/9227/files#diff-10bef7ead42aafa580f5d7973b364700R6) which is being reused in lot of places.\r\n\r\nThis situation is little more complicated in that, the `main.js` here is kind of an API for saveButton which is used in lot of places. The options I have here are either 1. load above reusable ajax_csrf_setup.js in all those places where `main.js` is loaded or 2. Copy paste ajax_csrf_setup to `main.js` so that that repetition is avoided.","created_at":"2015-11-23T09:06:33Z","updated_at":"2015-11-23T09:06:33Z","html_url":"https://github.com/dimagi/commcare-hq/pull/9227#discussion_r45582033","pull_request_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/9227","_links":{"self":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments/45582033"},"html":{"href":"https://github.com/dimagi/commcare-hq/pull/9227#discussion_r45582033"},"pull_request":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/9227"}}},"pull_request":{"url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/9227","id":51492307,"html_url":"https://github.com/dimagi/commcare-hq/pull/9227","diff_url":"https://github.com/dimagi/commcare-hq/pull/9227.diff","patch_url":"https://github.com/dimagi/commcare-hq/pull/9227.patch","issue_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/9227","number":9227,"state":"open","locked":false,"title":"Partially enable csrf protection on HQ. ","user":{"login":"sravfeyn","id":829142,"avatar_url":"https://avatars.githubusercontent.com/u/829142?v=3","gravatar_id":"","url":"https://api.github.com/users/sravfeyn","html_url":"https://github.com/sravfeyn","followers_url":"https://api.github.com/users/sravfeyn/followers","following_url":"https://api.github.com/users/sravfeyn/following{/other_user}","gists_url":"https://api.github.com/users/sravfeyn/gists{/gist_id}","starred_url":"https://api.github.com/users/sravfeyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sravfeyn/subscriptions","organizations_url":"https://api.github.com/users/sravfeyn/orgs","repos_url":"https://api.github.com/users/sravfeyn/repos","events_url":"https://api.github.com/users/sravfeyn/events{/privacy}","received_events_url":"https://api.github.com/users/sravfeyn/received_events","type":"User","site_admin":false},"body":"This PR does *#*1 and some of *#*2 of following. Best reviewed per commit\r\n\r\nWe are in the process of turning CSRF protection on for HQ. This involves two things\r\n1. Turn on csrf check on server side to reject invalid requests\r\n2. Include csrf tokens in all the HTML forms and ajax requests\r\n\r\nDoing *#*1 means a lot of HQ forms and ajax code that does't include csrf requests will fail. To gracefully switch to csrf-protection, we are turning on *#*1, but instead of rejecting invalid requests, we are soft-asserting that these requests are invalid and that the corresponding forms be fixed. \r\n\r\nTo fix a soft-assert `csrftoken` should be included in that request. Here is how you do it\r\n\r\n1. Find the HTML form or ajax code that is the source of the invalid request and do one of following.\r\n2. If it is an HTML form, simply append `{% csrftoken %}` template var to the HTML form. Here is an [example](https://github.com/dimagi/commcare-hq/commit/2a69336776252431413cc2c0bd2ccb3602364fd1#diff-4b35c1177f06760f4eb5590a89d5fc38R519)\r\n3. If it is ajax code, the ajax call needs to send the correct csrftoken. See this [example](https://github.com/dimagi/commcare-hq/commit/15ef9840baa6c7e4de41c2ebb31e5fa669a059ec#diff-aaec15f91412f9a1acb5d0cb69ce9144R296)\r\n4. Here is the [example](https://github.com/dimagi/commcare-hq/commit/2a69336776252431413cc2c0bd2ccb3602364fd1#diff-a7d4c523af44f14bc7c79367a783011dR27) to make an angular form csrf safe\r\n\r\nUse `settings.CSRF_ALWAYS_OFF = False` when testing the fix. Above is a summary of [detailed docs from Django](https://docs.djangoproject.com/en/1.8/ref/csrf/)\r\n","created_at":"2015-11-23T06:55:33Z","updated_at":"2015-11-23T09:06:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a78ddaf4f0ebe1e03152774f131367499f83f23f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/9227/commits","review_comments_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/9227/comments","review_comment_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/9227/comments","statuses_url":"https://api.github.com/repos/dimagi/commcare-hq/statuses/7a5c3e50069bb1d98c7619f83b6a897f6ff5bb15","head":{"label":"dimagi:csrf","ref":"csrf","sha":"7a5c3e50069bb1d98c7619f83b6a897f6ff5bb15","user":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"repo":{"id":247278,"name":"commcare-hq","full_name":"dimagi/commcare-hq","owner":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dimagi/commcare-hq","description":"A server-side tool to help manage community health workers, written in Django","fork":false,"url":"https://api.github.com/repos/dimagi/commcare-hq","forks_url":"https://api.github.com/repos/dimagi/commcare-hq/forks","keys_url":"https://api.github.com/repos/dimagi/commcare-hq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimagi/commcare-hq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimagi/commcare-hq/teams","hooks_url":"https://api.github.com/repos/dimagi/commcare-hq/hooks","issue_events_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/events{/number}","events_url":"https://api.github.com/repos/dimagi/commcare-hq/events","assignees_url":"https://api.github.com/repos/dimagi/commcare-hq/assignees{/user}","branches_url":"https://api.github.com/repos/dimagi/commcare-hq/branches{/branch}","tags_url":"https://api.github.com/repos/dimagi/commcare-hq/tags","blobs_url":"https://api.github.com/repos/dimagi/commcare-hq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimagi/commcare-hq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimagi/commcare-hq/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimagi/commcare-hq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimagi/commcare-hq/statuses/{sha}","languages_url":"https://api.github.com/repos/dimagi/commcare-hq/languages","stargazers_url":"https://api.github.com/repos/dimagi/commcare-hq/stargazers","contributors_url":"https://api.github.com/repos/dimagi/commcare-hq/contributors","subscribers_url":"https://api.github.com/repos/dimagi/commcare-hq/subscribers","subscription_url":"https://api.github.com/repos/dimagi/commcare-hq/subscription","commits_url":"https://api.github.com/repos/dimagi/commcare-hq/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimagi/commcare-hq/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimagi/commcare-hq/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimagi/commcare-hq/contents/{+path}","compare_url":"https://api.github.com/repos/dimagi/commcare-hq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimagi/commcare-hq/merges","archive_url":"https://api.github.com/repos/dimagi/commcare-hq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimagi/commcare-hq/downloads","issues_url":"https://api.github.com/repos/dimagi/commcare-hq/issues{/number}","pulls_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls{/number}","milestones_url":"https://api.github.com/repos/dimagi/commcare-hq/milestones{/number}","notifications_url":"https://api.github.com/repos/dimagi/commcare-hq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimagi/commcare-hq/labels{/name}","releases_url":"https://api.github.com/repos/dimagi/commcare-hq/releases{/id}","created_at":"2009-07-09T17:00:07Z","updated_at":"2015-11-05T13:41:38Z","pushed_at":"2015-11-23T08:50:20Z","git_url":"git://github.com/dimagi/commcare-hq.git","ssh_url":"git@github.com:dimagi/commcare-hq.git","clone_url":"https://github.com/dimagi/commcare-hq.git","svn_url":"https://github.com/dimagi/commcare-hq","homepage":"http://www.commcarehq.org","size":234249,"stargazers_count":54,"watchers_count":54,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":63,"mirror_url":null,"open_issues_count":61,"forks":63,"open_issues":61,"watchers":54,"default_branch":"master"}},"base":{"label":"dimagi:master","ref":"master","sha":"9a57dc941ee57887c3b05ae1ceba0ebf30003b15","user":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"repo":{"id":247278,"name":"commcare-hq","full_name":"dimagi/commcare-hq","owner":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dimagi/commcare-hq","description":"A server-side tool to help manage community health workers, written in Django","fork":false,"url":"https://api.github.com/repos/dimagi/commcare-hq","forks_url":"https://api.github.com/repos/dimagi/commcare-hq/forks","keys_url":"https://api.github.com/repos/dimagi/commcare-hq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimagi/commcare-hq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimagi/commcare-hq/teams","hooks_url":"https://api.github.com/repos/dimagi/commcare-hq/hooks","issue_events_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/events{/number}","events_url":"https://api.github.com/repos/dimagi/commcare-hq/events","assignees_url":"https://api.github.com/repos/dimagi/commcare-hq/assignees{/user}","branches_url":"https://api.github.com/repos/dimagi/commcare-hq/branches{/branch}","tags_url":"https://api.github.com/repos/dimagi/commcare-hq/tags","blobs_url":"https://api.github.com/repos/dimagi/commcare-hq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimagi/commcare-hq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimagi/commcare-hq/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimagi/commcare-hq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimagi/commcare-hq/statuses/{sha}","languages_url":"https://api.github.com/repos/dimagi/commcare-hq/languages","stargazers_url":"https://api.github.com/repos/dimagi/commcare-hq/stargazers","contributors_url":"https://api.github.com/repos/dimagi/commcare-hq/contributors","subscribers_url":"https://api.github.com/repos/dimagi/commcare-hq/subscribers","subscription_url":"https://api.github.com/repos/dimagi/commcare-hq/subscription","commits_url":"https://api.github.com/repos/dimagi/commcare-hq/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimagi/commcare-hq/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimagi/commcare-hq/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimagi/commcare-hq/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimagi/commcare-hq/contents/{+path}","compare_url":"https://api.github.com/repos/dimagi/commcare-hq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimagi/commcare-hq/merges","archive_url":"https://api.github.com/repos/dimagi/commcare-hq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimagi/commcare-hq/downloads","issues_url":"https://api.github.com/repos/dimagi/commcare-hq/issues{/number}","pulls_url":"https://api.github.com/repos/dimagi/commcare-hq/pulls{/number}","milestones_url":"https://api.github.com/repos/dimagi/commcare-hq/milestones{/number}","notifications_url":"https://api.github.com/repos/dimagi/commcare-hq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimagi/commcare-hq/labels{/name}","releases_url":"https://api.github.com/repos/dimagi/commcare-hq/releases{/id}","created_at":"2009-07-09T17:00:07Z","updated_at":"2015-11-05T13:41:38Z","pushed_at":"2015-11-23T08:50:20Z","git_url":"git://github.com/dimagi/commcare-hq.git","ssh_url":"git@github.com:dimagi/commcare-hq.git","clone_url":"https://github.com/dimagi/commcare-hq.git","svn_url":"https://github.com/dimagi/commcare-hq","homepage":"http://www.commcarehq.org","size":234249,"stargazers_count":54,"watchers_count":54,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":63,"mirror_url":null,"open_issues_count":61,"forks":63,"open_issues":61,"watchers":54,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/9227"},"html":{"href":"https://github.com/dimagi/commcare-hq/pull/9227"},"issue":{"href":"https://api.github.com/repos/dimagi/commcare-hq/issues/9227"},"comments":{"href":"https://api.github.com/repos/dimagi/commcare-hq/issues/9227/comments"},"review_comments":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/9227/comments"},"review_comment":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dimagi/commcare-hq/pulls/9227/commits"},"statuses":{"href":"https://api.github.com/repos/dimagi/commcare-hq/statuses/7a5c3e50069bb1d98c7619f83b6a897f6ff5bb15"}}}}