@adrouter/agent 0.1.0-beta.2 → 0.1.0-beta.3
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/lib/installer.mjs +32 -5
- package/package.json +1 -1
- package/release-manifest.json +6 -6
package/lib/installer.mjs
CHANGED
|
@@ -8,12 +8,13 @@ import {
|
|
|
8
8
|
open,
|
|
9
9
|
readdir,
|
|
10
10
|
readFile,
|
|
11
|
+
readlink,
|
|
11
12
|
realpath,
|
|
12
13
|
rename,
|
|
13
14
|
rm,
|
|
14
15
|
} from 'node:fs/promises';
|
|
15
16
|
import { homedir } from 'node:os';
|
|
16
|
-
import { basename, join, sep } from 'node:path';
|
|
17
|
+
import { basename, join, posix, relative, sep } from 'node:path';
|
|
17
18
|
import { promisify } from 'node:util';
|
|
18
19
|
|
|
19
20
|
const execFileAsync = promisify(execFile);
|
|
@@ -83,6 +84,25 @@ export function assertSafeArchiveEntries(entries) {
|
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
|
|
87
|
+
export function assertSafeArchiveSymlink(entry, target) {
|
|
88
|
+
assertSafeArchiveEntries([entry]);
|
|
89
|
+
if (
|
|
90
|
+
typeof target !== 'string' ||
|
|
91
|
+
target.length === 0 ||
|
|
92
|
+
target.includes('\0') ||
|
|
93
|
+
target.startsWith('/') ||
|
|
94
|
+
target.startsWith('\\') ||
|
|
95
|
+
target.includes('\\')
|
|
96
|
+
) {
|
|
97
|
+
throw new Error(`Unsafe ZIP symbolic link target: ${JSON.stringify(target)}`);
|
|
98
|
+
}
|
|
99
|
+
const resolved = posix.resolve('/', posix.dirname(entry), target);
|
|
100
|
+
const appRoot = `/${APP_NAME}`;
|
|
101
|
+
if (resolved !== appRoot && !resolved.startsWith(`${appRoot}/`)) {
|
|
102
|
+
throw new Error(`ZIP symbolic link escapes ${APP_NAME}: ${entry} -> ${target}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
86
106
|
export function releasePaths(_manifest, homeDirectory = homedir()) {
|
|
87
107
|
const applicationsDirectory = join(homeDirectory, 'Applications');
|
|
88
108
|
const supportDirectory = join(
|
|
@@ -167,12 +187,15 @@ async function verifyExtractedTree(root, appPath) {
|
|
|
167
187
|
const canonicalRoot = `${await realpath(root)}${sep}`;
|
|
168
188
|
async function visit(path) {
|
|
169
189
|
const stat = await lstat(path);
|
|
170
|
-
if (stat.isSymbolicLink())
|
|
190
|
+
if (stat.isSymbolicLink()) {
|
|
191
|
+
const entry = relative(root, path).split(sep).join('/');
|
|
192
|
+
assertSafeArchiveSymlink(entry, await readlink(path));
|
|
193
|
+
}
|
|
171
194
|
const canonical = await realpath(path);
|
|
172
195
|
if (canonical !== canonicalRoot.slice(0, -1) && !canonical.startsWith(canonicalRoot)) {
|
|
173
196
|
throw new Error('Release archive escaped its extraction directory.');
|
|
174
197
|
}
|
|
175
|
-
if (!stat.isDirectory()) return;
|
|
198
|
+
if (!stat.isDirectory() || stat.isSymbolicLink()) return;
|
|
176
199
|
for (const entry of await readdir(path)) await visit(join(path, entry));
|
|
177
200
|
}
|
|
178
201
|
const topLevel = await readdir(root);
|
|
@@ -241,8 +264,12 @@ async function archiveEntries(zipPath, executeImpl = execute) {
|
|
|
241
264
|
const entries = stdout.split('\n').filter(Boolean);
|
|
242
265
|
assertSafeArchiveEntries(entries);
|
|
243
266
|
const { stdout: listing } = await executeImpl('/usr/bin/zipinfo', ['-l', zipPath]);
|
|
244
|
-
|
|
245
|
-
|
|
267
|
+
for (const line of listing.split('\n').filter((value) => /^l[rwx-]{9}\s/.test(value))) {
|
|
268
|
+
const match = line.match(/^l[rwx-]{9}\s+\S+\s+\S+\s+\d+\s+\S+\s+\d+\s+\S+\s+\S+\s+\S+\s+(.+)$/);
|
|
269
|
+
if (!match) throw new Error('Unable to validate a ZIP symbolic link entry.');
|
|
270
|
+
const entry = match[1];
|
|
271
|
+
const { stdout: target } = await executeImpl('/usr/bin/unzip', ['-p', zipPath, entry]);
|
|
272
|
+
assertSafeArchiveSymlink(entry, target);
|
|
246
273
|
}
|
|
247
274
|
return entries;
|
|
248
275
|
}
|
package/package.json
CHANGED
package/release-manifest.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema": 2,
|
|
3
3
|
"distributionMode": "credential-free-adhoc",
|
|
4
|
-
"releaseVersion": "0.1.0-beta.
|
|
5
|
-
"releaseTag": "v0.1.0-beta.
|
|
6
|
-
"assetName": "AdRouter-Agent-0.1.0-beta.
|
|
7
|
-
"assetUrl": "https://github.com/adrouter/adrouterAgent/releases/download/v0.1.0-beta.
|
|
8
|
-
"sha256": "
|
|
4
|
+
"releaseVersion": "0.1.0-beta.3",
|
|
5
|
+
"releaseTag": "v0.1.0-beta.3",
|
|
6
|
+
"assetName": "AdRouter-Agent-0.1.0-beta.3-universal.zip",
|
|
7
|
+
"assetUrl": "https://github.com/adrouter/adrouterAgent/releases/download/v0.1.0-beta.3/AdRouter-Agent-0.1.0-beta.3-universal.zip",
|
|
8
|
+
"sha256": "269e60704fea20797edefc64d440afb54112b4a238d2fed9df119bb656b7d397",
|
|
9
9
|
"repository": "adrouter/adrouterAgent",
|
|
10
10
|
"bundleIdentifier": "com.adrouter.agent",
|
|
11
11
|
"bundleShortVersion": "0.1.0",
|
|
12
|
-
"bundleVersion": "
|
|
12
|
+
"bundleVersion": "10003"
|
|
13
13
|
}
|