mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-21 07:32:54 +00:00
fix(plugins): close remaining authorization races
This commit is contained in:
1 parent
6e79ef9ff9
commit
e6c55c9052
8 files changed
+158
-4
No files matched your search
@@ -217,6 +217,32 @@ test("manifest validation reports permission and contribution mistakes", () => {
|
||||
assert.match(result.errors.join("\n"), /undeclared command/);
|
||||
});
|
||||
|
||||
test("manifest validation applies the runtime resource limit for each permission", () => {
|
||||
for (const [permission, length, expectedLimit] of [
|
||||
["network", 2_049, 2_048],
|
||||
["storage", 2_049, 2_048],
|
||||
["companion.execute", 193, 192],
|
||||
] as const) {
|
||||
const result = validateManifestValue(manifest({
|
||||
permissions: {
|
||||
required: [{ permission, resources: ["x".repeat(length)] }],
|
||||
},
|
||||
}));
|
||||
assert.equal(result.valid, false);
|
||||
assert.match(
|
||||
result.errors.join("\n"),
|
||||
new RegExp(`Permission resource for ${permission.replace(".", "\\.")} exceeds ${expectedLimit}`),
|
||||
);
|
||||
}
|
||||
|
||||
const filesystem = validateManifestValue(manifest({
|
||||
permissions: {
|
||||
required: [{ permission: "filesystem.read", resources: [`/${"x".repeat(4_096)}`] }],
|
||||
},
|
||||
}));
|
||||
assert.equal(filesystem.valid, true, filesystem.errors.join("\n"));
|
||||
});
|
||||
|
||||
test("Node utility entrypoints require the explicit advanced-runtime permission", () => {
|
||||
const missing = validateManifestValue(manifest({
|
||||
main: { node: "dist/index.js" },
|
||||
|
||||
@@ -134,6 +134,31 @@ function permissionName(declaration: PermissionDeclaration): PluginPermission {
|
||||
return typeof declaration === "string" ? declaration : declaration.permission;
|
||||
}
|
||||
|
||||
function permissionResourceLimit(permission: PluginPermission): number {
|
||||
if (permission === "filesystem.read" || permission === "filesystem.write") return 8_192;
|
||||
if (permission === "companion.execute") return 192;
|
||||
return 2_048;
|
||||
}
|
||||
|
||||
function validatePermissionResourceLimits(manifest: PluginManifest): string[] {
|
||||
const errors: string[] = [];
|
||||
for (const declaration of [
|
||||
...(manifest.permissions?.required ?? []),
|
||||
...(manifest.permissions?.optional ?? []),
|
||||
]) {
|
||||
if (typeof declaration === "string") continue;
|
||||
const maximum = permissionResourceLimit(declaration.permission);
|
||||
for (const resource of declaration.resources) {
|
||||
if (resource.length > maximum) {
|
||||
errors.push(
|
||||
`Permission resource for ${declaration.permission} exceeds ${maximum} characters`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
function findDuplicateIds(manifest: PluginManifest): string[] {
|
||||
const errors: string[] = [];
|
||||
const groups = [
|
||||
@@ -185,6 +210,7 @@ function validateSemantics(manifest: PluginManifest): string[] {
|
||||
const errors = [
|
||||
...findDuplicateIds(manifest),
|
||||
...validateOwnedContributionIds(manifest),
|
||||
...validatePermissionResourceLimits(manifest),
|
||||
];
|
||||
for (const [engine, range] of Object.entries(manifest.engines)) {
|
||||
if (validRange(range) === null) {
|
||||
|
||||
Reference in new issue
Block a user