diff --git a/client.csp.demo/routes/exercise.js b/client.csp.demo/routes/exercise.js index 266ec10..8a56481 100644 --- a/client.csp.demo/routes/exercise.js +++ b/client.csp.demo/routes/exercise.js @@ -20,4 +20,20 @@ router.post('/1/exploited', express.urlencoded(), (req, res) => { } }) +router.get('/2', (req, res) => { + res.render(`ex2`, {cspIsSet: req.exSetPolicy, isPost: false, isSuccess: false, emailAddr: '' }); +}); + +router.post('/2', express.urlencoded(), (req, res) => { + if(req.body.email) { + if(/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(req.body.email)) { + res.render(`ex2`, {cspIsSet: req.exSetPolicy, isPost: true, isSuccess: false, emailAddr: '', message: 'If the supplied email matches a valid user in this app, an email will be sent with reset instructions.'}); + } else { + res.render(`ex2`, {cspIsSet: req.exSetPolicy, isPost: true, isSuccess: false, emailAddr: req.body.email, message: 'The supplied email address appeared to be improperly formatted.' }); + } + } else { + res.render(`ex2`, {cspIsSet: req.exSetPolicy, isPost: true, isSuccess: false, emailAddr: ''}); + } +}); + module.exports = router \ No newline at end of file diff --git a/client.csp.demo/static/alertsolve.js b/client.csp.demo/static/alertsolve.js new file mode 100644 index 0000000..fd1afb7 --- /dev/null +++ b/client.csp.demo/static/alertsolve.js @@ -0,0 +1,6 @@ +window.alert = ((_alert) => { + return function() { + $('#topMessage').text(`Congratulations on solving this exercise!`); + return _alert.apply(null, arguments); + } +})(window.alert); \ No newline at end of file diff --git a/client.csp.demo/static/cspForm.js b/client.csp.demo/static/cspForm.js index 698acf6..b60c1d3 100644 --- a/client.csp.demo/static/cspForm.js +++ b/client.csp.demo/static/cspForm.js @@ -2,9 +2,6 @@ setTimeout(function() { document.getElementById('msg').innerHTML = ''}, 2500); function createTexboxBlurHandler(checkbox) { return function (event) { - console.log('event fired') - console.log(event.target) - console.log(event.target.value) if(event.target.value.trim().length === 0) { checkbox.checked = '' } else { diff --git a/client.csp.demo/views/_base.njk b/client.csp.demo/views/_base.njk index 2e19923..f95e915 100644 --- a/client.csp.demo/views/_base.njk +++ b/client.csp.demo/views/_base.njk @@ -20,6 +20,9 @@ Exercise 1 + + Exercise 2 + diff --git a/client.csp.demo/views/ex2.njk b/client.csp.demo/views/ex2.njk new file mode 100644 index 0000000..31a5fc3 --- /dev/null +++ b/client.csp.demo/views/ex2.njk @@ -0,0 +1,49 @@ +{% extends "_base.njk" %} + +{% block pageTitle %} - Exercise 2{% endblock %} + +{% block body %} +
This exercise is a test of finding the flaw in the CSP. Execute a JavaScript alert
pop-up to prove you have execution.
Note: This one requires access to the internet.
+ + + + +Forgot My Password
+ +