-
Notifications
You must be signed in to change notification settings - Fork 194
feat(fe): permissionless app metadata for the authorize flow #4221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
866f561
feat(fe): permissionless app metadata for the authorize flow
claude debbb43
fix(fe): harden app-metadata fetching per review feedback
claude fd6faf9
fix(fe): cancel oversize/non-200 metadata streams and align origin docs
claude c3108bf
fix(fe): reject malformed-UTF-8 metadata and fall back on broken logos
claude f2f17b2
fix(fe): keep app-provided names out of unsaveable account labels
claude dcf8827
fix(fe): only name the app where its origin is shown, cover the timeout
claude 4ee96e9
fix(fe): stop stripping the zero-width joiners names legitimately use
claude 4cd337f
fix(fe): don't hide scheme or port in the origin trust anchor
claude b339a81
docs: make the app-metadata spec match what the code actually validates
claude c82437c
Merge branch 'main' into arshavir/charming-knuth-32obpn
aterga 2eb1146
feat(fe): source app metadata from the derivation origin, validate it…
claude 6d95347
fix(fe): render app logos from a re-encoded blob, not a data URL
claude 826858d
fix(fe): raise the logo size cap to 1 MiB
claude 130f460
fix(fe): stream bodies into blobs, and stop refusing legitimate bidi …
claude c6812c1
refactor(fe): carry only the content type onto the capped blob
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| import { get } from "svelte/store"; | ||
| import { beforeEach, expect, test, vi } from "vitest"; | ||
| import { | ||
| getAppMetadataStore, | ||
| resetAppMetadataStores, | ||
| } from "$lib/stores/app-metadata.store"; | ||
| import { fetchAppMetadata, type AppMetadata } from "$lib/utils/appMetadata"; | ||
|
|
||
| vi.mock("$lib/utils/appMetadata", () => ({ | ||
| fetchAppMetadata: vi.fn(), | ||
| })); | ||
|
|
||
| // The curated dapps list reads canister config that is only available in the | ||
| // browser; stub it with a single known dapp. | ||
| vi.mock("$lib/legacy/flows/dappsExplorer/dapps", () => ({ | ||
| getDapps: () => [ | ||
| { | ||
| hasOrigin: (origin: string) => origin === "https://known.example.com", | ||
| name: "Known App", | ||
| oneLiner: "A curated app", | ||
| logoSrc: "/known-logo.png", | ||
| }, | ||
| ], | ||
| })); | ||
|
|
||
| const fetchAppMetadataMock = vi.mocked(fetchAppMetadata); | ||
|
|
||
| const pending = (): Promise<AppMetadata | undefined> => new Promise(() => {}); | ||
|
|
||
| beforeEach(() => { | ||
| resetAppMetadataStores(); | ||
| fetchAppMetadataMock.mockReset(); | ||
| }); | ||
|
|
||
| test("should fall back to the curated dapps list while fetching", () => { | ||
| fetchAppMetadataMock.mockReturnValue(pending()); | ||
|
|
||
| const store = getAppMetadataStore("https://known.example.com"); | ||
|
|
||
| expect(get(store)).toEqual({ | ||
| name: "Known App", | ||
| description: "A curated app", | ||
| logo: "/known-logo.png", | ||
| }); | ||
| }); | ||
|
|
||
| test("should fall back to empty metadata for unknown origins", () => { | ||
| fetchAppMetadataMock.mockReturnValue(pending()); | ||
|
|
||
| const store = getAppMetadataStore("https://unknown.example.com"); | ||
|
|
||
| expect(get(store)).toEqual({}); | ||
| }); | ||
|
|
||
| test("should replace the fallback wholesale once metadata is fetched", async () => { | ||
| fetchAppMetadataMock.mockResolvedValue({ name: "Self-Published App" }); | ||
|
|
||
| const store = getAppMetadataStore("https://known.example.com"); | ||
|
|
||
| await vi.waitFor(() => | ||
| expect(get(store)).toEqual({ name: "Self-Published App" }), | ||
| ); | ||
| expect(fetchAppMetadataMock).toHaveBeenCalledExactlyOnceWith( | ||
| "https://known.example.com", | ||
| ); | ||
| }); | ||
|
|
||
| test("should keep the fallback when the origin serves no metadata", async () => { | ||
| fetchAppMetadataMock.mockResolvedValue(undefined); | ||
|
|
||
| const store = getAppMetadataStore("https://known.example.com"); | ||
|
|
||
| // Give the resolved promise a chance to (incorrectly) overwrite the value. | ||
| await new Promise((resolve) => setTimeout(resolve)); | ||
| expect(get(store)).toEqual({ | ||
| name: "Known App", | ||
| description: "A curated app", | ||
| logo: "/known-logo.png", | ||
| }); | ||
| }); | ||
|
|
||
| test("should fetch once per origin and share the store", () => { | ||
| fetchAppMetadataMock.mockReturnValue(pending()); | ||
|
|
||
| const first = getAppMetadataStore("https://app.example.com"); | ||
| const second = getAppMetadataStore("https://app.example.com"); | ||
| const other = getAppMetadataStore("https://other.example.com"); | ||
|
|
||
| expect(first).toBe(second); | ||
| expect(other).not.toBe(first); | ||
| expect(fetchAppMetadataMock).toHaveBeenCalledTimes(2); | ||
| expect(fetchAppMetadataMock).toHaveBeenCalledWith("https://app.example.com"); | ||
| expect(fetchAppMetadataMock).toHaveBeenCalledWith( | ||
| "https://other.example.com", | ||
| ); | ||
| }); | ||
|
|
||
| test("should update subscribers that subscribed before the fetch resolved", async () => { | ||
| let resolveFetch: (metadata: AppMetadata | undefined) => void = () => {}; | ||
| fetchAppMetadataMock.mockReturnValue( | ||
| new Promise((resolve) => (resolveFetch = resolve)), | ||
| ); | ||
|
|
||
| const store = getAppMetadataStore("https://app.example.com"); | ||
| const seen: AppMetadata[] = []; | ||
| const unsubscribe = store.subscribe((value) => seen.push(value)); | ||
|
|
||
| resolveFetch({ name: "Late App" }); | ||
| await vi.waitFor(() => expect(seen).toHaveLength(2)); | ||
| expect(seen[0]).toEqual({}); | ||
| expect(seen[1]).toEqual({ name: "Late App" }); | ||
| unsubscribe(); | ||
| }); | ||
|
|
||
| test("should fetch again after the cache is reset", () => { | ||
| fetchAppMetadataMock.mockResolvedValue({ name: "App" }); | ||
|
|
||
| getAppMetadataStore("https://app.example.com"); | ||
| resetAppMetadataStores(); | ||
| getAppMetadataStore("https://app.example.com"); | ||
|
|
||
| expect(fetchAppMetadataMock).toHaveBeenCalledTimes(2); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /** | ||
| * Per-origin display metadata (name, description, logo) for apps that sign in | ||
| * with Internet Identity, e.g. shown on the authorize flow screens. | ||
| * | ||
| * The metadata is sourced permissionlessly from the app itself: every origin | ||
| * can serve a `/.well-known/ii-app-metadata` file (see | ||
| * {@link fetchAppMetadata}). The curated dapps list shipped with II is only | ||
| * used as a fallback while apps migrate to the well-known file, and a valid | ||
| * file always replaces the curated entry wholesale — the app owns its own | ||
| * presentation. When neither source has data, consumers fall back to the | ||
| * origin's hostname. | ||
| */ | ||
| import { writable, type Readable } from "svelte/store"; | ||
| import { fetchAppMetadata, type AppMetadata } from "$lib/utils/appMetadata"; | ||
| import { getDapps } from "$lib/legacy/flows/dappsExplorer/dapps"; | ||
|
|
||
| export type { AppMetadata } from "$lib/utils/appMetadata"; | ||
|
|
||
| const storeByOrigin = new Map<string, Readable<AppMetadata>>(); | ||
|
|
||
| /** Fallback display metadata from the curated dapps list shipped with II. */ | ||
| const knownDappMetadata = (origin: string): AppMetadata => { | ||
| const dapp = getDapps().find((dapp) => dapp.hasOrigin(origin)); | ||
| return dapp === undefined | ||
| ? {} | ||
| : { name: dapp.name, description: dapp.oneLiner, logo: dapp.logoSrc }; | ||
| }; | ||
|
|
||
| /** | ||
| * Reactive display metadata for the given origin. | ||
| * | ||
| * Resolves synchronously to the curated-list fallback (so known dapps never | ||
| * flash an unbranded screen) and updates in place once the origin's own | ||
| * `/.well-known/ii-app-metadata` file has been fetched and validated. The | ||
| * fetch runs once per origin per page load; all subscribers share the result. | ||
| * | ||
| * @param origin Origin as shown to the user (e.g. the postMessage channel | ||
| * origin), not the derivation origin (which may be remapped). | ||
| */ | ||
| export const getAppMetadataStore = (origin: string): Readable<AppMetadata> => { | ||
| const existing = storeByOrigin.get(origin); | ||
| if (existing !== undefined) { | ||
| return existing; | ||
| } | ||
| const { subscribe, set } = writable<AppMetadata>(knownDappMetadata(origin)); | ||
| const store = { subscribe }; | ||
| storeByOrigin.set(origin, store); | ||
| void fetchAppMetadata(origin).then((metadata) => { | ||
| if (metadata !== undefined) { | ||
| set(metadata); | ||
| } | ||
| }); | ||
| return store; | ||
| }; | ||
|
|
||
| /** Test-only: drop all cached per-origin stores so fetches run again. */ | ||
| export const resetAppMetadataStores = (): void => { | ||
| storeByOrigin.clear(); | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.