-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Remove examples that show insecure practices #10435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
301b118
remove examples that show insecure practices
gewarren 4042826
fix build warnings and delete corresponding vb snippets
gewarren a2c7a33
fix up VB snippets to match C# snippets
gewarren c6a5c00
update TFM and package version
gewarren 11a7940
fix final warnings
gewarren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,2 @@ | ||
> [!WARNING] | ||
> Storing user credentials in the `credentials` section is **insecure**. Instead, use [Azure Key Vault](/azure/key-vault/general/overview). |
This file contains hidden or 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,2 @@ | ||
> [!WARNING] | ||
> Microsoft does not recommend providing your user name and password directly, because it's an insecure pattern. Where possible, use more secure authentication flows, such as [Managed Identities for Azure resources](/sql/connect/ado-net/sql/azure-active-directory-authentication#using-managed-identity-authentication), or [Windows authentication](/sql/relational-databases/security/choose-an-authentication-mode#connecting-through-windows-authentication) for SQL Server. |
This file contains hidden or 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
10 changes: 5 additions & 5 deletions
10
...ts/csharp/VS_Snippets_ADO.NET/Classic WebData SqlCommand.ExecuteReader2/CS/Project.csproj
This file contains hidden or 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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<TargetFramework>net8.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" /> | ||
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
12 changes: 12 additions & 0 deletions
12
.../csharp/VS_Snippets_ADO.NET/DataWorks SqlConnectionStringBuilder.Remove/CS/Project.csproj
This file contains hidden or 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,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains hidden or 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
13 changes: 13 additions & 0 deletions
13
snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlConnectionStringBuilder/CS/Project.csproj
This file contains hidden or 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,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net4.8</TargetFramework> | ||
<LangVersion>11</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" /> | ||
</ItemGroup> | ||
|
||
</Project> |
43 changes: 12 additions & 31 deletions
43
snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlConnectionStringBuilder/CS/source.cs
This file contains hidden or 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 |
---|---|---|
@@ -1,56 +1,37 @@ | ||
| ||
|
||
using System; | ||
// <Snippet1> | ||
using System.Data; | ||
using System; | ||
using System.Data.SqlClient; | ||
|
||
class Program | ||
{ | ||
static void Main() | ||
{ | ||
// <Snippet1> | ||
// Create a new SqlConnectionStringBuilder and | ||
// initialize it with a few name/value pairs. | ||
SqlConnectionStringBuilder builder = | ||
new SqlConnectionStringBuilder(GetConnectionString()); | ||
SqlConnectionStringBuilder builder = new( | ||
"Server=(local);Integrated Security=true;" + | ||
"Initial Catalog=AdventureWorks" | ||
); | ||
|
||
// The input connection string used the | ||
// Server key, but the new connection string uses | ||
// the well-known Data Source key instead. | ||
Console.WriteLine(builder.ConnectionString); | ||
|
||
// Pass the SqlConnectionStringBuilder an existing | ||
// connection string, and you can retrieve and | ||
// modify any of the elements. | ||
builder.ConnectionString = "server=(local);user id=ab;" + | ||
"password= a!Pass113;initial catalog=AdventureWorks"; | ||
Console.WriteLine($"Original connection string: '{builder.ConnectionString}'"); | ||
|
||
// Now that the connection string has been parsed, | ||
// you can work with individual items. | ||
Console.WriteLine(builder.Password); | ||
builder.Password = "new@1Password"; | ||
Console.WriteLine($"Initial catalog: '{builder.InitialCatalog}'"); | ||
builder.InitialCatalog = "Northwind"; | ||
builder.AsynchronousProcessing = true; | ||
|
||
// You can refer to connection keys using strings, | ||
// as well. When you use this technique (the default | ||
// Item property in Visual Basic, or the indexer in C#), | ||
// you can specify any synonym for the connection string key | ||
// name. | ||
// you can specify any synonym for the connection string key name. | ||
builder["Server"] = "."; | ||
builder["Connect Timeout"] = 1000; | ||
builder["Trusted_Connection"] = true; | ||
Console.WriteLine(builder.ConnectionString); | ||
|
||
Console.WriteLine("Press Enter to finish."); | ||
Console.ReadLine(); | ||
} | ||
|
||
private static string GetConnectionString() | ||
{ | ||
// To avoid storing the connection string in your code, | ||
// you can retrieve it from a configuration file. | ||
return "Server=(local);Integrated Security=SSPI;" + | ||
"Initial Catalog=AdventureWorks"; | ||
Console.WriteLine($"Modified connection string: '{builder.ConnectionString}'"); | ||
// </Snippet1> | ||
} | ||
} | ||
// </Snippet1> |
13 changes: 13 additions & 0 deletions
13
...sharp/VS_Snippets_WebNet/System.Web.Configuration.AuthenticationSection/CS/Project.csproj
This file contains hidden or 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,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net4.8</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="System.Configuration" /> | ||
<Reference Include="System.Web" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains hidden or 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
13 changes: 13 additions & 0 deletions
13
...ippets_WebNet/System.Web.Configuration.FormsAuthenticationConfiguration/CS/Project.csproj
This file contains hidden or 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,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net4.8</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="System.Configuration" /> | ||
<Reference Include="System.Web" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.