Skip to content

Commit a2c94a9

Browse files
committed
Add the connected sites panel and cut the consent screen down
Two changes from Samet's review. The consent screen was too long. Most people approving this will not read a wall of text, and a wall of text is what makes them not read. The scope list is now one line each, the four withheld items collapsed into one sentence, and the longer explanations moved behind a "Bunlar ne demek?" disclosure that needs no JavaScript. The openid row is gone from the visible list — "who you are on this site" is the definition of signing in, so it spent a line to say nothing and pushed the rows that matter further down. What did not move: the email row still says the site keeps its own copy, now as three words in parentheses. That is the one consequence of this decision that cannot be undone later, and a screen that omits it is hiding it. Short is the goal; silent is not. Connected sites is its own card rather than a row inside "Bağlı uygulamalar", because that card shows authority granted to an agent while this one shows a site you signed into. One list would mean the person pressing revoke does not know what they are cutting. The endpoints live under /v1/me rather than /v1/oauth: /v1/oauth is where sites talk to us, /v1/me is where the person does. Revoking someone else's grant answers 404 rather than 403, since confirming the id exists would let grant ids be probed. Verified end to end, not just listed: cutting a connection kills the access token and the refresh in the same step, so "your session there is closed" is true when the panel says it. Reconnecting afterwards asks for consent again rather than being permanently barred. 184 core tests, 2810 site assertions and 557 browser assertions pass.
1 parent 5c6cf96 commit a2c94a9

6 files changed

Lines changed: 338 additions & 53 deletions

File tree

‎scripts/orbit-site-authorization-tests.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,6 @@ describe('Orbit as a sign-in door for other sites', { concurrency: false }, () =
938938
clientSiteUrl: 'https://anime.sametbasbug.dev',
939939
scopes: ['openid', 'profile', 'email'],
940940
accountHandle: 'samet',
941-
accountDisplayName: 'Samet Başbuğ',
942941
ticket: 'orb_site_req_v1.payload.signature',
943942
csrfToken: 'csrf-value',
944943
cancelUrl: 'https://anime.sametbasbug.dev/auth/v1/callback?error=access_denied',
@@ -957,8 +956,8 @@ describe('Orbit as a sign-in door for other sites', { concurrency: false }, () =
957956
assert.match(html, /o kopya sitede kalır/u);
958957
/* Verilmeyenler listesi — takip akışı burada, çünkü kapsam listesinde
959958
* bilerek yok. */
960-
assert.match(html, /takip akışın/u);
961-
assert.match(html, /Mesajların/u);
959+
assert.match(html, /Takip akışın/u);
960+
assert.match(html, /mesajların/u);
962961
/* İstenmeyen kapsamın metni sayfaya hiç girmiyor. */
963962
assert.equal(html.includes('Herkese açık gönderilerin'), false);
964963
assert.match(html, /@samet/u);
@@ -970,7 +969,6 @@ describe('Orbit as a sign-in door for other sites', { concurrency: false }, () =
970969
clientSiteUrl: 'https://anime.example/"><script>alert(2)</script>',
971970
scopes: ['openid'],
972971
accountHandle: 'samet',
973-
accountDisplayName: 'Samet',
974972
ticket: 'orb_site_req_v1.a.b',
975973
csrfToken: 'csrf',
976974
cancelUrl: 'https://anime.example/cb',

‎scripts/orbit-site-signin-e2e-tests.ts‎

Lines changed: 177 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,23 @@ function ticketFromConsentPage(html: string): string {
195195
return match[1];
196196
}
197197

198+
/* Koda kadar giden yol, izin durumundan bağımsız.
199+
*
200+
* Testler sırayla koşuyor ve içlerinden biri izni iptal ediyor; ondan sonraki
201+
* her `/authorize` onay ekranıyla başlıyor. Bu yardımcı iki hâli de yürütüyor,
202+
* böylece bir testin bıraktığı durum sonrakini "yönlendirme bekleniyordu"
203+
* diye kırmıyor — kırdığında da sebebi kendi konusu olmayan bir şey olurdu. */
204+
async function authorizeToCode(query: Record<string, string>): Promise<string> {
205+
const first = await authorize(query);
206+
if (first.status === 200) {
207+
const redirect = await consent(ticketFromConsentPage(await first.text()), 'allow');
208+
assert.equal(redirect.status, 302);
209+
return locationOf(redirect).searchParams.get('code') ?? '';
210+
}
211+
assert.equal(first.status, 302);
212+
return locationOf(first).searchParams.get('code') ?? '';
213+
}
214+
198215
function locationOf(response: Response): URL {
199216
const location = response.headers.get('location');
200217
assert.ok(location, `expected a redirect, got ${response.status}`);
@@ -569,9 +586,167 @@ describe('Signing in to another Equinox site with Orbit', { concurrency: false }
569586
assert.equal(afterBurn.status, 400, 'the replay must burn the rotated token too');
570587
});
571588

589+
test('the connected sites panel lists the grant and cutting it kills the session', async () => {
590+
const code = await authorizeToCode(authorizeQuery({ state: 'panel-state' }));
591+
const issued = await tokenRequest({
592+
grant_type: 'authorization_code',
593+
code,
594+
code_verifier: VERIFIER,
595+
redirect_uri: REDIRECT_URI,
596+
});
597+
assert.equal(issued.status, 200);
598+
599+
const listed = await fetch(`${baseUrl}/v1/me/connected-sites`, {
600+
headers: { cookie: sessionCookie, 'x-test-now': String(NOW) },
601+
});
602+
assert.equal(listed.status, 200);
603+
const { connectedSites } = await listed.json() as {
604+
connectedSites: Array<{ id: string; label: string; scopes: string[]; lastUsedAt: number | null }>;
605+
};
606+
assert.equal(connectedSites.length, 1);
607+
assert.equal(connectedSites[0]?.label, CLIENT_LABEL);
608+
assert.ok(connectedSites[0]?.lastUsedAt);
609+
610+
/* Panel bir tarayıcı yüzeyi: mutasyon CSRF başlığı ve izinli origin
611+
* istiyor. İkisi olmadan iptal edilemiyor, yoksa başka bir sitedeki bir
612+
* sayfa kullanıcının bağlantılarını kesebilirdi. */
613+
const withoutCsrf = await fetch(
614+
`${baseUrl}/v1/me/connected-sites/${encodeURIComponent(connectedSites[0].id)}/revoke`,
615+
{
616+
method: 'POST',
617+
headers: {
618+
'content-type': 'application/json',
619+
origin: ORIGIN,
620+
cookie: sessionCookie,
621+
'x-test-now': String(NOW),
622+
},
623+
body: '{}',
624+
},
625+
);
626+
assert.equal(withoutCsrf.status, 403);
627+
628+
const revoked = await fetch(
629+
`${baseUrl}/v1/me/connected-sites/${encodeURIComponent(connectedSites[0].id)}/revoke`,
630+
{
631+
method: 'POST',
632+
headers: {
633+
'content-type': 'application/json',
634+
origin: ORIGIN,
635+
cookie: sessionCookie,
636+
'X-Orbit-CSRF': csrfToken,
637+
'x-test-now': String(NOW),
638+
},
639+
body: '{}',
640+
},
641+
);
642+
assert.equal(revoked.status, 200);
643+
644+
/* "Bağlantıyı kes" gerçekten kesiyor: erişim anahtarı da, yenileme de
645+
* ölüyor. Panelde düğmeye basan kişi için bunun anlamı "o sitedeki oturumum
646+
* kapandı" ve o cümlenin doğru olması gerekiyor. */
647+
const userinfo = await fetch(`${baseUrl}/v1/oauth/userinfo`, {
648+
headers: {
649+
authorization: `Bearer ${String(issued.body.access_token)}`,
650+
'x-test-now': String(NOW + 1_000),
651+
},
652+
});
653+
assert.equal(userinfo.status, 401);
654+
const refreshed = await tokenRequest({
655+
grant_type: 'refresh_token',
656+
refresh_token: String(issued.body.refresh_token),
657+
}, { now: NOW + 1_000 });
658+
assert.equal(refreshed.status, 400);
659+
660+
const emptied = await fetch(`${baseUrl}/v1/me/connected-sites`, {
661+
headers: { cookie: sessionCookie, 'x-test-now': String(NOW) },
662+
});
663+
const after = await emptied.json() as { connectedSites: unknown[] };
664+
assert.equal(after.connectedSites.length, 0, 'a cut connection leaves the list');
665+
666+
/* İkinci iptal 409: iptal edilmiş bir bağlantı kesilecek bir şey
667+
* bırakmıyor ve sessiz bir 200, panelde olmayan bir şeyi kesmiş gibi
668+
* görünürdü. */
669+
const again = await fetch(
670+
`${baseUrl}/v1/me/connected-sites/${encodeURIComponent(connectedSites[0].id)}/revoke`,
671+
{
672+
method: 'POST',
673+
headers: {
674+
'content-type': 'application/json',
675+
origin: ORIGIN,
676+
cookie: sessionCookie,
677+
'X-Orbit-CSRF': csrfToken,
678+
'x-test-now': String(NOW),
679+
},
680+
body: '{}',
681+
},
682+
);
683+
assert.equal(again.status, 409);
684+
685+
/* Kullanıcı kestiği siteye geri dönebiliyor: yeniden onay izni diriltiyor.
686+
* Diriltmeyen bir tasarım, "bağlantıyı kes"i kalıcı bir yasağa çevirirdi. */
687+
const reconnected = await authorize(authorizeQuery({ state: 'reconnect-state' }));
688+
assert.equal(reconnected.status, 200, 'reconnecting must ask for consent again');
689+
});
690+
691+
test('another account cannot cut someone else’s connection', async () => {
692+
const strangerId = '019f7000-0000-7000-8000-0000000000c1';
693+
assert.equal((await testPost('/__test/seed-account', {
694+
accountId: strangerId,
695+
handle: 'yabanci',
696+
displayName: 'Yabancı',
697+
now: NOW,
698+
})).status, 200);
699+
const strangerSession = await createOpaqueToken('session', SESSION_PEPPER);
700+
const strangerCsrf = randomBase64Url(32);
701+
assert.equal((await testPost('/__test/seed-human-session', {
702+
sessionId: strangerSession.selector,
703+
secretDigest: strangerSession.digest,
704+
csrfDigest: await hmacDigest(
705+
`orbit:csrf:v1:${strangerSession.selector}:${strangerCsrf}`,
706+
CSRF_PEPPER,
707+
),
708+
accountId: strangerId,
709+
now: NOW,
710+
})).status, 200);
711+
712+
/* Önce sahibi bir bağlantı kursun. */
713+
assert.ok(await authorizeToCode(authorizeQuery({ state: 'stranger-state' })));
714+
const listed = await fetch(`${baseUrl}/v1/me/connected-sites`, {
715+
headers: { cookie: sessionCookie, 'x-test-now': String(NOW) },
716+
});
717+
const { connectedSites } = await listed.json() as { connectedSites: Array<{ id: string }> };
718+
assert.ok(connectedSites.length >= 1);
719+
720+
const stolen = await fetch(
721+
`${baseUrl}/v1/me/connected-sites/${encodeURIComponent(connectedSites[0].id)}/revoke`,
722+
{
723+
method: 'POST',
724+
headers: {
725+
'content-type': 'application/json',
726+
origin: ORIGIN,
727+
cookie: `__Host-orbit_session=${strangerSession.token}; __Host-orbit_csrf=${strangerCsrf}`,
728+
'X-Orbit-CSRF': strangerCsrf,
729+
'x-test-now': String(NOW),
730+
},
731+
body: '{}',
732+
},
733+
);
734+
/* 404, 403 değil: "yetkin yok" cevabı o kimliğin var olduğunu doğrular ve
735+
* izin kimliklerinin taranmasına izin verirdi. */
736+
assert.equal(stolen.status, 404);
737+
738+
const strangerList = await fetch(`${baseUrl}/v1/me/connected-sites`, {
739+
headers: {
740+
cookie: `__Host-orbit_session=${strangerSession.token}; __Host-orbit_csrf=${strangerCsrf}`,
741+
'x-test-now': String(NOW),
742+
},
743+
});
744+
const strangerBody = await strangerList.json() as { connectedSites: unknown[] };
745+
assert.equal(strangerBody.connectedSites.length, 0);
746+
});
747+
572748
test('suspending the account stops the refresh and the userinfo read', async () => {
573-
const granted = await authorize(authorizeQuery({ state: 'suspend-state' }));
574-
const code = locationOf(granted).searchParams.get('code') ?? '';
749+
const code = await authorizeToCode(authorizeQuery({ state: 'suspend-state' }));
575750
const issued = await tokenRequest({
576751
grant_type: 'authorization_code',
577752
code,

‎src/pages/dashboard.astro‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,15 @@ import { LEGAL_LAST_UPDATED } from '../data/legal';
220220
<p class="section-help">Orbit ajanlarına verdiğin MCP okuma izinlerini buradan geri alabilirsin.</p>
221221
<div id="mcp-authorizations" class="dashboard-list"></div>
222222
</article>
223+
<!-- Ayrı kart, "Bağlı uygulamalar"ın içine karışmıyor: o kart bir
224+
AJANA verilmiş yetkiyi, bu kart Orbit hesabıyla girdiğin bir
225+
SİTEYİ gösteriyor. Tek listede toplamak, iptal düğmesine basan
226+
kişinin neyi kestiğini bilmemesi olurdu. -->
227+
<article id="connected-sites-card" class="dashboard-card account-card section-card">
228+
<h2>Bağlı siteler</h2>
229+
<p class="section-help">Orbit hesabınla giriş yaptığın siteler. Bağlantıyı kesmek o sitedeki anahtarları anında düşürür; sitenin kendi kaydına aldığı bilgileri silmez.</p>
230+
<div id="connected-sites" class="dashboard-list"></div>
231+
</article>
223232
<div class="truth-note">
224233
<Icon name="info" size={17} />
225234
<p><strong>Bir sorun mu var?</strong><span>Sayfayı yenile. Sorun sürerse ekran görüntüsüyle Orbit yöneticisine ulaş.</span></p>

‎src/scripts/dashboard.js‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,41 @@ async function loadMcpAuthorizations() {
314314
}
315315
}
316316

317+
/* Bağlı siteler. Ayrı bir yükleyici, ayrı bir uç: "Bağlı uygulamalar" bir
318+
ajana verilmiş MCP yetkisini gösteriyor, burası Orbit hesabıyla giriş
319+
yapılmış siteleri. İkisini tek listede toplamak, iptale basan kişinin neyi
320+
kestiğini bilmemesi olurdu. */
321+
async function loadConnectedSites() {
322+
const rows = (await request('/v1/me/connected-sites')).body.connectedSites;
323+
const host = byId('connected-sites');
324+
host.replaceChildren();
325+
if (!rows.length) {
326+
host.innerHTML = '<div class="dashboard-item"><strong>Bağlı site yok</strong><div class="meta">Bir Equinox sitesine Orbit hesabınla girdiğinde burada görünecek.</div></div>';
327+
return;
328+
}
329+
for (const site of rows) {
330+
const item = document.createElement('div');
331+
item.className = 'dashboard-item';
332+
const since = new Date(site.createdAt).toLocaleDateString('tr-TR');
333+
/* Son kullanım tarihi gösteriliyor: listede birden fazla site varken
334+
"bunu hâlâ kullanıyor muyum" sorusunun cevabı bu. Hiç kullanılmamışsa
335+
satır yazılmıyor — "—" yazmak bilgi taşımıyor. */
336+
const lastUsed = site.lastUsedAt
337+
? ` · son giriş ${new Date(site.lastUsedAt).toLocaleDateString('tr-TR')}`
338+
: '';
339+
item.innerHTML = `<strong>${escapeHtml(site.label)}</strong><div class="meta">${escapeHtml(since)} tarihinden beri${escapeHtml(lastUsed)} · ${escapeHtml(site.scopes.join(', '))}</div>`;
340+
item.append(actionButton('Bağlantıyı kes', async () => {
341+
if (!window.confirm(`${site.label} bağlantısı kesilsin mi? O sitedeki oturumun kapanır.`)) return;
342+
try {
343+
await mutate(`/v1/me/connected-sites/${encodeURIComponent(site.id)}/revoke`);
344+
await loadConnectedSites();
345+
flash('Site bağlantısı kesildi.');
346+
} catch (error) { flash(error.message, 'error'); }
347+
}, 'danger'));
348+
host.append(item);
349+
}
350+
}
351+
317352
async function credentialRotate() {
318353
if (!managed.activeCredential) return;
319354
try {
@@ -578,7 +613,7 @@ async function load() {
578613
}
579614
showPrimaryView('dashboard');
580615
renderAccount();
581-
await Promise.all([loadSessions(), loadAgent(), loadMcpAuthorizations()]);
616+
await Promise.all([loadSessions(), loadAgent(), loadMcpAuthorizations(), loadConnectedSites()]);
582617
const publicationReviewer = me.account.roles.includes('platform_owner') || me.account.roles.includes('moderator');
583618
if (publicationReviewer) {
584619
byId('admin-tools').classList.remove('hidden');

‎src/server/http/api.ts‎

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4426,7 +4426,6 @@ async function handleSiteAuthorize(
44264426
clientSiteUrl: client.siteUrl,
44274427
scopes,
44284428
accountHandle: auth.account.handle,
4429-
accountDisplayName: auth.account.displayName,
44304429
ticket,
44314430
csrfToken: auth.csrfToken ?? '',
44324431
cancelUrl: redirectUri,
@@ -7118,6 +7117,58 @@ export async function handleApiRequest(
71187117
}, 201);
71197118
}
71207119

7120+
/* "Bağlı siteler" — insan yüzü. `/v1/oauth/*` uçları sitelerin konuştuğu
7121+
* yer; bu iki uç kullanıcının konuştuğu yer, o yüzden `/v1/me` altında.
7122+
* Aynı ön eki paylaşsalardı, sitenin sunabildiği bir anahtarla insanın
7123+
* oturumunun aynı kapıdan geçtiği izlenimi doğardı. */
7124+
if (request.method === 'GET' && path === '/v1/me/connected-sites') {
7125+
const auth = await authenticateHuman(request, env, repository, now, false);
7126+
const grants = await siteRepository.listAccountGrants(auth.account.id);
7127+
return json({
7128+
/* Yalnız yürürlükteki bağlantılar — MCP listesindeki gerekçenin
7129+
* aynısı: iptal edilmiş bir kayıt panelde kesilecek bir şey
7130+
* bırakmıyor, yalnız gerçekten bağlı olanı görünmez kılıyor. Satırın
7131+
* kendisi silinmiyor, denetim izi `revoked_at` ile duruyor. */
7132+
connectedSites: grants
7133+
.filter((grant) => grant.revokedAt === null)
7134+
.map((grant) => ({
7135+
id: grant.id,
7136+
label: grant.clientLabel,
7137+
siteUrl: grant.clientSiteUrl,
7138+
scopes: grant.scopes,
7139+
createdAt: grant.createdAt,
7140+
lastUsedAt: grant.lastUsedAt,
7141+
})),
7142+
});
7143+
}
7144+
7145+
const connectedSiteRevokeMatch = /^\/v1\/me\/connected-sites\/([^/]+)\/revoke$/u.exec(path);
7146+
if (request.method === 'POST' && connectedSiteRevokeMatch) {
7147+
const auth = await authenticateHuman(request, env, repository, now, true);
7148+
const body = await readJson(request);
7149+
requireExactFields(body, [], 'invalid_connected_site_revoke_fields');
7150+
const grantId = decodeURIComponent(connectedSiteRevokeMatch[1]);
7151+
const grant = await siteRepository.getGrantById(grantId);
7152+
/* Başkasının izni "bulunamadı" diye dönüyor, "yetkin yok" diye değil:
7153+
* ikincisi, elindeki kimliğin var olduğunu doğrulayarak izin
7154+
* kimliklerinin taranmasına izin verirdi. */
7155+
if (!grant || grant.accountId !== auth.account.id) {
7156+
throw new ApiError(404, 'connected_site_not_found', 'Connected site was not found.');
7157+
}
7158+
if (grant.revokedAt !== null) {
7159+
throw new ApiError(409, 'connected_site_already_revoked', 'Connected site is already revoked.');
7160+
}
7161+
await siteRepository.revokeGrant({
7162+
grantId,
7163+
actorAccountId: auth.account.id,
7164+
reason: 'user_revoked',
7165+
auditEventId: createEntityId(),
7166+
requestId,
7167+
revokedAt: now,
7168+
});
7169+
return json({ connectedSite: { id: grantId, revoked: true } });
7170+
}
7171+
71217172
const mcpAuthorizationRevokeMatch = /^\/v1\/mcp\/authorizations\/([^/]+)\/revoke$/u.exec(path);
71227173
if (request.method === 'POST' && mcpAuthorizationRevokeMatch) {
71237174
const auth = await authenticateHuman(request, env, repository, now, true);

0 commit comments

Comments
 (0)