Skip to content

The agent that grows with you

fix(gateway): apply the profile rule to the login-stamp claim shortcut

unsupportedpastels7f49657aab0e
diff --git a/gateway/session_local_migration.py b/gateway/session_local_migration.py
index ca3ce1b0b3d..fd2015b7529 100644
--- a/gateway/session_local_migration.py
+++ b/gateway/session_local_migration.py
@@ -39,7 +39,8 @@ def require_history_claim(authority, conn, actor, sid):
return
if conn.execute('SELECT 1 FROM state_meta WHERE key=?', (BINDING_PREFIX + sid,)).fetchone():
return # authorize_history checks the already committed importer identity.
- if _owner_user(row) and row['user_id'] in (actor.subject, _login_label(actor.subject)):
+ own_profile = row['profile_name'] in (None, '', authority.db._own_profile_name() or 'default')
+ if own_profile and _owner_user(row) and row['user_id'] in (actor.subject, _login_label(actor.subject)):
return # The login that created it (a served remote Desktop); authorize_history re-checks it.
if getattr(authority, '_native_legacy_transports', {}).get(actor.transport_id) != actor:
raise RuntimeStoreError('permission_denied')
diff --git a/tests/gateway/test_legacy_desktop_source.py b/tests/gateway/test_legacy_desktop_source.py
index dea2925b7b7..9668492e9e9 100644
--- a/tests/gateway/test_legacy_desktop_source.py
+++ b/tests/gateway/test_legacy_desktop_source.py
@@ -97,6 +97,8 @@ def test_a_served_login_controls_its_own_stamped_chat_over_http(tmp_path):
try:
db.create_session('alice-row', source='desktop', user_id='basic:alice')
db.create_session('unstamped', source='desktop')
+ # Restored or copied from another profile: the adoption gate answers not_found for it.
+ db.create_session('alice-other-profile', source='desktop', user_id='basic:alice', profile_name='other')
authority = SimpleNamespace(profile_id=str(tmp_path), db=db, sessions={})
caps = frozenset({'session:read', 'session:create', 'session:control'})
alice, bob, host = (Principal(subject, str(tmp_path), caps, 'http')
@@ -107,7 +109,8 @@ def test_a_served_login_controls_its_own_stamped_chat_over_http(tmp_path):
return _authorize_control(authority, actor, SessionRef(str(tmp_path), sid), params)
assert control(alice, 'alice-row') is True
- for stranger, sid in ((bob, 'alice-row'), (host, 'alice-row'), (alice, 'unstamped')):
+ for stranger, sid in ((bob, 'alice-row'), (host, 'alice-row'), (alice, 'unstamped'),
+ (alice, 'alice-other-profile')):
with pytest.raises(RuntimeStoreError, match='permission_denied'):
control(stranger, sid)
finally: