feat(plugins): skip plugins that share InternalNames with official plugins (#991)

This commit is contained in:
Philpax 2022-08-31 22:08:27 +02:00 committed by GitHub
parent 877f242ac8
commit a4cac03239
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 1 deletions

View file

@ -556,7 +556,12 @@ internal partial class PluginManager : IDisposable, IServiceType
public async Task ReloadPluginMastersAsync(bool notify = true) public async Task ReloadPluginMastersAsync(bool notify = true)
{ {
Log.Information("Now reloading all PluginMasters..."); Log.Information("Now reloading all PluginMasters...");
await Task.WhenAll(this.Repos.Select(repo => repo.ReloadPluginMasterAsync()));
Debug.Assert(!this.Repos.First().IsThirdParty, "First repository should be main repository");
await this.Repos.First().ReloadPluginMasterAsync(); // Load official repo first
await Task.WhenAll(this.Repos.Skip(1).Select(repo => repo.ReloadPluginMasterAsync()));
Log.Information("PluginMasters reloaded, now refiltering..."); Log.Information("PluginMasters reloaded, now refiltering...");
this.RefilterPluginMasters(notify); this.RefilterPluginMasters(notify);
@ -730,6 +735,13 @@ internal partial class PluginManager : IDisposable, IServiceType
// Reload as a local manifest, add some attributes, and save again. // Reload as a local manifest, add some attributes, and save again.
var manifest = LocalPluginManifest.Load(manifestFile); var manifest = LocalPluginManifest.Load(manifestFile);
if (manifest.InternalName != repoManifest.InternalName)
{
Directory.Delete(outputDir.FullName, true);
throw new Exception(
$"Distributed internal name does not match repo internal name: {manifest.InternalName} - {repoManifest.InternalName}");
}
if (useTesting) if (useTesting)
{ {
manifest.Testing = true; manifest.Testing = true;

View file

@ -1,6 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -108,6 +110,35 @@ internal class PluginRepository
manifest.SourceRepo = this; manifest.SourceRepo = this;
} }
var pm = Service<PluginManager>.Get();
var official = pm.Repos.First();
Debug.Assert(!official.IsThirdParty, "First repository should be official repository");
if (official.State == PluginRepositoryState.Success && this.IsThirdParty)
{
pluginMaster = pluginMaster.Where(thisRepoEntry =>
{
if (official.PluginMaster!.Any(officialRepoEntry =>
string.Equals(thisRepoEntry.InternalName, officialRepoEntry.InternalName, StringComparison.InvariantCultureIgnoreCase)))
{
Log.Warning(
"The repository {RepoName} tried to replace the plugin {PluginName}, which is already installed through the official repo - this is no longer allowed for security reasons. " +
"Please reach out if you have an use case for this.",
this.PluginMasterUrl,
thisRepoEntry.InternalName);
return false;
}
return true;
}).ToList();
}
else if (this.IsThirdParty)
{
Log.Warning("Official repository not loaded - couldn't check for overrides!");
this.State = PluginRepositoryState.Fail;
return;
}
this.PluginMaster = pluginMaster.AsReadOnly(); this.PluginMaster = pluginMaster.AsReadOnly();
Log.Information($"Successfully fetched repo: {this.PluginMasterUrl}"); Log.Information($"Successfully fetched repo: {this.PluginMasterUrl}");