packager: block use of net.runelite namespace (#9742)

This commit is contained in:
Abex
2025-12-04 21:36:41 -07:00
committed by GitHub
parent ef7bf922ae
commit 5097faee5a
2 changed files with 38 additions and 2 deletions

View File

@@ -714,6 +714,13 @@ public class Plugin implements Closeable
.withFile(fileName);
}
if (disallowedIsFatal &&
name != null && name.startsWith("net/runelite/"))
{
throw PluginBuildException.of(Plugin.this, "use of net.runelite package namespace is not allowed")
.withFile(fileName);
}
jarClasses.add(name.replace('/', '.'));
extendsPlugin = "net/runelite/client/plugins/Plugin".equals(superName);

View File

@@ -136,6 +136,30 @@ public class PluginTest
}
}
@Test
public void testNetRuneLitePackage() throws InterruptedException, DisabledPluginException, PluginBuildException, IOException
{
try (Plugin p = createExamplePlugin("net-runelite-package", "net.runelite"))
{
p.build(Util.readRLVersion(), true);
Assert.fail();
}
catch (PluginBuildException e)
{
assertContains(e.getMessage(), "use of net.runelite package namespace is not allowed");
log.info("ok: ", e);
}
}
@Test
public void testNetRuneLitePackageDoesNotBlockExisting() throws InterruptedException, DisabledPluginException, PluginBuildException, IOException
{
try (Plugin p = createExamplePlugin("net-runelite-package-preexisting", "net.runelite"))
{
p.build(Util.readRLVersion(), false);
}
}
private static void writeProperties(Properties props, File fi) throws IOException
{
try (FileOutputStream fos = new FileOutputStream(fi))
@@ -167,6 +191,11 @@ public class PluginTest
}
private static Plugin createExamplePlugin(String name) throws DisabledPluginException, PluginBuildException, IOException, InterruptedException
{
return createExamplePlugin(name, "com.example");
}
private static Plugin createExamplePlugin(String name, String packageName) throws DisabledPluginException, PluginBuildException, IOException, InterruptedException
{
Plugin p = newPlugin(name, "" +
"repository=https://github.com/runelite/example-plugin.git\n" +
@@ -177,7 +206,7 @@ public class PluginTest
"--noninteractive",
"--output_directory", p.repositoryDirectory.getAbsolutePath(),
"--name", "Test Example",
"--package", "com.example",
"--package", packageName,
"--author", "Test Nobody",
"--description", "Test An example greeter plugin")
.inheritIO()
@@ -191,4 +220,4 @@ public class PluginTest
{
Assert.assertTrue(haystack, haystack.contains(needle));
}
}
}