|
1 | | -using System; |
2 | | -using System.Collections.Generic; |
3 | | -using System.Collections.Immutable; |
4 | | -using System.Linq; |
5 | | -using System.Threading; |
6 | | -using System.Threading.Tasks; |
| 1 | +using System.Collections.Immutable; |
7 | 2 | using Avalonia.Controls.Notifications; |
| 3 | +using Avalonia.Threading; |
8 | 4 | using CommunityToolkit.Mvvm.ComponentModel; |
| 5 | +using FluentAvalonia.UI.Controls; |
9 | 6 | using Injectio.Attributes; |
10 | 7 | using KeyedSemaphores; |
11 | 8 | using Microsoft.Extensions.Logging; |
12 | 9 | using Nito.Disposables.Internals; |
| 10 | +using StabilityMatrix.Avalonia.Languages; |
13 | 11 | using StabilityMatrix.Avalonia.Models; |
14 | 12 | using StabilityMatrix.Avalonia.ViewModels; |
15 | 13 | using StabilityMatrix.Core.Extensions; |
@@ -79,6 +77,111 @@ IPyRunner pyRunner |
79 | 77 | return null; |
80 | 78 | } |
81 | 79 |
|
| 80 | + // Show warning if critical vulnerabilities are found |
| 81 | + if (basePackage.HasCriticalVulnerabilities) |
| 82 | + { |
| 83 | + var vulns = basePackage |
| 84 | + .KnownVulnerabilities.Where(v => v.Severity == VulnerabilitySeverity.Critical) |
| 85 | + .Select( |
| 86 | + v => |
| 87 | + $"**{v.Id}**: {v.Title}\n - Severity: {v.Severity}\n - Description: {v.Description}" |
| 88 | + ) |
| 89 | + .ToList(); |
| 90 | + |
| 91 | + var message = |
| 92 | + $"# ⚠️ Critical Security Vulnerabilities\n\nThis package has critical security vulnerabilities that may put your system at risk:\n\n{string.Join("\n\n", vulns)}"; |
| 93 | + message += |
| 94 | + "\n\nFor more information, please visit the [GitHub Security Advisory page](https://github.com/LykosAI/StabilityMatrix/security/advisories)."; |
| 95 | + |
| 96 | + var dialog = DialogHelper.CreateMarkdownDialog(message, "Security Warning"); |
| 97 | + |
| 98 | + dialog.IsPrimaryButtonEnabled = false; |
| 99 | + dialog.PrimaryButtonText = "Continue Anyway (3)"; |
| 100 | + dialog.CloseButtonText = Resources.Action_Cancel; |
| 101 | + dialog.DefaultButton = ContentDialogButton.Close; |
| 102 | + |
| 103 | + // Start a timer to enable the button after 3 seconds |
| 104 | + var countdown = 3; |
| 105 | + var timer = new System.Timers.Timer(1000); |
| 106 | + timer.Elapsed += (_, _) => |
| 107 | + { |
| 108 | + Dispatcher.UIThread.Post(() => |
| 109 | + { |
| 110 | + countdown--; |
| 111 | + if (countdown <= 0) |
| 112 | + { |
| 113 | + dialog.IsPrimaryButtonEnabled = true; |
| 114 | + dialog.PrimaryButtonText = "Continue Anyway"; |
| 115 | + timer.Stop(); |
| 116 | + timer.Dispose(); |
| 117 | + } |
| 118 | + else |
| 119 | + { |
| 120 | + dialog.PrimaryButtonText = $"Continue Anyway ({countdown})"; |
| 121 | + } |
| 122 | + }); |
| 123 | + }; |
| 124 | + timer.Start(); |
| 125 | + |
| 126 | + var result = await dialog.ShowAsync(); |
| 127 | + if (result != ContentDialogResult.Primary) |
| 128 | + { |
| 129 | + return null; |
| 130 | + } |
| 131 | + } |
| 132 | + // Show warning if any vulnerabilities are found |
| 133 | + else if (basePackage.HasVulnerabilities) |
| 134 | + { |
| 135 | + var vulns = basePackage |
| 136 | + .KnownVulnerabilities.Select( |
| 137 | + v => |
| 138 | + $"**{v.Id}**: {v.Title}\n - Severity: {v.Severity}\n - Description: {v.Description}" |
| 139 | + ) |
| 140 | + .ToList(); |
| 141 | + |
| 142 | + var message = |
| 143 | + $"# ⚠️ Security Notice\n\nThis package has known vulnerabilities:\n\n{string.Join("\n\n", vulns)}"; |
| 144 | + |
| 145 | + message += |
| 146 | + "\n\nFor more information, please visit the [GitHub Security Advisory page](https://github.com/LykosAI/StabilityMatrix/security/advisories)."; |
| 147 | + |
| 148 | + var dialog = DialogHelper.CreateMarkdownDialog(message, "Security Notice"); |
| 149 | + |
| 150 | + dialog.IsPrimaryButtonEnabled = false; |
| 151 | + dialog.PrimaryButtonText = "Continue Anyway (3)"; |
| 152 | + dialog.CloseButtonText = Resources.Action_Cancel; |
| 153 | + dialog.DefaultButton = ContentDialogButton.Close; |
| 154 | + |
| 155 | + // Start a timer to enable the button after 3 seconds |
| 156 | + var countdown = 3; |
| 157 | + var timer = new System.Timers.Timer(1000); |
| 158 | + timer.Elapsed += (_, _) => |
| 159 | + { |
| 160 | + Dispatcher.UIThread.Post(() => |
| 161 | + { |
| 162 | + countdown--; |
| 163 | + if (countdown <= 0) |
| 164 | + { |
| 165 | + dialog.IsPrimaryButtonEnabled = true; |
| 166 | + dialog.PrimaryButtonText = "Continue Anyway"; |
| 167 | + timer.Stop(); |
| 168 | + timer.Dispose(); |
| 169 | + } |
| 170 | + else |
| 171 | + { |
| 172 | + dialog.PrimaryButtonText = $"Continue Anyway ({countdown})"; |
| 173 | + } |
| 174 | + }); |
| 175 | + }; |
| 176 | + timer.Start(); |
| 177 | + |
| 178 | + var result = await dialog.ShowAsync(); |
| 179 | + if (result != ContentDialogResult.Primary) |
| 180 | + { |
| 181 | + return null; |
| 182 | + } |
| 183 | + } |
| 184 | + |
82 | 185 | // If this is the first launch (LaunchArgs is null), |
83 | 186 | // load and save a launch options dialog vm |
84 | 187 | // so that dynamic initial values are saved. |
|
0 commit comments