-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4cf842
commit 42bf0c6
Showing
19 changed files
with
639 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<ui:DialogWindow x:Class="Snyk.VisualStudio.Extension.TrustDialogWindow" | ||
x:Name="TrustWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:toolkit="clr-namespace:Community.VisualStudio.Toolkit;assembly=Community.VisualStudio.Toolkit" | ||
xmlns:ui="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.15.0" | ||
mc:Ignorable="d" | ||
WindowStartupLocation="CenterScreen" | ||
IsCloseButtonEnabled="True" | ||
HasHelpButton="False" | ||
MinHeight="290" Height="290" | ||
MinWidth="500" Width="500" | ||
BorderBrush="{x:Static SystemColors.WindowFrameBrush}" BorderThickness="1" | ||
WindowStyle="None" ResizeMode="NoResize" AllowsTransparency="True" | ||
xmlns:catalog="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.ImageCatalog" | ||
xmlns:imaging="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.Imaging" | ||
toolkit:Themes.UseVsTheme="True" | ||
Title="Snyk - This folder has not been trusted" | ||
MouseDown="TrustDialogWindow_OnMouseDown"> | ||
<DockPanel Margin="10"> | ||
<Button DockPanel.Dock="Top" HorizontalAlignment="Right" Click="DoNotTrustButton_OnClick" MinWidth="1" MinHeight="1" Width="35" Margin="0" Padding="0"> | ||
<imaging:CrispImage Moniker="{x:Static catalog:KnownMonikers.Close}"/> | ||
</Button> | ||
<StackPanel HorizontalAlignment="Right" DockPanel.Dock="Bottom" Orientation="Horizontal"> | ||
<Button x:Name="TrustButton" Margin="5, 5" Content="Trust folder and continue" Click="TrustButton_OnClick"/> | ||
<Button x:Name="DoNotTrustButton" Margin="5, 5" Content="Don't scan" Click="DoNotTrustButton_OnClick"/> | ||
</StackPanel> | ||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="auto"/> | ||
<RowDefinition Height="auto"/> | ||
</Grid.RowDefinitions> | ||
<Grid Grid.Row="0"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*"/> | ||
<ColumnDefinition Width="5*"/> | ||
</Grid.ColumnDefinitions> | ||
<imaging:CrispImage Grid.Column="0" Width="50" Moniker="{x:Static catalog:KnownMonikers.StatusSecurityWarning}"/> | ||
<StackPanel VerticalAlignment="Center" Grid.Column="1" Margin="0, 0, 5, 0"> | ||
<TextBlock FontSize="14">This folder has not been trusted:</TextBlock> | ||
<TextBlock FontSize="14" FontWeight="Bold" TextWrapping="Wrap" Text="{Binding ElementName=TrustWindow, Path=FolderPath}"/> | ||
</StackPanel> | ||
</Grid> | ||
<StackPanel Grid.Row="1" Margin="5"> | ||
<TextBlock TextWrapping="Wrap"> | ||
When scanning folder files for vulnerabilities, Snyk may automatically execute code such as invoking the package manager to get dependency information. You should only scan folders you trust. | ||
</TextBlock> | ||
<TextBlock> | ||
<LineBreak/> | ||
<Hyperlink NavigateUri="https://docs.snyk.io/ide-tools/visual-studio-extension/workspace-trust" RequestNavigate="Hyperlink_OnRequestNavigate"> | ||
More information | ||
</Hyperlink> | ||
</TextBlock> | ||
</StackPanel> | ||
</Grid> | ||
</DockPanel> | ||
</ui:DialogWindow> |
49 changes: 49 additions & 0 deletions
49
Snyk.VisualStudio.Extension.2022/TrustDialogWindow.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
| ||
namespace Snyk.VisualStudio.Extension | ||
{ | ||
using System.Diagnostics; | ||
using System.Windows; | ||
using System.Windows.Input; | ||
using System.Windows.Navigation; | ||
using Microsoft.VisualStudio.PlatformUI; | ||
|
||
/// <summary> | ||
/// Trusted dialog window for Visual Studio 2022. | ||
/// </summary> | ||
public partial class TrustDialogWindow : DialogWindow | ||
{ | ||
public TrustDialogWindow(string folderPath) | ||
{ | ||
this.FolderPath = folderPath; | ||
this.InitializeComponent(); | ||
} | ||
|
||
public string FolderPath { get; } | ||
|
||
private void DoNotTrustButton_OnClick(object sender, RoutedEventArgs e) | ||
{ | ||
this.DialogResult = false; | ||
this.Close(); | ||
} | ||
|
||
private void TrustButton_OnClick(object sender, RoutedEventArgs e) | ||
{ | ||
this.DialogResult = true; | ||
this.Close(); | ||
} | ||
|
||
private void Hyperlink_OnRequestNavigate(object sender, RequestNavigateEventArgs e) | ||
{ | ||
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri)); | ||
e.Handled = true; | ||
} | ||
|
||
private void TrustDialogWindow_OnMouseDown(object sender, MouseButtonEventArgs e) | ||
{ | ||
if (e.ChangedButton == MouseButton.Left) | ||
{ | ||
this.DragMove(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
Snyk.VisualStudio.Extension.Shared/Service/IWorkspaceTrustService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Snyk.VisualStudio.Extension.Shared.Service | ||
{ | ||
public interface IWorkspaceTrustService | ||
{ | ||
bool IsFolderTrusted(string absoluteFolderPath); | ||
|
||
void AddFolderToTrusted(string absoluteFolderPath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
Snyk.VisualStudio.Extension.Shared/Service/WorkspaceTrustService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
namespace Snyk.VisualStudio.Extension.Shared.Service | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using Serilog; | ||
using Snyk.Common; | ||
using Snyk.VisualStudio.Extension.Shared.Settings; | ||
|
||
public class WorkspaceTrustService : IWorkspaceTrustService | ||
{ | ||
private static readonly ILogger Logger = LogManager.ForContext<WorkspaceTrustService>(); | ||
|
||
private readonly IUserStorageSettingsService settingsService; | ||
|
||
public WorkspaceTrustService(IUserStorageSettingsService settingsService) | ||
{ | ||
this.settingsService = settingsService; | ||
} | ||
|
||
public void AddFolderToTrusted(string absoluteFolderPath) | ||
{ | ||
if (!Path.IsPathRooted(absoluteFolderPath)) | ||
{ | ||
throw new ArgumentException("Trusted folder path provided is not absolute."); | ||
} | ||
|
||
if (!Directory.Exists(absoluteFolderPath)) | ||
{ | ||
throw new ArgumentException("Trusted folder doesn't exist."); | ||
} | ||
|
||
try | ||
{ | ||
var trustedFolders = this.settingsService.TrustedFolders; | ||
trustedFolders.Add(absoluteFolderPath); | ||
this.settingsService.TrustedFolders = trustedFolders; | ||
} | ||
catch (Exception e) | ||
{ | ||
Logger.Error(e, "Failed to add a folder to trusted."); | ||
} | ||
} | ||
|
||
public bool IsFolderTrusted(string absoluteFolderPath) | ||
{ | ||
var trustedFolders = this.settingsService.TrustedFolders; | ||
|
||
foreach (var trustedFolder in trustedFolders) | ||
{ | ||
if (this.IsSubFolderOrEqual(trustedFolder, absoluteFolderPath)) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/// <summary> | ||
/// Verify if subfolder is rooted at parent path. | ||
/// </summary> | ||
/// <param name="parentPath">Parent path to check against.</param> | ||
/// <param name="childPath">Subfolder path to verify.</param> | ||
/// <returns>Returns true if childPath is subfolder of parentPath, or equal to it.</returns> | ||
private bool IsSubFolderOrEqual(string parentPath, string childPath) | ||
{ | ||
var parentUri = new Uri(parentPath); | ||
if (new Uri(childPath).Equals(parentUri)) | ||
{ | ||
return true; | ||
} | ||
|
||
var childUri = new DirectoryInfo(childPath).Parent; | ||
while (childUri != null) | ||
{ | ||
if (new Uri(childUri.FullName).Equals(parentUri)) | ||
{ | ||
return true; | ||
} | ||
|
||
childUri = childUri.Parent; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Snyk.VisualStudio.Extension.Shared/Settings/IUserStorageSettingsService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Snyk.VisualStudio.Extension.Shared.Settings | ||
{ | ||
using System.Collections.Generic; | ||
|
||
public interface IUserStorageSettingsService | ||
{ | ||
ISet<string> TrustedFolders { get; set; } | ||
} | ||
} |
Oops, something went wrong.