Skip to content

Latest commit

 

History

History
28 lines (18 loc) · 1.01 KB

02-Step02.md

File metadata and controls

28 lines (18 loc) · 1.01 KB

Step 2 - Securing your code

GitHub Copilot does a pretty good job of minimising insecure code being recommended, but things can sometimes slips through.

Take a look at your Browse method. It might look something like this:

public string Browse(string genre) { 
    return "Hello from Store.Browse(), Genre = " + genre; 
}

While most modern web browsers will block inline JavaScript submissions, and many web frameworks parse and block risky requests, we should still be protecting our solution by parsing the values being supplied in the genre parameter.

See if you can craft a Copilot prompt in this method that protects your solution from JavaScript injection attacks.

Your result coding should look similar to the below.

string message = HttpUtility.HtmlEncode("Store.Browse, Genre = " + genre);

Note

You will need to add a using statement and refactor some code to get this to run.


Previous - Adding a Controller | Next - Adding a View