Skip to content

Commit 3e77a2e

Browse files
author
Hayt
committed
Merge remote-tracking branch 'origin/main' into hayt/nip-fi-stateless-enforcement
* origin/main: docs(nip-fi): add Blossom kind-24242 media possession-proof exception (#7278) fix(desktop): wrap message tables within the available pane (#7279) Signed-off-by: Hayt <9e1c23a3fd83f61da34420e4e88ff1b16e45cafcc0cd9019eb07d4ecfa8ca9b0@buzz.block.builderlab.xyz>
2 parents 19fd134 + 752cbfc commit 3e77a2e

6 files changed

Lines changed: 266 additions & 6 deletions

File tree

‎desktop/playwright.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export default defineConfig({
115115
"**/channel-head-restart.spec.ts",
116116
"**/live-broadcast-reply-timeline.spec.ts",
117117
"**/markdown-parse-cache.spec.ts",
118+
"**/markdown-tables.spec.ts",
118119
"**/overscroll-boundary.spec.ts",
119120
"**/terminal-wheel.spec.ts",
120121
"**/cold-switch-longtask.perf.ts",

‎desktop/src/shared/ui/markdown.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,12 +1563,12 @@ export function createMarkdownComponents(
15631563
),
15641564
table: ({ children }) => <MarkdownTable>{children}</MarkdownTable>,
15651565
td: ({ children }) => (
1566-
<td className="border-t border-border/70 px-3 py-2 align-top">
1566+
<td className="min-w-24 border-t border-border/70 px-3 py-2 align-top">
15671567
{children}
15681568
</td>
15691569
),
15701570
th: ({ children }) => (
1571-
<th className="bg-muted/60 px-3 py-2 font-semibold text-foreground">
1571+
<th className="min-w-24 bg-muted/60 px-3 py-2 align-top font-semibold text-foreground">
15721572
{children}
15731573
</th>
15741574
),

‎desktop/src/shared/ui/markdown/MarkdownTable.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ export function MarkdownTable({ children }: { children?: React.ReactNode }) {
1212
className="overflow-x-auto rounded-2xl border border-border/70"
1313
data-table-block=""
1414
>
15-
<table className="w-max min-w-full border-collapse text-left text-sm">
15+
{/* Inherit message wrap-anywhere for long tokens. The cells' minimum
16+
widths keep short labels readable; many-column tables scroll locally. */}
17+
<table className="w-full border-collapse text-left text-sm">
1618
{children}
1719
</table>
1820
</div>
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
import { expect, test } from "@playwright/test";
2+
import { waitForAnimations } from "../helpers/animations";
3+
import { installMockBridge } from "../helpers/bridge";
4+
5+
const token = "0123456789abcdef".repeat(8);
6+
const url = `https://example.com/reports/${token}`;
7+
const prose =
8+
"Review the rollout notes and confirm that each owner can read the complete status without scrolling sideways. Keep the next action beside its owner, even when this description spans several lines.";
9+
const content = `Table readability fixture
10+
11+
| Owner | Status and next action with enough detail to span multiple lines in a narrow pane |
12+
| --- | --- |
13+
| Alice | ${prose} |
14+
| Bob | [Read the complete rollout notes and review checklist](${url}) and then confirm the next step. |
15+
| Token | ${token} |
16+
| Link | <${url}> |
17+
| Code | \`git diff --check\` and **review** the result. |
18+
19+
Surrounding paragraph stays in the message layout.`;
20+
21+
for (const surface of ["channel", "thread"] as const) {
22+
test(`markdown tables wrap and stay contained in the ${surface}`, async ({
23+
page,
24+
}, testInfo) => {
25+
await page.setViewportSize({ width: 1280, height: 1440 });
26+
await installMockBridge(page);
27+
await page.goto("/");
28+
await page.getByTestId("channel-general").click();
29+
await expect(page.getByTestId("chat-title")).toHaveText("general");
30+
await page.waitForFunction(() =>
31+
window.__BUZZ_E2E_HAS_MOCK_LIVE_SUBSCRIPTION__?.({
32+
channelName: "general",
33+
}),
34+
);
35+
const root = await page.evaluate((body) => {
36+
const root = window.__BUZZ_E2E_EMIT_MOCK_MESSAGE__?.({
37+
channelName: "general",
38+
content: body,
39+
});
40+
if (!root) throw new Error("Mock message was not emitted");
41+
return root.id;
42+
}, content);
43+
44+
const timelineMessage = page
45+
.getByTestId("message-timeline")
46+
.locator(`[data-message-id="${root}"]`);
47+
await expect(timelineMessage).toBeVisible();
48+
if (surface === "thread") {
49+
await timelineMessage.hover();
50+
await page.getByTestId(`reply-message-${root}`).click();
51+
await expect(page.getByTestId("message-thread-panel")).toBeVisible();
52+
}
53+
const scope = page.getByTestId(
54+
surface === "thread" ? "message-thread-panel" : "message-timeline",
55+
);
56+
const markdown = scope
57+
.locator(".message-markdown")
58+
.filter({ hasText: "Table readability fixture" });
59+
const block = markdown.locator("[data-table-block]");
60+
await expect(block).toBeVisible();
61+
await page.mouse.move(0, 0);
62+
await waitForAnimations(page);
63+
await markdown.screenshot({ path: testInfo.outputPath(`${surface}.png`) });
64+
const metrics = await block.evaluate((element) => {
65+
const table = element.querySelector("table");
66+
if (!table) throw new Error("Semantic table missing");
67+
const label = document.createRange();
68+
label.selectNodeContents(table.rows[0].cells[0]);
69+
return {
70+
labelLines: label.getClientRects().length,
71+
width: element.clientWidth,
72+
scrollWidth: element.scrollWidth,
73+
tableWidth: table.getBoundingClientRect().width,
74+
alignments: Array.from(
75+
table.querySelectorAll("th, td"),
76+
(cell) => getComputedStyle(cell).verticalAlign,
77+
),
78+
rowHeight: table.rows[1].getBoundingClientRect().height,
79+
lineHeight: Number.parseFloat(getComputedStyle(table).lineHeight),
80+
pageWidth: document.documentElement.clientWidth,
81+
pageScrollWidth: document.documentElement.scrollWidth,
82+
};
83+
});
84+
await testInfo.attach("layout", {
85+
body: JSON.stringify(metrics, null, 2),
86+
contentType: "application/json",
87+
});
88+
expect(metrics.width).toBeGreaterThan(250);
89+
if (surface === "thread") expect(metrics.width).toBeLessThan(500);
90+
expect(metrics.scrollWidth).toBeLessThanOrEqual(metrics.width + 1);
91+
expect(metrics.tableWidth).toBeLessThanOrEqual(metrics.width + 1);
92+
expect(metrics.alignments.every((value) => value === "top")).toBe(true);
93+
expect(metrics.labelLines).toBe(1);
94+
expect(metrics.rowHeight).toBeGreaterThan(metrics.lineHeight * 2);
95+
expect(metrics.pageScrollWidth).toBe(metrics.pageWidth);
96+
await expect(block.locator("tbody tr")).toHaveCount(5);
97+
await expect(block.getByRole("link")).toHaveCount(2);
98+
for (const link of await block.getByRole("link").all()) {
99+
await expect(link).toHaveAttribute("href", url);
100+
}
101+
await expect(block.locator("code")).toHaveText("git diff --check");
102+
await expect(
103+
block.locator("td").filter({ hasText: token }).first(),
104+
).toHaveText(token);
105+
await expect(markdown.locator("p").last()).toHaveText(
106+
"Surrounding paragraph stays in the message layout.",
107+
);
108+
});
109+
}
110+
111+
test("unavoidably wide tables scroll locally without losing cells", async ({
112+
page,
113+
}) => {
114+
await installMockBridge(page);
115+
await page.goto("/");
116+
await page.getByTestId("channel-general").click();
117+
await page.waitForFunction(() =>
118+
window.__BUZZ_E2E_HAS_MOCK_LIVE_SUBSCRIPTION__?.({
119+
channelName: "general",
120+
}),
121+
);
122+
const columns = Array.from({ length: 40 }, (_, i) => `C${i}`);
123+
const wide = [columns, columns.map(() => "---"), columns]
124+
.map((row) => `| ${row.join(" | ")} |`)
125+
.join("\n");
126+
await page.evaluate((body) => {
127+
window.__BUZZ_E2E_EMIT_MOCK_MESSAGE__?.({
128+
channelName: "general",
129+
content: `Wide table fixture\n\n${body}`,
130+
});
131+
}, wide);
132+
const block = page
133+
.getByTestId("message-timeline")
134+
.locator(".message-markdown")
135+
.filter({ hasText: "Wide table fixture" })
136+
.locator("[data-table-block]");
137+
await expect(block.locator("td")).toHaveCount(40);
138+
const metrics = await block.evaluate((element) => {
139+
element.scrollLeft = element.scrollWidth;
140+
return {
141+
width: element.clientWidth,
142+
scrollWidth: element.scrollWidth,
143+
scrollLeft: element.scrollLeft,
144+
overflow: getComputedStyle(element).overflowX,
145+
pageWidth: document.documentElement.clientWidth,
146+
pageScrollWidth: document.documentElement.scrollWidth,
147+
};
148+
});
149+
expect(metrics.scrollWidth).toBeGreaterThan(metrics.width);
150+
expect(metrics.scrollLeft).toBeGreaterThan(0);
151+
expect(metrics.overflow).toBe("auto");
152+
expect(metrics.pageScrollWidth).toBe(metrics.pageWidth);
153+
await expect(block.locator("td").last()).toHaveText("C39");
154+
});

‎desktop/tests/e2e/messaging.spec.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ test("long autolink wraps without widening the timeline", async ({ page }) => {
454454
.toBeLessThanOrEqual(0);
455455
});
456456

457-
test("markdown tables overflow wide content and fill the message when narrow", async ({
457+
test("markdown tables wrap long prose and fill the message when narrow", async ({
458458
page,
459459
}) => {
460460
await page.setViewportSize({ width: 900, height: 600 });
@@ -497,13 +497,15 @@ test("markdown tables overflow wide content and fill the message when narrow", a
497497
await expect(wideTable).toBeVisible();
498498
await expect(narrowTable).toBeVisible();
499499

500+
// Long prose should wrap, not force horizontal scrolling. Unavoidable
501+
// many-column overflow is covered separately in markdown-tables.spec.ts.
500502
await expect
501503
.poll(() =>
502504
wideTable.evaluate(
503505
(element) => element.scrollWidth - element.clientWidth,
504506
),
505507
)
506-
.toBeGreaterThan(1);
508+
.toBeLessThanOrEqual(1);
507509
await expect
508510
.poll(() =>
509511
narrowTable.evaluate((element) => {

‎docs/nips/NIP-FI.md‎

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,107 @@ This exemption applies solely to the Git credential-helper proof pattern on
582582
these three endpoints. It is not a precedent for any other surface. A client
583583
change that enables per-request signing supersedes this exemption.
584584

585+
### Media possession-proof exception (Blossom, kind 24242)
586+
587+
Kind `24242` Blossom auth events are accepted as the NIP-FI pairing possession
588+
proof for media routes **only**. This is a media-only, operation-specific
589+
alternative possession format — not a general "signed Nostr event" escape hatch
590+
and not precedent for any other surface. Any future alternative proof format
591+
requires an explicit axis-by-axis security review covering: payload/resource
592+
binding, method/operation scope, audience/tenant scope, freshness, signature/key
593+
pairing, transport cardinality, and cross-endpoint replay. Per-request NIP-98
594+
support supersedes this exception when available.
595+
596+
#### Scope fence
597+
598+
Kind-24242 proofs are valid **only** on the following routes and operations:
599+
600+
| Proof type (`t` tag) | Valid route | Method |
601+
|---|---|---|
602+
| `upload` | `PUT /upload` (and temporary alias `PUT /media/upload` until that alias is removed) | PUT |
603+
| `get` | `GET /media/{hash…}`, `HEAD /media/{hash…}` | GET, HEAD |
604+
605+
No other protected route may accept a kind-24242 proof. A kind-24242 event
606+
presented on any other route MUST be rejected as `evidence_rejected`.
607+
608+
#### Upload proofs
609+
610+
Upload proofs MUST carry exactly one `x` tag whose value is the lowercase
611+
hexadecimal SHA-256 of the exact consumed request body bytes. The signed `x`
612+
MUST be verified against the completed body; temporal admission is checked
613+
before the body is consumed.
614+
615+
Upload proofs MUST carry exactly one `server` tag whose value matches the
616+
request's already-resolved tenant host. An upload proof with an absent or
617+
mismatched `server` tag MUST be rejected as `evidence_rejected`.
618+
619+
#### Read proofs
620+
621+
Read proofs MAY be host-wide: no `x` tag is required for reads, and a valid
622+
read proof authorizes reads of any blob on the one bound tenant host.
623+
624+
Read proofs MUST carry exactly one `server` tag whose value matches the
625+
request's already-resolved tenant host. A read proof with an absent or
626+
mismatched `server` tag MUST be rejected as `evidence_rejected`.
627+
628+
If an `x` tag is present on a read proof: there MUST be exactly one, and it
629+
MUST match the requested parent blob hash. A mismatched `x` tag MUST be
630+
rejected as `evidence_rejected`.
631+
632+
> **Named residual:** within a window of at most 60 seconds from minting (plus
633+
> a bounded 5-second future-skew allowance), a captured full header set allows
634+
> reading any media blob on exactly one tenant host. This access is read-only,
635+
> membership-checked, and revocable via assertion expiry or deny-map
636+
> enforcement. It is not state-changing and does not cross tenant boundaries.
637+
638+
#### Freshness
639+
640+
The following freshness rules apply to all kind-24242 proofs (upload and read):
641+
642+
- `created_at <= now + 5s` — bounded future skew; a proof dated more than 5
643+
seconds in the future MUST be rejected as `evidence_rejected`.
644+
- `now - created_at <= 60s` — a proof older than 60 seconds MUST be rejected
645+
as `evidence_rejected`.
646+
- Exactly one `expiration` tag MUST be present, MUST be valid (strictly in the
647+
future at admission time), and MUST satisfy `expiration <= created_at + 60s`.
648+
An absent, duplicate, expired, or out-of-range `expiration` tag MUST be
649+
rejected as `evidence_rejected`.
650+
651+
#### Transport and cardinality
652+
653+
The following cardinality rules apply to all kind-24242 proofs:
654+
655+
- A missing `Authorization` header field MUST be treated as `missing_evidence`.
656+
Repeated, comma-combined, empty, malformed, or wrong-scheme `Authorization`
657+
values MUST be rejected as `evidence_rejected`.
658+
- Exactly one `t` tag MUST be present. A missing, duplicate, or unrecognized
659+
`t` value MUST be rejected as `evidence_rejected`.
660+
- Exactly one `expiration` tag MUST be present (see Freshness above).
661+
- Exactly one `server` tag MUST be present on all kind-24242 proofs (see
662+
Upload proofs and Read proofs above).
663+
- If `x` is present, exactly one instance is permitted (see Upload proofs and
664+
Read proofs above).
665+
- Malformed, empty, duplicate, or conflicting instances of any of these fields
666+
MUST be rejected as `evidence_rejected`.
667+
668+
#### Per-request pairing
669+
670+
Every kind-24242 proof MUST be subject to the full NIP-FI per-request pairing
671+
requirement: full assertion verification, exact key equality between the
672+
assertion's `nostr_pubkey` claim and the kind-24242 event's public key, and
673+
deny-map enforcement (see Admission procedure, steps 1–5).
674+
675+
The effectiveness of deny-map enforcement is contingent on the real
676+
issuer-scoped deny map. Until that map is operational, the stub implementation
677+
constitutes a **known gap** in this section's security guarantees.
678+
679+
#### Compliance note
680+
681+
The implementation as of PR #7264 pairs via a permissive Blossom verifier and
682+
is explicitly non-compliant with this section. The named gaps are:
683+
multi-tag acceptance, a 3600-second proof window, and an optional `server`
684+
tag. These are resolved when the bounded hardening task lands.
685+
585686
### Request format
586687

587688
Each protected HTTP request MUST present both of the following:
@@ -739,7 +840,7 @@ deployment-local identifiers. [FI-TRACE-DISCOVERY-PRIVATE]
739840
| `FI-TRACE-DEPENDENCY-FAIL-CLOSED` | An unreadable JWKS snapshot denies `authorization_unavailable`; no degraded Nostr-only access. |
740841
| `FI-TRACE-LEASE-BOUND` | A session closes at its earliest deadline; equality at any deadline is expired. |
741842
| `FI-TRACE-DENY-SET` | A pubkey in the deny set is denied `authorization_denied` on admission until `now >= until`; an expired or absent entry does not deny; a past-`until` command closes sessions — absent an active same-key entry it creates no future denial, while an active entry remains unchanged under the merge rule; a deny-set-full command is rejected `503` without closing sessions and without removing any existing entry; capacity is evaluated per issuer — one issuer's capacity exhaustion MUST NOT reject another issuer's command; a connection that passes the deny-set check before a concurrent deny-entry insertion but completes admission after MUST still be terminated (the session's proven `k` is registered before the deny-set check, ensuring the close scan catches it); two overlapping commands for the same `(iss, pubkey)` in either delivery order result in `until = max(until_A, until_B)` — delivery order does not shorten the longer deny; a past-`until` command arriving over an active entry leaves the active entry's `until` unchanged; a successful disconnect responds `{"disconnected": true}` regardless of how many sessions were closed; the deny entry applies across all communities served by the relay under that issuer. |
742-
| `FI-TRACE-HTTP-INGRESS` | A protected HTTP request with both valid headers and matching pubkeys is admitted; absent, mismatched, or invalid assertion or NIP-98 event denies; a request presenting only one of the two denies; an active deny-set entry denies; a route that cannot be classified as exempt is treated as protected; repeated, comma-combined, wrong-scheme, or alternative-credential `Authorization` fields deny; an authorization-relevant body without exactly one matching `payload` tag denies; the NIP-FI administrative API is not a protected surface. |
843+
| `FI-TRACE-HTTP-INGRESS` | A protected HTTP request with both valid headers and matching pubkeys is admitted; absent, mismatched, or invalid assertion or NIP-98 event denies; a request presenting only one of the two denies; an active deny-set entry denies; a route that cannot be classified as exempt is treated as protected; repeated, comma-combined, wrong-scheme, or alternative-credential `Authorization` fields deny `evidence_rejected`; a missing `Authorization` field denies `missing_evidence`; an authorization-relevant body without exactly one matching `payload` tag denies; the NIP-FI administrative API is not a protected surface. For kind-24242 (Blossom) proofs on media routes: a `t=upload` proof with valid `x`, `server`, `expiration`, and freshness is admitted on `PUT /upload`; a `t=get` proof with valid `server`, `expiration`, and freshness is admitted on `GET\|HEAD /media/{hash…}`; a kind-24242 proof on any other route denies; an upload proof with absent or mismatched `server` tag denies; a read proof with absent or mismatched `server` tag denies; a proof with a duplicate, missing, or out-of-range `expiration` tag denies; a proof dated more than 5 seconds in the future denies; a proof older than 60 seconds denies; key mismatch between assertion `nostr_pubkey` and the kind-24242 event pubkey denies; an active deny-set entry denies. |
743844
| `FI-TRACE-DENIAL-ORACLE` | Each public-class row produces its exact fixed bytes; all private-state rows compare byte-identical. |
744845
| `FI-TRACE-DISCOVERY-PRIVATE` | Complete discovery bytes do not expose issuer, audience, or deployment-private state. |
745846
| `FI-TRACE-CROSS-DOMAIN-COLLISION` | Equal `sub` values under different `iss` values remain distinct identities. |

0 commit comments

Comments
 (0)