fix(files): a token made as every session ends goes with them, and a file being shared holds its job

This commit is contained in:
2026-10-15 05:47:00 +02:00
parent 2efa7d5a75
commit 620f84dba4
5 changed files with 199 additions and 7 deletions
+8 -2
View File
@@ -120,8 +120,14 @@ def create_token(
name = body.name.strip()
if not name:
raise refused(400, "api_token_name_required")
# The user's row, locked: two requests at once cannot both slip under the ceiling.
db.execute(select(User.id).where(User.id == user.id).with_for_update())
# The user's row, locked: two requests at once cannot both slip under the ceiling, and a
# session ended since `current_user` read the epoch (unlocked) cannot mint a token that outlives
# it — `bump_session_epoch` takes this lock before it revokes them all.
epoch = db.execute(
select(User.session_epoch).where(User.id == user.id).with_for_update()
).scalar_one()
if (epoch or 0) != (user.session_epoch or 0):
raise refused(401, "not_authenticated")
count = db.execute(
select(func.count(ApiToken.id)).where(ApiToken.user_id == user.id)
).scalar_one()