Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Authorization header can be an empty string #46184

Merged
merged 1 commit into from
Jul 1, 2024

Conversation

juliushaertl
Copy link
Member

@juliushaertl juliushaertl commented Jun 27, 2024

On our instance we've noticed that macOS dav clients are actually sending tons of requests. When looking at the network dump of what is happening it turned out that every request is sent twice, one time with a cookie which fails with a 401 and once with basic auth then.

I've been stepping through such a request now and it turned out that our check to see if a Authorization header is sent along was not working as it is always filled with an empty string from $_SERVER['HTTP_AUTHORIZATION']

Turns out that once fixing this check, macOS is able to properly reuse the cookies it sends along.

Some screenshots from debugging to easier follow the code that leads to this Screenshot 2024-06-27 at 20 25 14 Screenshot 2024-06-27 at 20 25 41 Screenshot 2024-06-27 at 20 27 02

@@ -185,7 +185,7 @@
//Fix for broken webdav clients
($this->userSession->isLoggedIn() && is_null($this->session->get(self::DAV_AUTHENTICATED))) ||
//Well behaved clients that only send the cookie are allowed
($this->userSession->isLoggedIn() && $this->session->get(self::DAV_AUTHENTICATED) === $this->userSession->getUser()->getUID() && $request->getHeader('Authorization') === null) ||
($this->userSession->isLoggedIn() && $this->session->get(self::DAV_AUTHENTICATED) === $this->userSession->getUser()->getUID() && empty($request->getHeader('Authorization'))) ||

Check notice

Code scanning / Psalm

PossiblyNullReference Note

Cannot call method getUID on possibly null value
@@ -185,7 +185,7 @@
//Fix for broken webdav clients
($this->userSession->isLoggedIn() && is_null($this->session->get(self::DAV_AUTHENTICATED))) ||
//Well behaved clients that only send the cookie are allowed
($this->userSession->isLoggedIn() && $this->session->get(self::DAV_AUTHENTICATED) === $this->userSession->getUser()->getUID() && $request->getHeader('Authorization') === null) ||
($this->userSession->isLoggedIn() && $this->session->get(self::DAV_AUTHENTICATED) === $this->userSession->getUser()->getUID() && empty($request->getHeader('Authorization'))) ||

Check notice

Code scanning / Psalm

RiskyTruthyFalsyComparison Note

Operand of type null|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead.
@juliushaertl juliushaertl requested review from nickvergessen, ChristophWurst, a team, ArtificialOwl, yemkareems and sorbaugh and removed request for a team June 27, 2024 18:31
Copy link
Member

@nickvergessen nickvergessen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈

@nickvergessen nickvergessen added this to the Nextcloud 30 milestone Jun 28, 2024
Signed-off-by: Julius Härtl <jus@bitgrid.net>
@juliushaertl juliushaertl merged commit 3b75c5b into master Jul 1, 2024
165 checks passed
@juliushaertl juliushaertl deleted the fix/dav-auth-check branch July 1, 2024 09:43
@juliushaertl
Copy link
Member Author

/backport to stable29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants