Skip to content

fix(session): Avoid useless authtoken DB queries for anonymous requests - #42607

Merged
ChristophWurst merged 1 commit into
masterfrom
tokenAnonReq
Jan 17, 2024
Merged

fix(session): Avoid useless authtoken DB queries for anonymous requests#42607
ChristophWurst merged 1 commit into
masterfrom
tokenAnonReq

Conversation

@solracsf

@solracsfsolracsf commented Jan 6, 2024

Copy link
Copy Markdown
Member

Checklist

@solracsfsolracsf added the 3. to review Waiting for reviews label Jan 6, 2024
@solracsfsolracsf added this to the Nextcloud 29 milestone Jan 6, 2024
Comment threadlib/private/User/Session.php Outdated
$instanceId = $this->config->getSystemValueString('instanceid');
if (is_null($request->getCookie($instanceId))) {
return false;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Without looking in depth, just from the following code lines I think that this could have unexpected side effects when just authenticating with an app password which is also a token but not necessarily has cookies if clients send it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Adjusted so that the token lookup by session id only happens if there is neither an Authrorization header nor session cookie

@ChristophWurstChristophWurst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Bildschirmfoto vom 2024-01-16 19-19-41

👍 as expected

tested with 100 samples of GET /login

@ChristophWurst

Copy link
Copy Markdown
Member

/backport to stable28

@ChristophWurst

Copy link
Copy Markdown
Member

/backport to stable27

@ChristophWurst

Copy link
Copy Markdown
Member

/backport to stable26

Comment threadlib/private/User/Session.php Outdated
$token = substr($authHeader, 7);
} else {
// No auth header, let's try session id
} else if ($request->getCookie($this->config->getSystemValueString('instanceid')) !== null) {

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Suggested change
} elseif ($request->getCookie($this->config->getSystemValueString('instanceid')) !== null) {
} elseif ($request->getCookie($this->config->getSystemValueString('instanceid')) !== null) {

…ous request
Co-Authored-By: Christoph Wurst <christoph@winzerhof-wurst.at>
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Two useless authtoken database queries for every anonymous request

3 participants

@solracsf@ChristophWurst@juliusknorr