stack-auth / stack

Open-source Auth0/Clerk alternative
https://stack-auth.com
Other
4.14k stars 263 forks source link

Fix XSS vulnerability by sanitizing user input using escapeHtml function in JavaScript. #240

Closed zeropath-ai[bot] closed 2 months ago

zeropath-ai[bot] commented 2 months ago

Summary

Vulnerability Details

Code Snippets

diff --git a/examples/express-proxied-server/server.js b/examples/express-proxied-server/server.js
index e570bf21..d28003dd 100644
--- a/examples/express-proxied-server/server.js
+++ b/examples/express-proxied-server/server.js
@@ -3,6 +3,15 @@ const express = require('express');
 const app = express();
 const PORT = process.env.PORT || 3000;

+function escapeHtml(unsafe) {
+  return unsafe
+    .replace(/&/g, "&")
+    .replace(/</g, "&lt;")
+    .replace(/>/g, "&gt;")
+    .replace(/"/g, "&quot;")
+    .replace(/'/g, "&#039;");
+}
+

 app.get('/', (req, res) => {
   const authenticated = !!req.headers['x-stack-authenticated'];
@@ -11,7 +20,7 @@ app.get('/', (req, res) => {
     <div>
       <p>Main page</p>
       <p>Authenticated: ${authenticated ? "Yes" : "No"}</p>
-      ${authenticated ? `<p>Display Name: ${displayName}</p>` : ""}
+      ${authenticated ? `<p>Display Name: ${escapeHtml(displayName)}</p>` : ""}
       ${authenticated ? `<p><a href="/handler/account-settings" style="text-decoration: underline;">Account Settings</a></p>` : ""}
       <p><a href="/protected" style="text-decoration: underline;">Go to protected page</a></p>
       ${!authenticated ? '<p><a href="/handler/sign-in" style="text-decoration: underline;">Sign In</a></p>' : ""}

How to Modify the Patch

You can modify this patch by using one of the two methods outlined below. We recommend using the ZeroPath bot for updating the code. If you encounter any bugs or issues with the patch, please report them here.

Ask @zeropath-ai!

To request modifications, please post a comment beginning with @zeropath-ai and specify the changes required.

@zeropath-ai will then implement the requested adjustments and commit them to the specified branch in this pull request. Our bot is capable of managing changes across multiple files and various development-related requests.

Manually Modify the Files

# Checkout ZeroPath created branch:
git checkout zeropath_fix_cross_site_scripting_xss_1726078977081876

# if vscode is installed run (or use your favorite editor / IDE):
code examples/express-proxied-server/server.js

# Add, commit, and push changes:
git add -A
git commit -m "Update generated patch with x, y, and z changes."
git push zeropath_fix_cross_site_scripting_xss_1726078977081876
vercel[bot] commented 2 months ago

The latest updates on your projects. Learn more about Vercel for Git ā†—ļøŽ

Name Status Preview Comments Updated (UTC)
stack-backend āœ… Ready (Inspect) Visit Preview šŸ’¬ Add feedback Sep 11, 2024 6:28pm
stack-dashboard āœ… Ready (Inspect) Visit Preview šŸ’¬ Add feedback Sep 11, 2024 6:28pm
stack-demo āœ… Ready (Inspect) Visit Preview šŸ’¬ Add feedback Sep 11, 2024 6:28pm
stack-partial-prerendering āœ… Ready (Inspect) Visit Preview šŸ’¬ Add feedback Sep 11, 2024 6:28pm
CLAassistant commented 2 months ago

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


ZeroPath seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.