In this exercise, you will use GitHub Copilot Chat to generate suggestions that help improve code security in a sample application. The focus will be on enhancing authentication, data protection, secure error handling, and compliance with security standards.
Before starting this exercise, ensure you have the following tools and resources installed:
- Visual Studio Code
- The C# Dev Kit extension for Visual Studio Code
- GitHub Copilot and GitHub Copilot Chat extensions
- Open the
APL2007M5BankAccount-Securityproject in Visual Studio Code. - Familiarize yourself with the
Program.csandBankAccount.csfiles under theBankAccountClassproject. - Build and run the project to ensure it works as expected:
- Open the terminal in Visual Studio Code and run the following command:
cd BankAccountClass dotnet run- The application should generate random bank account details and perform basic operations like crediting, debiting, and transferring funds.
- The output should display the account details and the results of the operations.
- Review the following methods in the
BankAccount.csfile:CreditDebitTransferCalculateInterest
- Consider aspects such as authentication, data protection, and secure error handling.
- Open the Chat view in
Askmode in Visual Studio Code. - Check that the the
BankAccount.csfile is attached to the Chat context, if it is not then ensure you have it selected in the editor. - Use the following prompt to generate suggestions:
- "
@workspaceHow can I improve authentication and data protection in theBankAccountclass?"
- "
- Review the suggestions provided by GitHub Copilot Chat.
- Implement updates that enhance code security, such as:
- Adding authentication mechanisms.
- Encrypting sensitive data.
- Avoiding hardcoded passwords.
- Open the Chat view in
Askmode in Visual Studio Code. - Check that the the
Program.csfile is attached to the Chat context, if it is not then ensure you have it selected in the editor. - Use the following prompt to generate suggestions:
- "
@workspaceHow can I implement secure exception handling in theProgram.csfile?"
- "
- Review the suggestions provided by GitHub Copilot Chat.
- Implement updates that enhance secure exception handling, such as:
- Catching specific exceptions instead of generic ones.
- Logging errors securely.
-
Use additional prompts to explore further improvements.
-
Repeat the process of reviewing, implementing, and testing updates.
Consider the following additional prompts:
- "
@workspaceHow can I avoid future security vulnerabilities in theProgram.csfile?" - "
@workspaceHow can I improve compliance with security standards in theBankAccountclass?"
- "
-
Implement updates that enhance code security, such as:
- Refactoring methods to handle sensitive data securely.
- Improving authentication and authorization mechanisms.
- Ensuring compliance with security standards and regulations.
- The suggestions provided by GitHub Copilot Chat are not exhaustive. Use your judgment and expertise to evaluate and implement them.
- Consider your workplace's coding standards and policies when choosing which updates to implement.
- Ensure thorough code reviews and testing to maintain high-quality code.
- If GitHub Copilot suggests creating a new file, use the "insert into new file" option to have it create the file for you.