Skip to content

Commit 6dbd887

Browse files
pointhiAndyScherzinger
authored andcommitted
Fix #41210 to allow non Same-Site Cookies set on first request
Signed-off-by: Thomas Pointhuber <thomas.pointhuber@gmx.at>
1 parent 4c4e414 commit 6dbd887

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

lib/base.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ private static function performSameSiteCookieProtection(\OCP\IConfig $config): v
504504
return;
505505
}
506506

507-
if (count($_COOKIE) > 0) {
507+
if (count($_COOKIE) > 0 && (isset($_COOKIE['nc_sameSiteCookielax']) || isset($_COOKIE['nc_sameSiteCookiestrict']))) {
508508
$requestUri = $request->getScriptName();
509509
$processingScript = explode('/', $requestUri);
510510
$processingScript = $processingScript[count($processingScript) - 1];

tests/lib/AppFramework/Http/RequestTest.php

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,6 +1850,87 @@ public function testPassesCSRFCheckWithHeaderAndWithoutCookies() {
18501850
$this->assertTrue($request->passesCSRFCheck());
18511851
}
18521852

1853+
public function testPassesCSRFCheckWithGetAndWithoutCSRFCookies() {
1854+
/** @var Request $request */
1855+
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
1856+
->setMethods(['getScriptName'])
1857+
->setConstructorArgs([
1858+
[
1859+
'get' => [
1860+
'requesttoken' => 'AAAHGxsTCTc3BgMQESAcNR0OAR0=:MyTotalSecretShareds',
1861+
],
1862+
'cookies' => [
1863+
'some_already_set_cookie' => 'true',
1864+
],
1865+
],
1866+
$this->requestId,
1867+
$this->config,
1868+
$this->csrfTokenManager,
1869+
$this->stream
1870+
])
1871+
->getMock();
1872+
$this->csrfTokenManager
1873+
->expects($this->once())
1874+
->method('isTokenValid')
1875+
->willReturn(true);
1876+
1877+
$this->assertTrue($request->passesCSRFCheck());
1878+
}
1879+
1880+
public function testPassesCSRFCheckWithPostAndWithoutCSRFCookies() {
1881+
/** @var Request $request */
1882+
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
1883+
->setMethods(['getScriptName'])
1884+
->setConstructorArgs([
1885+
[
1886+
'post' => [
1887+
'requesttoken' => 'AAAHGxsTCTc3BgMQESAcNR0OAR0=:MyTotalSecretShareds',
1888+
],
1889+
'cookies' => [
1890+
'some_already_set_cookie' => 'true',
1891+
],
1892+
],
1893+
$this->requestId,
1894+
$this->config,
1895+
$this->csrfTokenManager,
1896+
$this->stream
1897+
])
1898+
->getMock();
1899+
$this->csrfTokenManager
1900+
->expects($this->once())
1901+
->method('isTokenValid')
1902+
->willReturn(true);
1903+
1904+
$this->assertTrue($request->passesCSRFCheck());
1905+
}
1906+
1907+
public function testPassesCSRFCheckWithHeaderAndWithoutCSRFCookies() {
1908+
/** @var Request $request */
1909+
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')
1910+
->setMethods(['getScriptName'])
1911+
->setConstructorArgs([
1912+
[
1913+
'server' => [
1914+
'HTTP_REQUESTTOKEN' => 'AAAHGxsTCTc3BgMQESAcNR0OAR0=:MyTotalSecretShareds',
1915+
],
1916+
'cookies' => [
1917+
'some_already_set_cookie' => 'true',
1918+
],
1919+
],
1920+
$this->requestId,
1921+
$this->config,
1922+
$this->csrfTokenManager,
1923+
$this->stream
1924+
])
1925+
->getMock();
1926+
$this->csrfTokenManager
1927+
->expects($this->once())
1928+
->method('isTokenValid')
1929+
->willReturn(true);
1930+
1931+
$this->assertTrue($request->passesCSRFCheck());
1932+
}
1933+
18531934
public function testFailsCSRFCheckWithHeaderAndNotAllChecksPassing() {
18541935
/** @var Request $request */
18551936
$request = $this->getMockBuilder('\OC\AppFramework\Http\Request')

0 commit comments

Comments
 (0)