{"action":"created","comment":{"url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/pulls/comments/198158827","pull_request_review_id":132037536,"id":198158827,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5ODE1ODgyNw==","diff_hunk":"@@ -0,0 +1,37 @@\n+/**\n+\n+Copyright 2018 New Vector Ltd.\n+\n+Licensed under the Apache License, Version 2.0 (the \"License\");\n+you may not use this file except in compliance with the License.\n+You may obtain a copy of the License at\n+\n+    http://www.apache.org/licenses/LICENSE-2.0\n+\n+Unless required by applicable law or agreed to in writing, software\n+distributed under the License is distributed on an \"AS IS\" BASIS,\n+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+See the License for the specific language governing permissions and\n+limitations under the License.\n+\n+**/\n+\n+const { decryptBody } = require('./decrypt-body.js');\n+\n+function encryptedBodyMiddleware(req, res, next) {\n+    // If a POST body contains `encrypted_body`, decrypt it and pass it as a body\n+    // to the next middleware\n+\n+    if (req.method === 'POST' && req.body && req.body.encrypted_body) {\n+        try {\n+            req.body = decryptBody(req.body.encrypted_body);\n+        } catch (err) {\n+            next(err);\n+            return;\n+        }\n+    }","path":"src/encrypted-body-middleware.js","position":32,"original_position":32,"commit_id":"ef6b12dc3b71c4a10e634e9ad98d5c0893ba7959","original_commit_id":"ef6b12dc3b71c4a10e634e9ad98d5c0893ba7959","user":{"login":"lukebarnard1","id":6750344,"node_id":"MDQ6VXNlcjY3NTAzNDQ=","avatar_url":"https://avatars1.githubusercontent.com/u/6750344?v=4","gravatar_id":"","url":"https://api.github.com/users/lukebarnard1","html_url":"https://github.com/lukebarnard1","followers_url":"https://api.github.com/users/lukebarnard1/followers","following_url":"https://api.github.com/users/lukebarnard1/following{/other_user}","gists_url":"https://api.github.com/users/lukebarnard1/gists{/gist_id}","starred_url":"https://api.github.com/users/lukebarnard1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukebarnard1/subscriptions","organizations_url":"https://api.github.com/users/lukebarnard1/orgs","repos_url":"https://api.github.com/users/lukebarnard1/repos","events_url":"https://api.github.com/users/lukebarnard1/events{/privacy}","received_events_url":"https://api.github.com/users/lukebarnard1/received_events","type":"User","site_admin":false},"body":"It does feel quite bad to have \r\n```js\r\nif (req.method === 'POST' && req.body && req.body.encrypted_body) \r\n   do this specific thing transparently\r\n```\r\n\r\nI don't think it is the done thing necessarily. Would it help at all if there was sufficient logging to make the manoeuvre less transparent (for the server-side debug)?","created_at":"2018-06-26T14:10:24Z","updated_at":"2018-06-26T14:10:24Z","html_url":"https://github.com/matrix-org/matrix-content-scanner/pull/17#discussion_r198158827","pull_request_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/pulls/17","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/matrix-org/matrix-content-scanner/pulls/comments/198158827"},"html":{"href":"https://github.com/matrix-org/matrix-content-scanner/pull/17#discussion_r198158827"},"pull_request":{"href":"https://api.github.com/repos/matrix-org/matrix-content-scanner/pulls/17"}},"in_reply_to_id":198139102},"pull_request":{"url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/pulls/17","id":197412354,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk3NDEyMzU0","html_url":"https://github.com/matrix-org/matrix-content-scanner/pull/17","diff_url":"https://github.com/matrix-org/matrix-content-scanner/pull/17.diff","patch_url":"https://github.com/matrix-org/matrix-content-scanner/pull/17.patch","issue_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/issues/17","number":17,"state":"open","locked":false,"title":"Implement middleware to decipher encrypted POST requests","user":{"login":"lukebarnard1","id":6750344,"node_id":"MDQ6VXNlcjY3NTAzNDQ=","avatar_url":"https://avatars1.githubusercontent.com/u/6750344?v=4","gravatar_id":"","url":"https://api.github.com/users/lukebarnard1","html_url":"https://github.com/lukebarnard1","followers_url":"https://api.github.com/users/lukebarnard1/followers","following_url":"https://api.github.com/users/lukebarnard1/following{/other_user}","gists_url":"https://api.github.com/users/lukebarnard1/gists{/gist_id}","starred_url":"https://api.github.com/users/lukebarnard1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukebarnard1/subscriptions","organizations_url":"https://api.github.com/users/lukebarnard1/orgs","repos_url":"https://api.github.com/users/lukebarnard1/repos","events_url":"https://api.github.com/users/lukebarnard1/events{/privacy}","received_events_url":"https://api.github.com/users/lukebarnard1/received_events","type":"User","site_admin":false},"body":"Add a generic middleware for POST endpoints that allows them to\r\naccept requests that contain enciphered JSON strings.\r\n\r\nThe request body has the following structure:\r\n\r\n```json\r\n{\r\n    \"ephemeral\": \"[base64-encoded ephemeral public key]\",\r\n    \"mac\": \"[base64-encodeed MAC]\",\r\n    \"ciphertext\": \"[base64-encoded ciphertext of the JSON body]\"\r\n}\r\n```\r\n\r\nThe above can be calculated with matrix-olm `PkEncryption`. The\r\npublic key of the server is required to do this and can be found\r\nby doing a GET request to the `.../media_proxy/unstable/public_key`\r\nendpoint.","created_at":"2018-06-26T12:55:14Z","updated_at":"2018-06-26T14:10:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"84a9a1d3b4a0c6d23f7c4bd052c9f5ef75d619a5","assignee":{"login":"lukebarnard1","id":6750344,"node_id":"MDQ6VXNlcjY3NTAzNDQ=","avatar_url":"https://avatars1.githubusercontent.com/u/6750344?v=4","gravatar_id":"","url":"https://api.github.com/users/lukebarnard1","html_url":"https://github.com/lukebarnard1","followers_url":"https://api.github.com/users/lukebarnard1/followers","following_url":"https://api.github.com/users/lukebarnard1/following{/other_user}","gists_url":"https://api.github.com/users/lukebarnard1/gists{/gist_id}","starred_url":"https://api.github.com/users/lukebarnard1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukebarnard1/subscriptions","organizations_url":"https://api.github.com/users/lukebarnard1/orgs","repos_url":"https://api.github.com/users/lukebarnard1/repos","events_url":"https://api.github.com/users/lukebarnard1/events{/privacy}","received_events_url":"https://api.github.com/users/lukebarnard1/received_events","type":"User","site_admin":false},"assignees":[{"login":"lukebarnard1","id":6750344,"node_id":"MDQ6VXNlcjY3NTAzNDQ=","avatar_url":"https://avatars1.githubusercontent.com/u/6750344?v=4","gravatar_id":"","url":"https://api.github.com/users/lukebarnard1","html_url":"https://github.com/lukebarnard1","followers_url":"https://api.github.com/users/lukebarnard1/followers","following_url":"https://api.github.com/users/lukebarnard1/following{/other_user}","gists_url":"https://api.github.com/users/lukebarnard1/gists{/gist_id}","starred_url":"https://api.github.com/users/lukebarnard1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukebarnard1/subscriptions","organizations_url":"https://api.github.com/users/lukebarnard1/orgs","repos_url":"https://api.github.com/users/lukebarnard1/repos","events_url":"https://api.github.com/users/lukebarnard1/events{/privacy}","received_events_url":"https://api.github.com/users/lukebarnard1/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/pulls/17/commits","review_comments_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/pulls/17/comments","review_comment_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/pulls/comments{/number}","comments_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/issues/17/comments","statuses_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/statuses/ef6b12dc3b71c4a10e634e9ad98d5c0893ba7959","head":{"label":"matrix-org:luke/feature-encrypted-body","ref":"luke/feature-encrypted-body","sha":"ef6b12dc3b71c4a10e634e9ad98d5c0893ba7959","user":{"login":"matrix-org","id":8418310,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg0MTgzMTA=","avatar_url":"https://avatars2.githubusercontent.com/u/8418310?v=4","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"repo":{"id":136185016,"node_id":"MDEwOlJlcG9zaXRvcnkxMzYxODUwMTY=","name":"matrix-content-scanner","full_name":"matrix-org/matrix-content-scanner","owner":{"login":"matrix-org","id":8418310,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg0MTgzMTA=","avatar_url":"https://avatars2.githubusercontent.com/u/8418310?v=4","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/matrix-org/matrix-content-scanner","description":"A web service for scanning media hosted by a Matrix media repository","fork":false,"url":"https://api.github.com/repos/matrix-org/matrix-content-scanner","forks_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/forks","keys_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/keys{/key_id}","collaborators_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/teams","hooks_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/hooks","issue_events_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/issues/events{/number}","events_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/events","assignees_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/assignees{/user}","branches_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/branches{/branch}","tags_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/tags","blobs_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/git/refs{/sha}","trees_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/git/trees{/sha}","statuses_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/statuses/{sha}","languages_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/languages","stargazers_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/stargazers","contributors_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/contributors","subscribers_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/subscribers","subscription_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/subscription","commits_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/commits{/sha}","git_commits_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/git/commits{/sha}","comments_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/comments{/number}","issue_comment_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/issues/comments{/number}","contents_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/contents/{+path}","compare_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/compare/{base}...{head}","merges_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/merges","archive_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/downloads","issues_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/issues{/number}","pulls_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/pulls{/number}","milestones_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/milestones{/number}","notifications_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/labels{/name}","releases_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/releases{/id}","deployments_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/deployments","created_at":"2018-06-05T13:54:00Z","updated_at":"2018-06-21T09:14:34Z","pushed_at":"2018-06-26T12:55:15Z","git_url":"git://github.com/matrix-org/matrix-content-scanner.git","ssh_url":"git@github.com:matrix-org/matrix-content-scanner.git","clone_url":"https://github.com/matrix-org/matrix-content-scanner.git","svn_url":"https://github.com/matrix-org/matrix-content-scanner","homepage":null,"size":111,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"base":{"label":"matrix-org:master","ref":"master","sha":"c8824f8e55a99afe11027defc35757ac0cf74cc9","user":{"login":"matrix-org","id":8418310,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg0MTgzMTA=","avatar_url":"https://avatars2.githubusercontent.com/u/8418310?v=4","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"repo":{"id":136185016,"node_id":"MDEwOlJlcG9zaXRvcnkxMzYxODUwMTY=","name":"matrix-content-scanner","full_name":"matrix-org/matrix-content-scanner","owner":{"login":"matrix-org","id":8418310,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg0MTgzMTA=","avatar_url":"https://avatars2.githubusercontent.com/u/8418310?v=4","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/matrix-org/matrix-content-scanner","description":"A web service for scanning media hosted by a Matrix media repository","fork":false,"url":"https://api.github.com/repos/matrix-org/matrix-content-scanner","forks_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/forks","keys_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/keys{/key_id}","collaborators_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/teams","hooks_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/hooks","issue_events_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/issues/events{/number}","events_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/events","assignees_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/assignees{/user}","branches_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/branches{/branch}","tags_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/tags","blobs_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/git/refs{/sha}","trees_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/git/trees{/sha}","statuses_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/statuses/{sha}","languages_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/languages","stargazers_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/stargazers","contributors_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/contributors","subscribers_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/subscribers","subscription_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/subscription","commits_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/commits{/sha}","git_commits_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/git/commits{/sha}","comments_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/comments{/number}","issue_comment_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/issues/comments{/number}","contents_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/contents/{+path}","compare_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/compare/{base}...{head}","merges_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/merges","archive_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/downloads","issues_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/issues{/number}","pulls_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/pulls{/number}","milestones_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/milestones{/number}","notifications_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/labels{/name}","releases_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/releases{/id}","deployments_url":"https://api.github.com/repos/matrix-org/matrix-content-scanner/deployments","created_at":"2018-06-05T13:54:00Z","updated_at":"2018-06-21T09:14:34Z","pushed_at":"2018-06-26T12:55:15Z","git_url":"git://github.com/matrix-org/matrix-content-scanner.git","ssh_url":"git@github.com:matrix-org/matrix-content-scanner.git","clone_url":"https://github.com/matrix-org/matrix-content-scanner.git","svn_url":"https://github.com/matrix-org/matrix-content-scanner","homepage":null,"size":111,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"other","name":"Other","spdx_id":null,"url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/matrix-org/matrix-content-scanner/pulls/17"},"html":{"href":"https://github.com/matrix-org/matrix-content-scanner/pull/17"},"issue":{"href":"https://api.github.com/repos/matrix-org/matrix-content-scanner/issues/17"},"comments":{"href":"https://api.github.com/repos/matrix-org/matrix-content-scanner/issues/17/comments"},"review_comments":{"href":"https://api.github.com/repos/matrix-org/matrix-content-scanner/pulls/17/comments"},"review_comment":{"href":"https://api.github.com/repos/matrix-org/matrix-content-scanner/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/matrix-org/matrix-content-scanner/pulls/17/commits"},"statuses":{"href":"https://api.github.com/repos/matrix-org/matrix-content-scanner/statuses/ef6b12dc3b71c4a10e634e9ad98d5c0893ba7959"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"lukebarnard1"}}