@emiyakatuz/crispasr-agent-transcriber 0.4.0 → 0.4.1
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/package.json +1 -1
- package/src/installer.js +31 -3
- package/src/release.js +39 -1
package/package.json
CHANGED
package/src/installer.js
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
installMarketplaceEntry,
|
|
21
21
|
removeMarketplaceEntry,
|
|
22
22
|
} from "./marketplace.js";
|
|
23
|
-
import { extractZipSafely, fetchReleaseBundle } from "./release.js";
|
|
23
|
+
import { extractZipSafely, fetchReleaseBundle, normalizePluginPermissions } from "./release.js";
|
|
24
24
|
import { crispasrExecutableName, findCommand, runCommand } from "./system.js";
|
|
25
25
|
|
|
26
26
|
const MARKER_FILE = ".crispasr-installer.json";
|
|
@@ -108,10 +108,14 @@ function removeManagedEntries(targetDir) {
|
|
|
108
108
|
function copyPluginFiles(sourceDir, targetDir) {
|
|
109
109
|
fs.mkdirSync(targetDir, { recursive: true });
|
|
110
110
|
for (const entry of fs.readdirSync(sourceDir)) {
|
|
111
|
-
|
|
111
|
+
const destination = path.join(targetDir, entry);
|
|
112
|
+
// Replace old managed entries rather than merging into previously writable directories.
|
|
113
|
+
fs.rmSync(destination, { recursive: true, force: true });
|
|
114
|
+
fs.cpSync(path.join(sourceDir, entry), destination, {
|
|
112
115
|
recursive: true,
|
|
113
116
|
force: true,
|
|
114
117
|
});
|
|
118
|
+
normalizePluginPermissions(destination);
|
|
115
119
|
}
|
|
116
120
|
}
|
|
117
121
|
|
|
@@ -125,8 +129,9 @@ function writeMarker(targetDir, version, installed = true) {
|
|
|
125
129
|
fs.writeFileSync(
|
|
126
130
|
path.join(targetDir, MARKER_FILE),
|
|
127
131
|
`${JSON.stringify(marker, null, 2)}\n`,
|
|
128
|
-
"utf8",
|
|
132
|
+
{ encoding: "utf8", mode: 0o644 },
|
|
129
133
|
);
|
|
134
|
+
fs.chmodSync(path.join(targetDir, MARKER_FILE), 0o644);
|
|
130
135
|
}
|
|
131
136
|
|
|
132
137
|
function locatePluginSource(extractDir, version) {
|
|
@@ -145,6 +150,15 @@ function locatePluginSource(extractDir, version) {
|
|
|
145
150
|
{ expected: version, actual: manifest.version },
|
|
146
151
|
);
|
|
147
152
|
}
|
|
153
|
+
for (const entry of fs.readdirSync(sourceDir)) {
|
|
154
|
+
if (!MANAGED_ENTRIES.includes(entry) || entry === ".venv") {
|
|
155
|
+
throw new InstallerError(
|
|
156
|
+
"The plugin archive contains an unexpected top-level entry.",
|
|
157
|
+
"invalid_release_bundle",
|
|
158
|
+
{ entry },
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
148
162
|
return sourceDir;
|
|
149
163
|
}
|
|
150
164
|
|
|
@@ -401,6 +415,20 @@ export async function installPlugin(options = {}) {
|
|
|
401
415
|
const sourceDir = locatePluginSource(extractDir, version);
|
|
402
416
|
|
|
403
417
|
progress(`${update ? "Updating" : "Installing"} plugin files...`);
|
|
418
|
+
fs.mkdirSync(targetDir, { recursive: true, mode: 0o755 });
|
|
419
|
+
const targetStat = fs.lstatSync(targetDir);
|
|
420
|
+
if (!targetStat.isDirectory()) {
|
|
421
|
+
throw new InstallerError("The plugin target must be a directory.", "unsafe_target");
|
|
422
|
+
}
|
|
423
|
+
// Keep private roots private: remove shared write access without exposing user data.
|
|
424
|
+
const targetMode = (targetStat.mode & 0o755) | 0o700;
|
|
425
|
+
fs.chmodSync(targetDir, targetMode);
|
|
426
|
+
if (process.platform !== "win32" &&
|
|
427
|
+
(fs.lstatSync(targetDir).mode & 0o7777) !== targetMode) {
|
|
428
|
+
throw new InstallerError("Could not secure the plugin directory.", "unsafe_target", {
|
|
429
|
+
target: targetDir,
|
|
430
|
+
});
|
|
431
|
+
}
|
|
404
432
|
if (readMarker(targetDir)) {
|
|
405
433
|
removeManagedEntries(targetDir);
|
|
406
434
|
}
|
package/src/release.js
CHANGED
|
@@ -80,10 +80,48 @@ export function extractZipSafely(archivePath, destination) {
|
|
|
80
80
|
const entries = archive.getEntries();
|
|
81
81
|
for (const entry of entries) {
|
|
82
82
|
assertSafeArchiveEntry(entry.entryName);
|
|
83
|
+
const type = (entry.attr >>> 16) & 0o170000;
|
|
84
|
+
const expectedType = entry.isDirectory ? 0o040000 : 0o100000;
|
|
85
|
+
if (type !== 0 && type !== expectedType) {
|
|
86
|
+
throw new InstallerError(
|
|
87
|
+
"Plugin archives must contain only regular files and directories.",
|
|
88
|
+
"unsafe_archive",
|
|
89
|
+
{ entry: entry.entryName },
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
// The plugin bundle invokes scripts through their interpreter (all files are 0644).
|
|
93
|
+
// Set our policy before adm-zip writes files, including children of directory entries.
|
|
94
|
+
entry.attr = ((expectedType | (entry.isDirectory ? 0o755 : 0o644)) << 16) >>> 0;
|
|
83
95
|
}
|
|
84
96
|
fs.mkdirSync(destination, { recursive: true });
|
|
85
97
|
for (const entry of entries) {
|
|
86
|
-
archive.extractEntryTo(entry, destination, true, true);
|
|
98
|
+
archive.extractEntryTo(entry, destination, true, true, true);
|
|
99
|
+
}
|
|
100
|
+
normalizePluginPermissions(destination);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function normalizePluginPermissions(target) {
|
|
104
|
+
const stat = fs.lstatSync(target);
|
|
105
|
+
if (!stat.isDirectory() && !stat.isFile()) {
|
|
106
|
+
throw new InstallerError(
|
|
107
|
+
"Plugin code must contain only regular files and directories.",
|
|
108
|
+
"unsafe_plugin_entry",
|
|
109
|
+
{ path: target },
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
const mode = stat.isDirectory() ? 0o755 : 0o644;
|
|
113
|
+
fs.chmodSync(target, mode);
|
|
114
|
+
if (process.platform !== "win32" && (fs.lstatSync(target).mode & 0o7777) !== mode) {
|
|
115
|
+
throw new InstallerError(
|
|
116
|
+
"Could not establish safe plugin permissions.",
|
|
117
|
+
"unsafe_plugin_permissions",
|
|
118
|
+
{ path: target },
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
if (stat.isDirectory()) {
|
|
122
|
+
for (const entry of fs.readdirSync(target)) {
|
|
123
|
+
normalizePluginPermissions(path.join(target, entry));
|
|
124
|
+
}
|
|
87
125
|
}
|
|
88
126
|
}
|
|
89
127
|
|