How exactly does Cross Site Scripting (XSS) work?
Fixing Reflected XSS issue in Javascript. CheckMarx - Stack Overflow
ELI5: explaining cross-site scripting attack?
ELI5: Cross-Site Scripting vulnerability
How to Test for Cross-Site Scripting Vulnerabilities?
What are the Tools and Solutions to Detect and Prevent XSS Attacks?
What are XSS Attacks?
Videos
Hello,
So I know a general concept of XSS where a threat actor infects a website's code with it's own malicious part of code but what happens later. How does it work on victim's side? Does the malicious party create fake link first which is actually the same as the original link (with no typos) and sends it to the receiving party or is there any other way? I know about DOM-based XSS and how exactly do they differ between standard XSS?
I have also heard about reflected XSS which affects website owner's server which validates the fake link with malicious code in it. How different is that from the aforementioned attacks and how can one mitigate them?
I am sorry if this thread is too simple but I'd like to understand it as I am an idiot in this matter.
Make sure to sanitize any input you get from users, that includes taking any parameters from the request. You can find many sanitization modules or middle ware that will do this for you, just try a quick google search.
As for open redirect, if the url parameter is coming from a user, use Regex or something of the liking to parse the domain. It could even just be something as simple as making sure it starts with the right protocol and domain.
I believe Checkmarx sees the url variable first in the flow as arbitrary which is why it is seeing it as a Client DOM Open Redirect vulnerability. You can try prefixing the url with a hardcoded value if you don't need it to be arbitrary.
if(isNaN($rootScope.selectedContext.defaultAppPageId) || isNaN($rootScope.defaultHierarchyId)) {
return
}
var redirectUrl = "https://stackoverflow.com?" + "appPageId=" +
$rootScope.selectedContext.defaultAppPageId + "&hierarchyId="+
$rootScope.defaultHierarchyId
window.location.href = encodeURI(redirectUrl)
For the XSS vuln, it well could be considered as a false positive since Angular sanitizes and escapes untrusted values. However, you can't always trust the view engine to do its job so if you really wanted an explicit fix, you may want to use a html encode library (find a decent one, this is just an example):
var htmlencode = require('htmlencode');
res.send("The Context"+ htmlencode.htmlEncode(req.params.contextName) + " has restricted access. Please request access to this page");
Hope this helps!