refactor: switch to using verifyCid to check if module is valid

This commit is contained in:
Derrick Hammer 2023-07-04 02:05:56 -04:00
parent dd27520a8e
commit 2671fa35a7
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 3 additions and 3 deletions

View File

@ -10,7 +10,7 @@ import {
objAsString, objAsString,
sha512, sha512,
} from "@lumeweb/libkernel"; } from "@lumeweb/libkernel";
import { deriveChildKey, downloadObject } from "@lumeweb/libweb"; import { deriveChildKey, downloadObject, verifyCid } from "@lumeweb/libweb";
import type { moduleQuery, presentKeyData } from "@lumeweb/libkernel/module"; import type { moduleQuery, presentKeyData } from "@lumeweb/libkernel/module";
import { readableStreamToUint8Array } from "binconv"; import { readableStreamToUint8Array } from "binconv";
@ -295,14 +295,14 @@ function handleModuleCall(
} }
if ( if (
typeof event.data.data.module !== "string" || typeof event.data.data.module !== "string" ||
event.data.data.module.length != 46 !verifyCid(event.data.data.module)
) { ) {
logErr("moduleCall", "received moduleCall with malformed module"); logErr("moduleCall", "received moduleCall with malformed module");
respondErr( respondErr(
event, event,
messagePortal, messagePortal,
isWorker, isWorker,
"'module' field in moduleCall is expected to be a base64 skylink", "'module' field in moduleCall is expected to be a base58 encoded blake3 hash + filesize",
); );
return; return;
} }