Skip to content

session: one random row per login - #83

Merged
msimerson merged 5 commits into
NicTool:mainfrom
aberoham:session-row-per-login
Oct 16, 2026
Merged

msimerson merged 5 commits into
NicTool:mainfrom
aberoham:session-row-per-login

Conversation

@aberoham

Copy link
Copy Markdown
Contributor

Login wrote the constant 3.0.0 into nt_user_session. v2 looks a session up by that column alone, so on a shared db, sending nt_user_session=3.0.0 to v2 logged in as a recent v3 user.

Each login now gets its own row holding 3$ and 64 random hex chars, marked the way #56 marks password hashes. A login deletes that user's expired v3 rows and leaves v2's alone. The token's exp now matches the 4 hour max age it was already refused at. The mysql store now reads last_access, so its one-minute touch throttle works.

aberoham and others added 5 commits October 15, 2026 21:51
Each login writes its own row holding 3$ and 64 random hex chars
instead of the constant 3.0.0, which v2 accepted as a session from
anyone. The 3$ shape marks v3's rows the way a stored password hash
names its own format. A login sweeps that user's v3 sessions idle past
the token's max age, and leaves v2's to its own timeout. The token's
exp now matches that max age. The mysql store selects last_access, so
its activity throttle applies.
The token lifetime follows main's 8 hours: maxAgeSec in lib/session/v3.js
is now 8 * 60 * 60, and the expire test's stale row sits past that cutoff.
The JWT validate accepted any well-signed token, so DELETE /session left
the token working until it expired. A token is now valid only while its
session row exists for that user. v2's timeout_sessions deletes rows idle
past its session_timeout (45 min by default) on a shared db, so every
authenticated request now refreshes last_access, not only GET /session.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Existing predictable session rows remain exploitable through v2 until explicitly invalidated.

1 open finding
What changed in this PR

Improves session isolation and revocation for NicTool’s shared v2/v3 database.

Changes:

  • Creates a random, version-marked session row per login.
  • Checks session existence and refreshes activity on authenticated requests.
  • Adds expiry cleanup and session regression tests.
File Description
routes/​session.test.js Tests revocation, activity, and write failures.
routes/​session.js Creates random sessions and expires stale rows.
routes/​index.js Validates session existence and updates activity.
lib/​session/​v3.test.js Tests session value generation and identification.
lib/​session/​v3.js Defines session markers and lifetime constants.
lib/​session/​test/​index.js Tests distinct rows, activity updates, and cleanup.
lib/​session/​store/​mysql.js Adds expiry cleanup and reads activity timestamps.
lib/​session/​store/​file.js Creates distinct rows and adds expiry cleanup.
CHANGELOG.md Documents session security and lifecycle changes.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/session/store/mysql.js
@msimerson
msimerson merged commit b957e01 into NicTool:main Oct 16, 2026
10 checks passed
@aberoham
aberoham deleted the session-row-per-login branch October 16, 2026 05:43
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.

3 participants