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(session): Avoid useless authtoken DB queries for anonymous requests #42607

Merged
merged 1 commit into from
Jan 17, 2024

Conversation

solracsf
Copy link
Member

@solracsf solracsf commented Jan 6, 2024

Checklist

@solracsf solracsf added the 3. to review Waiting for reviews label Jan 6, 2024
@solracsf solracsf added this to the Nextcloud 29 milestone Jan 6, 2024
$instanceId = $this->config->getSystemValueString('instanceid');
if (is_null($request->getCookie($instanceId))) {
return false;
}
Copy link
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
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

Copy link
Member

@ChristophWurst ChristophWurst left a comment

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
Member

/backport to stable28

@ChristophWurst
Copy link
Member

/backport to stable27

@ChristophWurst
Copy link
Member

/backport to stable26

@@ -842,13 +842,16 @@ public function tryTokenLogin(IRequest $request) {
$authHeader = $request->getHeader('Authorization');
if (str_starts_with($authHeader, 'Bearer ')) {
$token = substr($authHeader, 7);
} else {
// No auth header, let's try session id
} else if ($request->getCookie($this->config->getSystemValueString('instanceid')) !== null) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
} else if ($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 free to 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