Skip to content

Commit 02a8367

Browse files
committed
Verify SHA256 hash of typst executable
1 parent e6dbe2e commit 02a8367

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

bot/exts/fun/typst.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,18 @@ async def _ensure_typst_executable(self) -> None:
120120
async def _download_typst_executable(self) -> None:
121121
if not Config.typst_archive_url:
122122
raise ValueError("Trying to download Typst but the archive URL isn't set")
123+
if not Config.typst_archive_sha256:
124+
raise ValueError("Trying to download Typst but the archive hash isn't set")
123125
async with self.bot.http_session.get(
124126
Config.typst_archive_url, raise_for_status=True
125127
) as response:
126128
arc_data = await response.read()
129+
digest = hashlib.sha256(arc_data).hexdigest()
130+
if digest != Config.typst_archive_sha256:
131+
raise ValueError(
132+
f"Retrieved archive doesn't match hash {Config.typst_archive_sha256}; "
133+
f"instead got file with size {len(arc_data)} and hash {digest}"
134+
)
127135
log.info("Retrieved Typst archive, unpacking")
128136
typst_executable = archive_retrieve_file(
129137
arc_data,

0 commit comments

Comments
 (0)