Lesson Plan Title: How to Perform Cross Site Scripting (XSS)

Concept / Topic To Teach:
It is always a good practice to scrub all inputs, especially those inputs that will later be used as parameters to OS commands, scripts, and database queries. It is particularly important for content that will be permanently stored somewhere. Users should not be able to create message content that could cause another user to load an undesirable page or undesirable content when the user's message is retrieved. XSS can also occur when unvalidated user input is used in an HTTP response. In a reflected XSS attack, an attacker can craft a URL with the attack script and post it to another website, email it, or otherwise get a victim to click on it.

General Goal(s):
For this exercise, you will perform stored and reflected XSS attacks. You will also implement code changes in the web application to defeat these attacks.

Solution:
You have to alter the method parseEmployeeProfile in the class UpdateProfile.java which is placed in the package org.owasp.webgoat.lessons.CrossSiteScripting
The place to code is marked! Following code will work:

`/**Your code**/
String regex = "[\\s\\w-,]*";
String stringToValidate = firstName+lastName+ssn+title+phone+address1+address2+
startDate+ccn+disciplinaryActionDate+
disciplinaryActionNotes+personalDescription;
Pattern pattern = Pattern.compile(regex);
validate(stringToValidate, pattern);
/**End of your code**/`

This validation allows following:
\s = whitspace: \t\n\x0B\f\r
\w = word: a-zA-Z_0-9
and the characters - and ,

Use of any other character will throw a Validation Exception.