Skip to content

Commit 3c2de46

Browse files
authored
Merge pull request #3277 from kwizer15/fix/cors-headers
fix: remove Access-Control-Allow-Credentials with Allow-Origin: *
2 parents 2c37d93 + 0e62720 commit 3c2de46

3 files changed

Lines changed: 61 additions & 2 deletions

File tree

.htaccess

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Options -Indexes -ExecCGI -FollowSymLinks
44

55
<IfModule mod_headers.c>
66
Header set Access-Control-Allow-Origin "*"
7-
Header set Access-Control-Allow-Credentials true
87
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
98
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
109
ServerSignature Off

install/nginx_default

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ server {
7171
fastcgi_read_timeout 300;
7272
if ($request_method = 'GET') {
7373
add_header 'Access-Control-Allow-Origin' '*';
74-
add_header 'Access-Control-Allow-Credentials' 'true';
7574
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
7675
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
7776
}

tests/corsHeadersTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/* This file is part of Jeedom.
4+
*
5+
* Jeedom is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* Jeedom is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with Jeedom. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
use PHPUnit\Framework\TestCase;
20+
21+
/**
22+
* Regression test: `Access-Control-Allow-Credentials: true` combined with
23+
* `Access-Control-Allow-Origin: *` is rejected by all modern browsers, so the
24+
* credentials directive is dead code that misleads reviewers about the
25+
* intended cross-origin policy. It must not reappear in the shipped config.
26+
*/
27+
class corsHeadersTest extends TestCase {
28+
29+
public function testHtaccessHasNoAllowCredentials() {
30+
$path = __DIR__ . '/../.htaccess';
31+
$this->assertFileExists($path);
32+
$content = file_get_contents($path);
33+
$this->assertDoesNotMatchRegularExpression(
34+
'/Access-Control-Allow-Credentials/i',
35+
$content,
36+
'.htaccess must not emit Access-Control-Allow-Credentials with Allow-Origin: *'
37+
);
38+
}
39+
40+
public function testNginxDefaultHasNoAllowCredentials() {
41+
$path = __DIR__ . '/../install/nginx_default';
42+
$this->assertFileExists($path);
43+
$content = file_get_contents($path);
44+
$this->assertDoesNotMatchRegularExpression(
45+
'/Access-Control-Allow-Credentials/i',
46+
$content,
47+
'nginx_default must not emit Access-Control-Allow-Credentials with Allow-Origin: *'
48+
);
49+
}
50+
51+
public function testJeeApiHasNoAllowCredentials() {
52+
$path = __DIR__ . '/../core/api/jeeApi.php';
53+
$this->assertFileExists($path);
54+
$content = file_get_contents($path);
55+
$this->assertDoesNotMatchRegularExpression(
56+
'/Access-Control-Allow-Credentials/i',
57+
$content,
58+
'jeeApi.php must not emit Access-Control-Allow-Credentials with Allow-Origin: *'
59+
);
60+
}
61+
}

0 commit comments

Comments
 (0)