Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,13 @@ in `docs/adr/0001-event-bus-and-alerts.md`.
- `integration_disabled`: its type is off in the environment (Slack without `SLACK_CLIENT_ID`/`SECRET`), or the
organization disconnected it (e.g., last Slack workspace was removed)
- `unavailable`: no transport registered

It is computed, never stored. When an organization removes its last Slack workspace (`removeSlackWorkspace()`),
`disableForIntegration()` disables all enabled Slack channels with `disabledReason: 'integration'`; when Slack
is installed again, `restoreForIntegration()` enables only those back (ones manually disabled or failed stay
as they are). `deliver()` only sends to `connected` channels, the views (`toView()`, alert channel options)
carry it, and the settings list badges `integration_disabled`.

- Paused alerts and delivery status: `alertDelivery()` (`#lib/alerts/delivery.ts`, shared with the
client) says whether an alert is `live`: it has email recipients or at least one connected
channel. It computes `disconnectedTypes` (types of the alert's disconnected channels without repeats,
Expand Down Expand Up @@ -756,6 +757,12 @@ Unauthenticated public routes for external alert recipients: `/notifications/ver
They are allowed without a session in `hooks.server.ts` and validate their tokens rather than
checking permissions.

Read API for discovery and Code Report (`GET /api/projects`, `/api/code-report/services[/id[/vulnerabilities]]`,
logic in `#lib/server/code-report/api.ts`): permission-first through `callerCan` (sessions and keys). A project
or service the caller cannot read is a 404; 403 only when the project is readable (`project:project:read` or a
Code Report read) but the action (`reports:read`, `vulnerabilities:read`) is not. Lists use `limit`/`cursor`;
CVE titles are cut to 300 characters and the SBOM or raw scanner output is never returned.

`locals.user.role` is a session role object, not the string `admin`. Use `isAdmin()` or the `can*`
helpers. Keep authorization tests beside changes to permission behavior.

Expand Down
2 changes: 2 additions & 0 deletions e2e/fixtures/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export type SeedOutput = {
outsiderOrgSlug: string;
outsiderProjectSlug: string;
seededServiceSlug: string;
seededServiceId: string;
apiKeys: {
readOnly: string;
write: string;
Expand Down Expand Up @@ -578,6 +579,7 @@ export async function seedAll(): Promise<SeedOutput> {
outsiderOrgSlug: requireSeedSlug(outsiderOrg.slug, 'outsider organization'),
outsiderProjectSlug: requireSeedSlug(outsiderProject.slug, 'outsider project'),
seededServiceSlug: seededService.slug,
seededServiceId: seededService.id,
apiKeys: {
readOnly: readOnlyApiKeyToken,
write: writeApiKeyToken,
Expand Down
94 changes: 94 additions & 0 deletions e2e/specs/code-report-api.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { test, expect, getSeed } from '../fixtures/auth';

// read-only Code Report API (#125): a user (cookie) or a project key sees its project; everyone
// else gets 404 (existence not revealed) or 403 when the project is readable but not the action
const seed = getSeed();
const services = `/api/code-report/services?projectId=${seed.primaryProjectId}`;
const detail = `/api/code-report/services/${seed.seededServiceId}`;
const vulnerabilities = `${detail}/vulnerabilities`;
const bearer = (token: string) => ({ Authorization: `Bearer ${token}` });

test.describe('code report API — session', () => {
test('a project viewer reads projects, services, report and vulnerabilities', async ({
page,
loginAs,
}) => {
await loginAs('projectViewer');

const projects = await page.request.get('/api/projects');
expect(projects.status()).toBe(200);
const { items } = await projects.json();
const mine = items.find((p: { id: string }) => p.id === seed.primaryProjectId);
expect(mine).toMatchObject({
slug: seed.primaryProjectSlug,
organization: { id: seed.primaryOrgId, slug: seed.primaryOrgSlug },
});
expect(mine.modules).toContain('codereport');
expect(items.some((p: { slug: string }) => p.slug === seed.outsiderProjectSlug)).toBe(false);

const list = await page.request.get(services);
expect(list.status()).toBe(200);
const listed = await list.json();
expect(listed.items.map((s: { id: string }) => s.id)).toContain(seed.seededServiceId);

const report = await page.request.get(detail);
expect(report.status()).toBe(200);
expect(await report.json()).toMatchObject({
id: seed.seededServiceId,
name: 'E2E Seeded Service',
lastAnalysisAt: null,
});

const cves = await page.request.get(vulnerabilities);
expect(cves.status()).toBe(200);
expect(await cves.json()).toEqual({ items: [], nextCursor: null });
});

test('invalid parameters are 400 with a normalized error', async ({ page, loginAs }) => {
await loginAs('projectViewer');
const response = await page.request.get(`${vulnerabilities}?severity=nasty`);
expect(response.status()).toBe(400);
expect(await response.json()).toMatchObject({ code: 'invalid_request' });
expect((await page.request.get('/api/code-report/services')).status()).toBe(400);
});

test('a project:project:read-only user is forbidden, not 404', async ({ page, loginAs }) => {
await loginAs('projectReadOnly');
expect((await page.request.get(services)).status()).toBe(403);
expect((await page.request.get(detail)).status()).toBe(403);
expect((await page.request.get(vulnerabilities)).status()).toBe(403);
});

test('a user of another organization gets 404 everywhere', async ({ page, loginAs }) => {
await loginAs('projectOutsider');
expect((await page.request.get(services)).status()).toBe(404);
expect((await page.request.get(detail)).status()).toBe(404);
expect((await page.request.get(vulnerabilities)).status()).toBe(404);
expect(
(await page.request.get(`/api/projects?organizationId=${seed.primaryOrgId}`)).status(),
).toBe(404);
const { items } = await (await page.request.get('/api/projects')).json();
expect(items.some((p: { id: string }) => p.id === seed.primaryProjectId)).toBe(false);
});

test('without a session the API answers 401', async ({ request }) => {
expect((await request.get(services)).status()).toBe(401);
});
});

test.describe('code report API — project keys', () => {
test('a key reads its own project', async ({ request }) => {
const headers = bearer(seed.apiKeys.readOnly);
expect((await request.get(services, { headers })).status()).toBe(200);
expect((await request.get(detail, { headers })).status()).toBe(200);
const { items } = await (await request.get('/api/projects', { headers })).json();
expect(items.map((p: { id: string }) => p.id)).toEqual([seed.primaryProjectId]);
});

test('a key of another project gets 404', async ({ request }) => {
const headers = bearer(seed.apiKeys.outsiderProject);
expect((await request.get(services, { headers })).status()).toBe(404);
expect((await request.get(detail, { headers })).status()).toBe(404);
expect((await request.get(vulnerabilities, { headers })).status()).toBe(404);
});
});
20 changes: 20 additions & 0 deletions e2e/specs/mcp-api-key.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,23 @@ test('a personal api key (not mcp) still has no permissions', async ({ request }
});
expect(response.status()).toBe(403);
});

test('an mcp key reads Code Report services and vulnerabilities', async ({ request }) => {
const services = await request.get(
`/api/code-report/services?projectId=${seed.primaryProjectId}`,
{ headers: mcp },
);
expect(services.status()).toBe(200);
const vulnerabilities = await request.get(
`/api/code-report/services/${seed.seededServiceId}/vulnerabilities`,
{ headers: mcp },
);
expect(vulnerabilities.status()).toBe(200);
});

test('an mcp key lists the primary project in /api/projects', async ({ request }) => {
const response = await request.get('/api/projects', { headers: mcp });
expect(response.status()).toBe(200);
const { items } = await response.json();
expect(items.map((project: { id: string }) => project.id)).toContain(seed.primaryProjectId);
});
Loading
Loading