@coflyn/mori 1.2.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/bundle-signing-key.pub.pem +3 -0
- package/engine.js +99 -53
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,15 @@ All notable changes to the Mori CLI (`@coflyn/mori`) will be documented in this
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.3.0] - 2026-12-06
|
|
9
|
+
|
|
10
|
+
### Security
|
|
11
|
+
- **Signed Mori Core engine updates**: The CLI now checks an Ed25519 signature (`bundle.js.sig`) before it installs, updates, rolls back or loads the Mori Core scraper engine. A bundle with a missing or invalid signature is refused and never run. The public key ships inside this package (`bundle-signing-key.pub.pem`), so a change on GitHub alone cannot alter what the CLI accepts.
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
- An engine installed by an older CLI version has no signature. It is reinstalled automatically on the next update check, or manually with `/update` or `/engine`.
|
|
15
|
+
- `/rollback` can only restore engine versions that are signed. Versions published before 1.3.0 are refused.
|
|
16
|
+
|
|
8
17
|
## [1.2.2] - 2026-11-17
|
|
9
18
|
|
|
10
19
|
### Fixed
|
package/engine.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
|
+
import crypto from "crypto";
|
|
2
3
|
import os from "os";
|
|
3
4
|
import path from "path";
|
|
4
5
|
import { exec, execSync } from "child_process";
|
|
@@ -436,6 +437,7 @@ export function resetMori() {
|
|
|
436
437
|
HISTORY_PATH,
|
|
437
438
|
OTA_BUNDLE_PATH,
|
|
438
439
|
OTA_META_PATH,
|
|
440
|
+
`${OTA_BUNDLE_PATH}.sig`,
|
|
439
441
|
SCRAPR_BUNDLE_PATH,
|
|
440
442
|
SCRAPR_META_PATH,
|
|
441
443
|
];
|
|
@@ -450,6 +452,62 @@ export function resetMori() {
|
|
|
450
452
|
|
|
451
453
|
export const OTA_VERSION_URL = `https://raw.githubusercontent.com/${GITHUB_REPO}/main/public/scrapers-version.json`;
|
|
452
454
|
export const OTA_BUNDLE_URL = `https://raw.githubusercontent.com/${GITHUB_REPO}/main/public/js/scrapers/bundle.js`;
|
|
455
|
+
const OTA_SIG_PATH = `${OTA_BUNDLE_PATH}.sig`;
|
|
456
|
+
|
|
457
|
+
// Remote bundles are only run if signed with the maintainer's Ed25519 key.
|
|
458
|
+
// The public key ships inside this npm package, so a push to GitHub alone cannot change it.
|
|
459
|
+
const BUNDLE_PUBLIC_KEY_PATH = path.join(__dirname, "bundle-signing-key.pub.pem");
|
|
460
|
+
|
|
461
|
+
export function isBundleSignatureValid(code, sigB64) {
|
|
462
|
+
try {
|
|
463
|
+
if (!code || !sigB64) return false;
|
|
464
|
+
const publicKey = crypto.createPublicKey(fs.readFileSync(BUNDLE_PUBLIC_KEY_PATH, "utf8"));
|
|
465
|
+
return crypto.verify(null, Buffer.from(code, "utf8"), publicKey, Buffer.from(String(sigB64).trim(), "base64"));
|
|
466
|
+
} catch (_) {
|
|
467
|
+
return false;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* Downloads bundle.js and bundle.js.sig from the same base URL and returns the code
|
|
473
|
+
* only if the signature is valid. Throws otherwise, so nothing unsigned is ever saved.
|
|
474
|
+
*/
|
|
475
|
+
async function fetchSignedBundle(bundleUrl, timeoutMs, userAgent) {
|
|
476
|
+
const opts = (ms) => ({
|
|
477
|
+
signal: AbortSignal.timeout(ms),
|
|
478
|
+
headers: { "User-Agent": userAgent, "Cache-Control": "no-cache" },
|
|
479
|
+
});
|
|
480
|
+
const [bundleRes, sigRes] = await Promise.all([
|
|
481
|
+
fetch(bundleUrl, opts(timeoutMs)),
|
|
482
|
+
fetch(`${bundleUrl}.sig`, opts(10000)),
|
|
483
|
+
]);
|
|
484
|
+
if (!bundleRes.ok) throw new Error(`Failed to download Mori bundle (HTTP ${bundleRes.status})`);
|
|
485
|
+
if (!sigRes.ok) throw new Error("This Mori Engine version is not signed. Refusing to install it.");
|
|
486
|
+
const bundleText = await bundleRes.text();
|
|
487
|
+
const sig = (await sigRes.text()).trim();
|
|
488
|
+
if (!bundleText || bundleText.length < 5000) throw new Error("Invalid Mori bundle payload received.");
|
|
489
|
+
if (!isBundleSignatureValid(bundleText, sig)) {
|
|
490
|
+
throw new Error("Mori Engine signature check failed. Refusing to install it.");
|
|
491
|
+
}
|
|
492
|
+
return { bundleText, sig };
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
function writeVerifiedBundle(bundleText, sig) {
|
|
496
|
+
if (!fs.existsSync(OTA_DIR)) fs.mkdirSync(OTA_DIR, { recursive: true });
|
|
497
|
+
fs.writeFileSync(OTA_BUNDLE_PATH, bundleText, "utf8");
|
|
498
|
+
fs.writeFileSync(OTA_SIG_PATH, sig + "\n", "utf8");
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function isInstalledBundleSigned() {
|
|
502
|
+
try {
|
|
503
|
+
return isBundleSignatureValid(
|
|
504
|
+
fs.readFileSync(OTA_BUNDLE_PATH, "utf8"),
|
|
505
|
+
fs.readFileSync(OTA_SIG_PATH, "utf8"),
|
|
506
|
+
);
|
|
507
|
+
} catch (_) {
|
|
508
|
+
return false;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
453
511
|
|
|
454
512
|
export function isMoriInstalled() {
|
|
455
513
|
return fs.existsSync(OTA_BUNDLE_PATH);
|
|
@@ -492,21 +550,8 @@ export async function downloadMoriEngine(onProgress) {
|
|
|
492
550
|
const meta = await metaRes.json();
|
|
493
551
|
|
|
494
552
|
if (onProgress) onProgress("Downloading Mori Engine bundle (~80 KB)...");
|
|
495
|
-
const
|
|
496
|
-
|
|
497
|
-
headers: { "User-Agent": "Mori-CLI", "Cache-Control": "no-cache" },
|
|
498
|
-
});
|
|
499
|
-
if (!bundleRes.ok) throw new Error(`Failed to download Mori bundle (HTTP ${bundleRes.status})`);
|
|
500
|
-
const bundleText = await bundleRes.text();
|
|
501
|
-
if (!bundleText || bundleText.length < 5000) {
|
|
502
|
-
throw new Error("Invalid Mori bundle payload received.");
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
if (!fs.existsSync(OTA_DIR)) {
|
|
506
|
-
fs.mkdirSync(OTA_DIR, { recursive: true });
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
fs.writeFileSync(OTA_BUNDLE_PATH, bundleText, "utf8");
|
|
553
|
+
const { bundleText, sig } = await fetchSignedBundle(OTA_BUNDLE_URL, 30000, "Mori-CLI");
|
|
554
|
+
writeVerifiedBundle(bundleText, sig);
|
|
510
555
|
fs.writeFileSync(
|
|
511
556
|
OTA_META_PATH,
|
|
512
557
|
JSON.stringify(
|
|
@@ -600,6 +645,9 @@ export function uninstallMoriEngine() {
|
|
|
600
645
|
if (fs.existsSync(OTA_META_PATH)) {
|
|
601
646
|
try { fs.unlinkSync(OTA_META_PATH); } catch (_) {}
|
|
602
647
|
}
|
|
648
|
+
if (fs.existsSync(OTA_SIG_PATH)) {
|
|
649
|
+
try { fs.unlinkSync(OTA_SIG_PATH); } catch (_) {}
|
|
650
|
+
}
|
|
603
651
|
cachedMoriScrapers = null;
|
|
604
652
|
return true;
|
|
605
653
|
}
|
|
@@ -645,26 +693,15 @@ export async function downloadMoriEngineByCommit(commitSha, onProgress) {
|
|
|
645
693
|
const bundleUrl = `https://raw.githubusercontent.com/${GITHUB_REPO}/${commitSha}/public/js/scrapers/bundle.js`;
|
|
646
694
|
const metaUrl = `https://raw.githubusercontent.com/${GITHUB_REPO}/${commitSha}/public/scrapers-version.json`;
|
|
647
695
|
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
headers: { "User-Agent": "Mori-CLI", "Cache-Control": "no-cache" },
|
|
652
|
-
}),
|
|
696
|
+
// Commits from before bundle signing have no .sig and are refused.
|
|
697
|
+
const [{ bundleText, sig }, metaRes] = await Promise.all([
|
|
698
|
+
fetchSignedBundle(bundleUrl, 30000, "Mori-CLI"),
|
|
653
699
|
fetch(metaUrl, {
|
|
654
700
|
signal: AbortSignal.timeout(15000),
|
|
655
701
|
headers: { "User-Agent": "Mori-CLI", "Cache-Control": "no-cache" },
|
|
656
702
|
}).catch(() => null),
|
|
657
703
|
]);
|
|
658
704
|
|
|
659
|
-
if (!bundleRes.ok) {
|
|
660
|
-
throw new Error(`Failed to fetch bundle at commit ${shortSha}: HTTP ${bundleRes.status}`);
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
const bundleText = await bundleRes.text();
|
|
664
|
-
if (!bundleText || bundleText.length < 5000) {
|
|
665
|
-
throw new Error("Downloaded bundle is empty or invalid.");
|
|
666
|
-
}
|
|
667
|
-
|
|
668
705
|
let meta = { scraperVersion: shortSha };
|
|
669
706
|
if (metaRes && metaRes.ok) {
|
|
670
707
|
try {
|
|
@@ -672,11 +709,7 @@ export async function downloadMoriEngineByCommit(commitSha, onProgress) {
|
|
|
672
709
|
} catch (_) {}
|
|
673
710
|
}
|
|
674
711
|
|
|
675
|
-
|
|
676
|
-
fs.mkdirSync(OTA_DIR, { recursive: true });
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
fs.writeFileSync(OTA_BUNDLE_PATH, bundleText, "utf8");
|
|
712
|
+
writeVerifiedBundle(bundleText, sig);
|
|
680
713
|
fs.writeFileSync(
|
|
681
714
|
OTA_META_PATH,
|
|
682
715
|
JSON.stringify(
|
|
@@ -785,25 +818,20 @@ export async function checkForOtaUpdate(force = false) {
|
|
|
785
818
|
|
|
786
819
|
const remoteMeta = await metaRes.json();
|
|
787
820
|
const currentVer = getActiveScraperVersion();
|
|
821
|
+
const needsResign = !isInstalledBundleSigned();
|
|
788
822
|
|
|
789
|
-
if (
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
if (!bundleText || bundleText.length < 5000) {
|
|
799
|
-
return { updated: false, reason: "Invalid bundle payload" };
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
if (!fs.existsSync(OTA_DIR)) {
|
|
803
|
-
fs.mkdirSync(OTA_DIR, { recursive: true });
|
|
823
|
+
if (
|
|
824
|
+
remoteMeta.scraperVersion &&
|
|
825
|
+
(needsResign || remoteMeta.scraperVersion > currentVer)
|
|
826
|
+
) {
|
|
827
|
+
let signed;
|
|
828
|
+
try {
|
|
829
|
+
signed = await fetchSignedBundle(OTA_BUNDLE_URL, 15000, "Mori-CLI-OTA");
|
|
830
|
+
} catch (e) {
|
|
831
|
+
return { updated: false, reason: e.message };
|
|
804
832
|
}
|
|
805
|
-
|
|
806
|
-
|
|
833
|
+
const { bundleText, sig } = signed;
|
|
834
|
+
writeVerifiedBundle(bundleText, sig);
|
|
807
835
|
fs.writeFileSync(
|
|
808
836
|
OTA_META_PATH,
|
|
809
837
|
JSON.stringify(
|
|
@@ -909,8 +937,10 @@ export function loadScraperEngine() {
|
|
|
909
937
|
const localBundlePath = path.join(__dirname, "bundle.js");
|
|
910
938
|
const rootBundlePath = path.join(ROOT_DIR, "public/js/scrapers/bundle.js");
|
|
911
939
|
|
|
912
|
-
// Priority 1: ~/.mori/scrapers-bundle.js
|
|
913
|
-
|
|
940
|
+
// Priority 1: ~/.mori/scrapers-bundle.js (only if its signature checks out)
|
|
941
|
+
const hasCachedBundle = fs.existsSync(OTA_BUNDLE_PATH);
|
|
942
|
+
const cachedBundleSigned = hasCachedBundle && isInstalledBundleSigned();
|
|
943
|
+
if (cachedBundleSigned) {
|
|
914
944
|
try {
|
|
915
945
|
const patchCode = fs.readFileSync(OTA_BUNDLE_PATH, "utf8");
|
|
916
946
|
(0, eval)(patchCode);
|
|
@@ -944,6 +974,11 @@ export function loadScraperEngine() {
|
|
|
944
974
|
} catch (_) {}
|
|
945
975
|
}
|
|
946
976
|
|
|
977
|
+
if (hasCachedBundle && !cachedBundleSigned) {
|
|
978
|
+
throw new Error(
|
|
979
|
+
"Installed Mori Engine is not signed (installed by an older CLI). Run /update or /engine to reinstall it.",
|
|
980
|
+
);
|
|
981
|
+
}
|
|
947
982
|
throw new Error("Mori Engine not installed. Use /engine to install.");
|
|
948
983
|
}
|
|
949
984
|
|
|
@@ -1116,6 +1151,9 @@ export function detectPlatform(rawUrl) {
|
|
|
1116
1151
|
url.includes("tibibox")
|
|
1117
1152
|
)
|
|
1118
1153
|
return "terabox";
|
|
1154
|
+
if (url.includes("soundcloud.com") || url.includes("on.soundcloud.com"))
|
|
1155
|
+
return "soundcloud";
|
|
1156
|
+
if (url.includes("weibo.com") || url.includes("weibo.cn")) return "weibo";
|
|
1119
1157
|
// File hosts & Resolvers (Engine 2: Scrapr)
|
|
1120
1158
|
if (url.includes("mediafire.com")) return "mediafire";
|
|
1121
1159
|
if (url.includes("sfile.mobi") || url.includes("sfile.co")) return "sfile";
|
|
@@ -1483,6 +1521,14 @@ export async function scrapeWithMori(url, platform, serverPreference = "auto") {
|
|
|
1483
1521
|
res = await scrapers.scrapeTeraBox(url);
|
|
1484
1522
|
usedServer = "TeraBox";
|
|
1485
1523
|
break;
|
|
1524
|
+
case "soundcloud":
|
|
1525
|
+
res = await scrapers.scrapeSoundCloud(url);
|
|
1526
|
+
usedServer = "SoundCloud";
|
|
1527
|
+
break;
|
|
1528
|
+
case "weibo":
|
|
1529
|
+
res = await scrapers.scrapeWeibo(url);
|
|
1530
|
+
usedServer = "Weibo";
|
|
1531
|
+
break;
|
|
1486
1532
|
default:
|
|
1487
1533
|
throw new Error(`Platform handler missing for ${platform}`);
|
|
1488
1534
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coflyn/mori",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Universal media downloader CLI. Save anything, from anywhere. No watermarks. No tracking.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"files": [
|
|
12
12
|
"index.js",
|
|
13
13
|
"engine.js",
|
|
14
|
+
"bundle-signing-key.pub.pem",
|
|
14
15
|
"README.md",
|
|
15
16
|
"CHANGELOG.md",
|
|
16
17
|
"LICENSE",
|
|
@@ -42,8 +43,8 @@
|
|
|
42
43
|
"access": "public"
|
|
43
44
|
},
|
|
44
45
|
"dependencies": {
|
|
45
|
-
"@clack/prompts": "^1.
|
|
46
|
-
"linkedom": "^0.18.
|
|
46
|
+
"@clack/prompts": "^1.9.0",
|
|
47
|
+
"linkedom": "^0.18.15",
|
|
47
48
|
"picocolors": "^1.1.1"
|
|
48
49
|
}
|
|
49
50
|
}
|