fix(skins): skip bundled skins in the skin store index instead of rejecting it

An index entry whose id is bundled with the client (a protected built-in id or a builtin.-prefixed id) is now dropped from the store catalog instead of failing the whole index with SKIN_STORE_INVALID. Invalid schema, illegal ids, duplicate ids and unsafe repositories still reject the index. This lets the store keep listing every other skin even while the public index still contains a skin that is now bundled.
This commit is contained in:
OddTurtleHead committed 2026-12-04 13:56:09 +08:00
1 parent 25b0a01ae7
commit f64e42429a
2 files changed
+36 -4

No files matched your search

+10 -4
View File
@@ -27,12 +27,18 @@ function parseIndex(value: unknown): { id: string; repository: string }[] {
const root = record(value);
if (root.schemaVersion !== 1 || !Array.isArray(root.skins) || root.skins.length > 50) return fail("SKIN_STORE_INVALID");
const seen = new Set<string>();
return root.skins.map(item => {
const sources: { id: string; repository: string }[] = [];
for (const item of root.skins) {
const entry = record(item);
if (typeof entry.id !== "string" || !ID.test(entry.id) || isBuiltinSkinId(entry.id) || entry.id.startsWith("builtin.") || seen.has(entry.id)) return fail("SKIN_STORE_INVALID");
if (typeof entry.id !== "string" || !ID.test(entry.id) || seen.has(entry.id)) return fail("SKIN_STORE_INVALID");
seen.add(entry.id);
return { id: entry.id, repository: skinRepository(entry.repository) };
});
// Skins that ship with the client are not installable from the store. Skip
// such an index entry instead of rejecting the whole index, so an index
// that still lists a newly bundled skin keeps working for every other skin.
if (isBuiltinSkinId(entry.id) || entry.id.startsWith("builtin.")) continue;
sources.push({ id: entry.id, repository: skinRepository(entry.repository) });
}
return sources;
}
function parseMetadata(value: unknown, id: string): SkinStoreMetadata {
+26
View File
@@ -102,6 +102,32 @@ test("store rejects unsafe repositories, malformed/duplicate indexes and isolate
assert.equal(result.entries[0].metadata, null);
assert.equal(result.entries[0].error, "SKIN_STORE_UNAVAILABLE");
});
test("store skips index entries for skins bundled with the client and keeps the other skins", async () => {
const f = fixture();
f.index.skins.unshift({ id: "community.ts3-classic-console", repository });
f.index.skins.push({ id: "community.kaak-voice", repository }, { id: "builtin.future-pack", repository: "not a repository" });
const result = await new SkinStore("0.3.4-dev.0", f.fetcher).list();
assert.deepEqual(result.entries.map(entry => entry.id), [manifest.id], "bundled and builtin.-prefixed entries are dropped, other skins stay");
assert.equal(result.entries[0].error, null);
assert.ok(!f.calls.some(url => url.includes("classic") || url.includes("kaak") || url.includes("future-pack")), "skipped entries are never downloaded");
});
test("store still rejects malformed, duplicate or unsafe index entries after skipping bundled skins", async () => {
const cases: unknown[] = [
{ schemaVersion: 2, skins: [{ id: manifest.id, repository }] },
{ schemaVersion: 1, skins: "community.store-test" },
{ schemaVersion: 1, skins: [{ id: "Bad Id", repository }] },
{ schemaVersion: 1, skins: [{ id: manifest.id, repository }, { id: manifest.id, repository }] },
{ schemaVersion: 1, skins: [{ id: "community.ts3-classic-console", repository }, { id: "community.ts3-classic-console", repository }] },
{ schemaVersion: 1, skins: [{ id: "community.ts3-classic-console", repository }, { id: manifest.id, repository: "https://example.com/skin" }] },
{ schemaVersion: 1, skins: [null] },
];
for (const index of cases) {
const f = fixture();
f.overrides.set(SKIN_STORE_INDEX_URL, () => Response.json(index));
await assert.rejects(new SkinStore("0.3.4-dev.0", f.fetcher).list(), errorCode("SKIN_STORE_INVALID"), JSON.stringify(index));
}
});
test("store bounds downloads and validates checksum, package identity and metadata before saving", async t => {
const f = fixture(), store = new SkinStore("0.2.8", f.fetcher), skins = await registry(t);
const entry = (await store.list()).entries[0], input = { id: entry.id, revision: entry.revision, installedVersion: null };