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

login: Prevent multiple logins in a single browser session #20860

Merged
merged 2 commits into from
Aug 20, 2024

Conversation

mvollmer
Copy link
Member

@mvollmer mvollmer commented Aug 9, 2024

unless allowed by cockpit.conf.

If the login page is loaded and a valid session cookie is already available, then we are about to log into a second host from the same browser session, and both logins will have access to each others cookies. This should only be allowed when AllowMultiHost is true. If it is not true, the login page immediately redirects to the session for the existing cookie.

Information about session cookies is not available to login.js, so cockpit-ws helps out by exposing which ones are present, without exposing the cookies themselves.

  • tests
  • coverage

@mvollmer
Copy link
Member Author

mvollmer commented Aug 9, 2024

This is the first half of #20834. I think we should get it in, before we figure out the warning texts.

@mvollmer
Copy link
Member Author

mvollmer commented Aug 9, 2024

Nice, TestEmbed.testBasic got broken, so we do test this!

@mvollmer mvollmer force-pushed the login-no-multihost branch 2 times, most recently from 6e0d509 to 38a681e Compare August 13, 2024 07:23
Changing the Shell= setting back without restarting cockpit has no
effect.
@mvollmer
Copy link
Member Author

Nicely testing this requires Browser tab support in testlib.py. Let's not block on that. The check-embed test covers this a bit, fortunately.

unless allowed by cockpit.conf.

If the login page is loaded and a valid session cookie is already
available, then we are about to log into a second host from the same
browser session, and both logins will have access to each others
cookies. This should only be allowed when AllowMultiHost is true. If
it is not true, the login page immediately redirects to the session
for the existing cookie.

Information about session cookies is not available to login.js, so
cockpit-ws helps out by exposing which ones are present, without
exposing the cookies themselves.
// from two machines into the same browser origin. This needs
// to be allowed explicitly via a configuration setting.

const logged_into = environment.logged_into || [];
Copy link
Contributor

Choose a reason for hiding this comment

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

This added line is not executed by any test.

if (cur_machine === ".") {
login_reload("/");
} else {
login_reload("/=" + cur_machine);
Copy link
Contributor

Choose a reason for hiding this comment

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

This added line is not executed by any test.

@mvollmer mvollmer marked this pull request as ready for review August 14, 2024 09:10
@mvollmer mvollmer added the release-blocker Targetted for next release label Aug 19, 2024
Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

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

Thanks! This wasn't on my radar (no review request). This by and large looks right, and it would indeed be a really nice fix for tomorrow's release. I found a few style issues, but they are not critical and could become follow-ups. Are you otherwise happy with this?


if (cookie_value)
{
decoded = base64_decode_string (cookie_value);
Copy link
Member

Choose a reason for hiding this comment

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

You can use g_autofree here, drop the declaration in line 1248 and the g_free below.

update: Oh, this is moved code. OK to keep if you prefer not to touch it.

// to be allowed explicitly via a configuration setting.

const logged_into = environment.logged_into || [];
const cur_machine = logged_into.length > 0 ? logged_into[0] : null;
Copy link
Member

Choose a reason for hiding this comment

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

const cur_machine = environment.logged_into?.[0]

(but if you prefer this, it's fine)

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks too much like Perl for my taste... :-) but let's do it.

gboolean cockpit_auth_is_valid_cookie_value (CockpitAuth *self,
const gchar *cookie_value);

gchar * cockpit_auth_parse_application (const gchar *path,
Copy link
Member

Choose a reason for hiding this comment

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

Please outdent again

Comment on lines +287 to +309
gchar *h = g_hash_table_lookup (request_headers, "Cookie");
while (h && *h) {
const gchar *start = h;
while (*h && *h != '=')
h++;
const gchar *equal = h;
while (*h && *h != ';')
h++;
const gchar *end = h;
if (*h)
h++;
while (*h && *h == ' ')
h++;

if (*equal != '=')
continue;

g_autofree gchar *value = g_strndup (equal + 1, end - equal - 1);

if (!cockpit_auth_is_valid_cookie_value (auth, value))
continue;

g_autofree gchar *name = g_strndup (start, equal - start);
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, do you want sscanf() here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, that would be the second time in my life that I use sscanf... hmm.

@martinpitt
Copy link
Member

I tested this with the flatpak, and it behaves the same way: Opening a second window goes straight into the running session. We should be able to improve that by isolating the webkit instances from one another somehow, but that can be a follow-up.

Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

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

Thanks! As discussed in chat, let's get that into today's release, and do some follow-ups.

@martinpitt martinpitt merged commit 77b993e into cockpit-project:main Aug 20, 2024
79 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-blocker Targetted for next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants