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

Cycle session ID on login #2813

Merged
merged 15 commits into from Feb 29, 2024
Merged

Cycle session ID on login #2813

merged 15 commits into from Feb 29, 2024

Conversation

stveit
Copy link
Contributor

@stveit stveit commented Feb 20, 2024

For #2804 (might not solve it fully depending on how many changes to session id we want to do)

Cycles session ID on login. Or more generally, every time a different user is made into the active account for the session, so this includes the sudo/desudo functions where the logged in account is changed.

Had some issues testing against sessions with a session scoped client fixture. Changing this to function scoped and ensuring I get a fresh client for each test was a lot better

@stveit stveit self-assigned this Feb 20, 2024
Copy link

github-actions bot commented Feb 20, 2024

Test results

     12 files       12 suites   12m 12s ⏱️
3 308 tests 3 308 ✔️ 0 💤 0
9 399 runs  9 399 ✔️ 0 💤 0

Results for commit 19c5d84.

♻️ This comment has been updated with latest results.

@stveit stveit changed the title Cycle session ID Cycle session ID on login Feb 21, 2024
@stveit stveit force-pushed the session-id-rot branch 3 times, most recently from fb59be6 to 6a85ed6 Compare February 21, 2024 09:16
Copy link

codecov bot commented Feb 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 57.14%. Comparing base (d533e8f) to head (19c5d84).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2813      +/-   ##
==========================================
+ Coverage   57.10%   57.14%   +0.03%     
==========================================
  Files         567      567              
  Lines       41275    41275              
==========================================
+ Hits        23570    23585      +15     
+ Misses      17705    17690      -15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@stveit stveit force-pushed the session-id-rot branch 7 times, most recently from f99a74c to 7737eab Compare February 23, 2024 09:29
@stveit stveit mentioned this pull request Feb 23, 2024
@stveit stveit force-pushed the session-id-rot branch 2 times, most recently from 9c07866 to d4916f8 Compare February 23, 2024 10:26
@stveit stveit marked this pull request as ready for review February 23, 2024 10:53
@stveit stveit mentioned this pull request Feb 27, 2024
@stveit
Copy link
Contributor Author

stveit commented Feb 27, 2024

The codecov complaints are irrelevant for this pr

Copy link
Member

@lunkwill42 lunkwill42 left a comment

Choose a reason for hiding this comment

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

Looks great to me!

Just naming nitpicks, and one potential corner case for cycling a session id.

tests/integration/web/webfront_test.py Outdated Show resolved Hide resolved
tests/integration/web/webfront_test.py Outdated Show resolved Hide resolved
tests/integration/web/webfront_test.py Outdated Show resolved Hide resolved
python/nav/web/auth/utils.py Show resolved Hide resolved
tests/integration/conftest.py Show resolved Hide resolved
tests/integration/conftest.py Show resolved Hide resolved
tests/integration/web/webfront_test.py Outdated Show resolved Hide resolved
tests/integration/web/auth/middleware_test.py Outdated Show resolved Hide resolved
Does not do antyhing for logging out(i.e. removing account)
just when changing from either no account to an account
or from one account to another
stveit and others added 14 commits February 29, 2024 09:57
this func is imported alot of places, makes no sense
for this to be marked as private
have to mock away the cycle_key thingy else existing tests
fail. Will probably need separate integration tests to test
session ID cycling
Avoids session id changing on every request.
session will still be cycled on login by the functions
that directly handle login.

ensure_account either just sets the request.account field
to the match the already logged in user, or sets the account
to be the anonymous user. Neither should trigger a session_id.
got some issues testing session stuff when the client was
shared amongst all tests, maybe it got old or something as well.
Getting a fresh client for each test was a lot better
Co-authored-by: Morten Brekkevold <morten.brekkevold@sikt.no>
Co-authored-by: Morten Brekkevold <morten.brekkevold@sikt.no>
Copy link

sonarcloud bot commented Feb 29, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@stveit
Copy link
Contributor Author

stveit commented Feb 29, 2024

Rebased on master to get in #2835

@stveit stveit merged commit dff1b0c into Uninett:master Feb 29, 2024
12 checks passed
@hmpf hmpf linked an issue Mar 5, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rework session ids
3 participants