Skip to content

Improve login flow v2 approval pages and warn about IP mismatch - #66223

Open
fput wants to merge 4 commits into
nextcloud:masterfrom
fput:improve-login-flow
Open

fput wants to merge 4 commits into
nextcloud:masterfrom
fput:improve-login-flow

Conversation

@fput

@fput fput commented Nov 3, 2026 •

Copy link
Copy Markdown

Summary

After analyzing phishing risks in the current login flow v2, I came up with the following improvements to mitigate the phishing risks somewhat, particularly from remote attackers (i.e., attackers with different IPs):

  • Show the requesting app’s IP address and display it alongside the browser IP, request age, and user agent. Indicate that the user agent is self-reported. Add help popups for further information, but don't overload the user by default.
  • Show a prominent warning when IPs differ and require an additional review step.
  • Redesign the browser approval screens with clearer context, an account card with avatar, and explicit Decline and Grant actions.
  • Previously there were two screens: One prompting the user to login, then a second after login prompting the user to confirm. They were redundant, so I simplified the first screen. If the user is already logged in, we now go straight to the grant screen.
  • Make declining invalidate the pending request.

These changes preserve existing client APIs and legacy login flows.

Before

before1

And then after logging in:

before2

After

after1

Clicking "Continue" will show the login form. After logging in:

after2

If the IP addresses of the client and the browser differ, a warning is shown:

after3

Steps to test my changes:

# Repository root, using Node 24
npm ci
npm --prefix build/frontend run build

# Inside the PHP environment, as the web-server user
php occ migrations:migrate core

In a nextcloud client (I tested with the macOS desktop client) try to add a new account and insert the URL of your instance (e.g. http://nextcloud.local). Then observe the redesigned login flow.

To test what happens when the IP address does not match, you can do something like this to fake the IP (using the dev docker setup):

# create a login request
curl -sS -X POST \
  -A 'IP mismatch preview' \
  http://nextcloud.local/index.php/login/v2 |
  python3 -c 'import json,sys; print(json.load(sys.stdin)["login"])'

# update the IP of the client in the DB so that there is a mismatch
docker exec --user www-data master-nextcloud-1 php -r '
require_once "lib/base.php";
$query = \OCP\Server::get(\OCP\IDBConnection::class)->getQueryBuilder();
$query->update("login_flow_v2")
    ->set("client_ip", $query->createNamedParameter("203.0.113.42"))
    ->where($query->expr()->eq("client_name", $query->createNamedParameter("IP mismatch preview")))
    ->andWhere($query->expr()->isNull("app_password"))
    ->executeStatement();'

# now go to the URL the first command returned and observe the warning in the login flow

Limitations

The IP comparison requires correctly configured proxies/forwarding in the nextcloud server to prevent IP spoofing.

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI: I used Codex for implementing and iterating over the changes after I came up with the redesign ideas.

fput added 2 commits November 3, 2026 19:18
This is a prerequisite to compare the browser's IP with the client's IP
to detect phishing attacks.

Signed-off-by: Florentin Putz <dev@fputz.net>
Assisted-by: Codex:gpt-6.1-sol
Previously, we only supported accepting requests. But users might want
to reject requests.

Make declining invalidate the pending request. Prevent competing
approvals or cancellations from overwriting the result.

Signed-off-by: Florentin Putz <dev@fputz.net>
Assisted-by: Codex:gpt-6.1-sol
@fput
fput marked this pull request as ready for review November 3, 2026 19:18
@fput
fput requested review from a team as code owners November 3, 2026 19:18
@fput
fput requested review from Altahrim, icewind1991, kristian-zendato, pringelmann, salmart-dev, skjnldsv and sorbaugh and removed request for a team November 3, 2026 19:18
@susnux susnux added this to the Nextcloud 36 milestone Nov 3, 2026
@susnux susnux added enhancement design Design, UI, UX, etc. 3. to review Waiting for reviews feature: authentication labels Nov 3, 2026
@fput
fput force-pushed the improve-login-flow branch 2 times, most recently from 1d3c720 to 6307e71 Compare November 4, 2026 10:59
@fput

fput commented Nov 4, 2026

Copy link
Copy Markdown
Author

@susnux I noticed that there were two lint errors due to unused imports. I have fixed them, hopefully the checks pass now!

@susnux
susnux requested a review from a team November 5, 2026 12:41

@susnux susnux left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks really great overall, but would need some adjustments to the PlayWright tests.

@fput
fput force-pushed the improve-login-flow branch from 6307e71 to 740dfc1 Compare November 5, 2026 18:57
@fput

fput commented Nov 5, 2026

Copy link
Copy Markdown
Author

Looks really great overall, but would need some adjustments to the PlayWright tests.

I have now fixed the PlayWright tests that previously failed, so hopefully it should work now.

@susnux
susnux requested review from CarlSchwan and removed request for sorbaugh November 5, 2026 19:59

@skjnldsv skjnldsv 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.

Some comments, overall really great!!

$browserIp = $this->request->getRemoteAddress();
$sameIp = null;
if ($clientIp !== null && Address::isValid($clientIp) && Address::isValid($browserIp)) {
$sameIp = (string)new Address($clientIp) === (string)new Address($browserIp);

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.

I'm a bit worried about IPv6 here. With privacy addresses the same machine can show up with a different IP per connection, and with dual stack the app can come in over v6 while the browser uses v4. Both would show the warning on a normal login. Maybe compare the /64 for v6, and leave sameIp as null when one is v4 and the other v6?

@fput fput Nov 6, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good points!

Comparing the IPv6 /64 is a great idea. The downside is that an attacker on the same shared subnet would not trigger a warning. But that's already the case anyways for IPv4 behind NAT, so we don't loose much.

For the case when one IP is v4 and the other is v6 I'm less sure, hmmm... An attacker could easily disable the warning then by using whatever IP version the user is not using on the phishing website. Even without that info, there's a substantial chance the attacker can disable the warning by guessing the correct IP version.

There is a trade-off here: Do we want fewer false alarms for dual-stack, but then also less warnings for actual attacks? @susnux @skjnldsv

Comment thread core/Db/LoginFlowV2Mapper.php Resolved
}

#[PublicPage]
#[UseSession]

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.

Why does this one need UseSession now? It keeps the session locked for the whole request.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

There might be a race condition when not locking the session, as state token lookup/validation could be separated from the token cleanup.

Would you recommend removing UseSession here? Or maybe close the session early in the function after line 237?

$this->session->remove(self::TOKEN_NAME);
$this->session->remove(self::STATE_NAME);
$this->session->close();

fput added 2 commits November 6, 2026 18:02
Redesign the browser approval screens with clearer context, an account
card with avatar, and explicit Decline and Grant actions.

Show the requesting app’s IP address and display it alongside the
browser IP, request age, and user agent. Indicate that the user agent
is self-reported. Add popups for further information, but don't overload
the user by default.

Previously there were two screens: One prompting the user to login,
then a second after login prompting the user to confirm. They were
redundant, so this simplifies the first screen. If the user is already
logged in, we now go straight to the grant screen.

Add a revocation-settings link after connection.

Signed-off-by: Florentin Putz <dev@fputz.net>
Assisted-by: Codex:gpt-6.1-sol
When the IP addresses of the requesting client and the current browser
session differ, show a prominent warning and require an additional
review step.

Signed-off-by: Florentin Putz <dev@fputz.net>
Assisted-by: Codex:gpt-6.1-sol
@fput
fput force-pushed the improve-login-flow branch from 740dfc1 to c41ab65 Compare November 7, 2026 01:02
@github-actions

Copy link
Copy Markdown
Contributor

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

This branch has not been deployed

No deployments
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.

Make login flow v2 more phishing proof

3 participants