{"action":"created","comment":{"url":"https://api.github.com/repos/restify/node-restify/pulls/comments/48204711","id":48204711,"diff_hunk":"@@ -35,16 +35,25 @@ var AC_EXPOSE_HEADERS = 'Access-Control-Expose-Headers';\n \n ///--- Internal Functions\n \n+// turn a string defining an allowed domain into a regex\n+function toRegExp(str) {\n+    if (str instanceof RegExp) {\n+        return str;\n+    }\n+    var regexStr = str\n+      // escape all the special characters, except *\n+      .replace(/[\\-\\[\\]\\/\\{\\}\\(\\)\\+\\?\\.\\\\\\^\\$\\|]/g, '\\\\$&')\n+      // replace all instances of * with a proper regex wildcard\n+      .replace(/\\*/g, '.*');\n+\n+    return new RegExp('^(https?://)?' + regexStr + '$', 'i');\n+}\n+\n function matchOrigin(req, origins) {\n     var origin = req.headers.origin;\n \n     function belongs(o) {\n-        if (origin === o || o === '*') {\n-            origin = o;\n-            return (true);\n-        }\n-\n-        return (false);\n+        return o.test(origin);","path":"lib/plugins/cors.js","position":28,"original_position":28,"commit_id":"b444b74a7ba4d7c71bd101b442949626b2b4a7a3","original_commit_id":"673a66f803abe2a77b4f35bb4fbf963af84d7293","user":{"login":"DonutEspresso","id":2381315,"avatar_url":"https://avatars.githubusercontent.com/u/2381315?v=3","gravatar_id":"","url":"https://api.github.com/users/DonutEspresso","html_url":"https://github.com/DonutEspresso","followers_url":"https://api.github.com/users/DonutEspresso/followers","following_url":"https://api.github.com/users/DonutEspresso/following{/other_user}","gists_url":"https://api.github.com/users/DonutEspresso/gists{/gist_id}","starred_url":"https://api.github.com/users/DonutEspresso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DonutEspresso/subscriptions","organizations_url":"https://api.github.com/users/DonutEspresso/orgs","repos_url":"https://api.github.com/users/DonutEspresso/repos","events_url":"https://api.github.com/users/DonutEspresso/events{/privacy}","received_events_url":"https://api.github.com/users/DonutEspresso/received_events","type":"User","site_admin":false},"body":"Fair point - I think I'd still prefer the differentiation due to subtle behavior changes that may not be captured in existing tests (plus the additional regex overhead). But I don't feel particularly strongly on this issue. @yunong, thoughts? ","created_at":"2015-12-21T23:20:18Z","updated_at":"2015-12-21T23:20:18Z","html_url":"https://github.com/restify/node-restify/pull/961#discussion_r48204711","pull_request_url":"https://api.github.com/repos/restify/node-restify/pulls/961","_links":{"self":{"href":"https://api.github.com/repos/restify/node-restify/pulls/comments/48204711"},"html":{"href":"https://github.com/restify/node-restify/pull/961#discussion_r48204711"},"pull_request":{"href":"https://api.github.com/repos/restify/node-restify/pulls/961"}}},"pull_request":{"url":"https://api.github.com/repos/restify/node-restify/pulls/961","id":52488758,"html_url":"https://github.com/restify/node-restify/pull/961","diff_url":"https://github.com/restify/node-restify/pull/961.diff","patch_url":"https://github.com/restify/node-restify/pull/961.patch","issue_url":"https://api.github.com/repos/restify/node-restify/issues/961","number":961,"state":"open","locked":false,"title":"CORS partial wildcards and protocol","user":{"login":"StefanoDalpiaz","id":10583213,"avatar_url":"https://avatars.githubusercontent.com/u/10583213?v=3","gravatar_id":"","url":"https://api.github.com/users/StefanoDalpiaz","html_url":"https://github.com/StefanoDalpiaz","followers_url":"https://api.github.com/users/StefanoDalpiaz/followers","following_url":"https://api.github.com/users/StefanoDalpiaz/following{/other_user}","gists_url":"https://api.github.com/users/StefanoDalpiaz/gists{/gist_id}","starred_url":"https://api.github.com/users/StefanoDalpiaz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StefanoDalpiaz/subscriptions","organizations_url":"https://api.github.com/users/StefanoDalpiaz/orgs","repos_url":"https://api.github.com/users/StefanoDalpiaz/repos","events_url":"https://api.github.com/users/StefanoDalpiaz/events{/privacy}","received_events_url":"https://api.github.com/users/StefanoDalpiaz/received_events","type":"User","site_admin":false},"body":"Hi, this PR adds some flexibility to the CORS configuration for allowed origins.\r\n\r\nCurrently, the cors middleware only allows two ways of defining an allowed origin:\r\n* a \"global\" wildcard `*`\r\n* a scheme + domain name string - e.g. `http://foo.bar`\r\n\r\nWith this additional logic, the following definitions are supported:\r\n* a \"partial\" wildcard, useful for whitelisting subdomains - e.g. `http://*.foo.bar`\r\n* a domain name without the protocol, in which case both the http and https versions will be allowed - e.g. `foo.bar` or `*.foo.bar`\r\n* a regular expression, to allow for total control over the format of the allowed domains - e.g. `/foo[0-9]?\\.bar/i`","created_at":"2015-12-03T03:48:46Z","updated_at":"2015-12-21T23:20:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ae8d231b99c7bb88b7706cc7d838e38e09b7e0dc","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/restify/node-restify/pulls/961/commits","review_comments_url":"https://api.github.com/repos/restify/node-restify/pulls/961/comments","review_comment_url":"https://api.github.com/repos/restify/node-restify/pulls/comments{/number}","comments_url":"https://api.github.com/repos/restify/node-restify/issues/961/comments","statuses_url":"https://api.github.com/repos/restify/node-restify/statuses/b444b74a7ba4d7c71bd101b442949626b2b4a7a3","head":{"label":"StefanoDalpiaz:cors-wildcards","ref":"cors-wildcards","sha":"b444b74a7ba4d7c71bd101b442949626b2b4a7a3","user":{"login":"StefanoDalpiaz","id":10583213,"avatar_url":"https://avatars.githubusercontent.com/u/10583213?v=3","gravatar_id":"","url":"https://api.github.com/users/StefanoDalpiaz","html_url":"https://github.com/StefanoDalpiaz","followers_url":"https://api.github.com/users/StefanoDalpiaz/followers","following_url":"https://api.github.com/users/StefanoDalpiaz/following{/other_user}","gists_url":"https://api.github.com/users/StefanoDalpiaz/gists{/gist_id}","starred_url":"https://api.github.com/users/StefanoDalpiaz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StefanoDalpiaz/subscriptions","organizations_url":"https://api.github.com/users/StefanoDalpiaz/orgs","repos_url":"https://api.github.com/users/StefanoDalpiaz/repos","events_url":"https://api.github.com/users/StefanoDalpiaz/events{/privacy}","received_events_url":"https://api.github.com/users/StefanoDalpiaz/received_events","type":"User","site_admin":false},"repo":{"id":47304502,"name":"node-restify","full_name":"StefanoDalpiaz/node-restify","owner":{"login":"StefanoDalpiaz","id":10583213,"avatar_url":"https://avatars.githubusercontent.com/u/10583213?v=3","gravatar_id":"","url":"https://api.github.com/users/StefanoDalpiaz","html_url":"https://github.com/StefanoDalpiaz","followers_url":"https://api.github.com/users/StefanoDalpiaz/followers","following_url":"https://api.github.com/users/StefanoDalpiaz/following{/other_user}","gists_url":"https://api.github.com/users/StefanoDalpiaz/gists{/gist_id}","starred_url":"https://api.github.com/users/StefanoDalpiaz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StefanoDalpiaz/subscriptions","organizations_url":"https://api.github.com/users/StefanoDalpiaz/orgs","repos_url":"https://api.github.com/users/StefanoDalpiaz/repos","events_url":"https://api.github.com/users/StefanoDalpiaz/events{/privacy}","received_events_url":"https://api.github.com/users/StefanoDalpiaz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/StefanoDalpiaz/node-restify","description":"node.js REST framework specifically meant for web service APIs","fork":true,"url":"https://api.github.com/repos/StefanoDalpiaz/node-restify","forks_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/forks","keys_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/keys{/key_id}","collaborators_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/teams","hooks_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/hooks","issue_events_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/issues/events{/number}","events_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/events","assignees_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/assignees{/user}","branches_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/branches{/branch}","tags_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/tags","blobs_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/git/refs{/sha}","trees_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/git/trees{/sha}","statuses_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/statuses/{sha}","languages_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/languages","stargazers_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/stargazers","contributors_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/contributors","subscribers_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/subscribers","subscription_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/subscription","commits_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/commits{/sha}","git_commits_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/git/commits{/sha}","comments_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/comments{/number}","issue_comment_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/issues/comments{/number}","contents_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/contents/{+path}","compare_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/compare/{base}...{head}","merges_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/merges","archive_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/downloads","issues_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/issues{/number}","pulls_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/pulls{/number}","milestones_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/milestones{/number}","notifications_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/labels{/name}","releases_url":"https://api.github.com/repos/StefanoDalpiaz/node-restify/releases{/id}","created_at":"2015-12-03T03:20:16Z","updated_at":"2015-12-03T03:20:18Z","pushed_at":"2015-12-21T03:09:44Z","git_url":"git://github.com/StefanoDalpiaz/node-restify.git","ssh_url":"git@github.com:StefanoDalpiaz/node-restify.git","clone_url":"https://github.com/StefanoDalpiaz/node-restify.git","svn_url":"https://github.com/StefanoDalpiaz/node-restify","homepage":"http://restifyjs.com","size":3177,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"5.x"}},"base":{"label":"restify:master","ref":"master","sha":"feb3eebc83fbc89eb9e7557bf12b14db451509e5","user":{"login":"restify","id":6948699,"avatar_url":"https://avatars.githubusercontent.com/u/6948699?v=3","gravatar_id":"","url":"https://api.github.com/users/restify","html_url":"https://github.com/restify","followers_url":"https://api.github.com/users/restify/followers","following_url":"https://api.github.com/users/restify/following{/other_user}","gists_url":"https://api.github.com/users/restify/gists{/gist_id}","starred_url":"https://api.github.com/users/restify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/restify/subscriptions","organizations_url":"https://api.github.com/users/restify/orgs","repos_url":"https://api.github.com/users/restify/repos","events_url":"https://api.github.com/users/restify/events{/privacy}","received_events_url":"https://api.github.com/users/restify/received_events","type":"Organization","site_admin":false},"repo":{"id":1661758,"name":"node-restify","full_name":"restify/node-restify","owner":{"login":"restify","id":6948699,"avatar_url":"https://avatars.githubusercontent.com/u/6948699?v=3","gravatar_id":"","url":"https://api.github.com/users/restify","html_url":"https://github.com/restify","followers_url":"https://api.github.com/users/restify/followers","following_url":"https://api.github.com/users/restify/following{/other_user}","gists_url":"https://api.github.com/users/restify/gists{/gist_id}","starred_url":"https://api.github.com/users/restify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/restify/subscriptions","organizations_url":"https://api.github.com/users/restify/orgs","repos_url":"https://api.github.com/users/restify/repos","events_url":"https://api.github.com/users/restify/events{/privacy}","received_events_url":"https://api.github.com/users/restify/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/restify/node-restify","description":"node.js REST framework specifically meant for web service APIs","fork":false,"url":"https://api.github.com/repos/restify/node-restify","forks_url":"https://api.github.com/repos/restify/node-restify/forks","keys_url":"https://api.github.com/repos/restify/node-restify/keys{/key_id}","collaborators_url":"https://api.github.com/repos/restify/node-restify/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/restify/node-restify/teams","hooks_url":"https://api.github.com/repos/restify/node-restify/hooks","issue_events_url":"https://api.github.com/repos/restify/node-restify/issues/events{/number}","events_url":"https://api.github.com/repos/restify/node-restify/events","assignees_url":"https://api.github.com/repos/restify/node-restify/assignees{/user}","branches_url":"https://api.github.com/repos/restify/node-restify/branches{/branch}","tags_url":"https://api.github.com/repos/restify/node-restify/tags","blobs_url":"https://api.github.com/repos/restify/node-restify/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/restify/node-restify/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/restify/node-restify/git/refs{/sha}","trees_url":"https://api.github.com/repos/restify/node-restify/git/trees{/sha}","statuses_url":"https://api.github.com/repos/restify/node-restify/statuses/{sha}","languages_url":"https://api.github.com/repos/restify/node-restify/languages","stargazers_url":"https://api.github.com/repos/restify/node-restify/stargazers","contributors_url":"https://api.github.com/repos/restify/node-restify/contributors","subscribers_url":"https://api.github.com/repos/restify/node-restify/subscribers","subscription_url":"https://api.github.com/repos/restify/node-restify/subscription","commits_url":"https://api.github.com/repos/restify/node-restify/commits{/sha}","git_commits_url":"https://api.github.com/repos/restify/node-restify/git/commits{/sha}","comments_url":"https://api.github.com/repos/restify/node-restify/comments{/number}","issue_comment_url":"https://api.github.com/repos/restify/node-restify/issues/comments{/number}","contents_url":"https://api.github.com/repos/restify/node-restify/contents/{+path}","compare_url":"https://api.github.com/repos/restify/node-restify/compare/{base}...{head}","merges_url":"https://api.github.com/repos/restify/node-restify/merges","archive_url":"https://api.github.com/repos/restify/node-restify/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/restify/node-restify/downloads","issues_url":"https://api.github.com/repos/restify/node-restify/issues{/number}","pulls_url":"https://api.github.com/repos/restify/node-restify/pulls{/number}","milestones_url":"https://api.github.com/repos/restify/node-restify/milestones{/number}","notifications_url":"https://api.github.com/repos/restify/node-restify/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/restify/node-restify/labels{/name}","releases_url":"https://api.github.com/repos/restify/node-restify/releases{/id}","created_at":"2011-04-25T21:19:26Z","updated_at":"2015-12-21T19:19:27Z","pushed_at":"2015-12-21T23:09:15Z","git_url":"git://github.com/restify/node-restify.git","ssh_url":"git@github.com:restify/node-restify.git","clone_url":"https://github.com/restify/node-restify.git","svn_url":"https://github.com/restify/node-restify","homepage":"http://restifyjs.com","size":4907,"stargazers_count":4337,"watchers_count":4337,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":520,"mirror_url":null,"open_issues_count":100,"forks":520,"open_issues":100,"watchers":4337,"default_branch":"5.x"}},"_links":{"self":{"href":"https://api.github.com/repos/restify/node-restify/pulls/961"},"html":{"href":"https://github.com/restify/node-restify/pull/961"},"issue":{"href":"https://api.github.com/repos/restify/node-restify/issues/961"},"comments":{"href":"https://api.github.com/repos/restify/node-restify/issues/961/comments"},"review_comments":{"href":"https://api.github.com/repos/restify/node-restify/pulls/961/comments"},"review_comment":{"href":"https://api.github.com/repos/restify/node-restify/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/restify/node-restify/pulls/961/commits"},"statuses":{"href":"https://api.github.com/repos/restify/node-restify/statuses/b444b74a7ba4d7c71bd101b442949626b2b4a7a3"}}}}