feat: add escapeHtml function
This can be used to escape any special characters in a string with HTML before sending from the server back to the client. This is important to prevent a cross-site scripting attack.
This commit is contained in:
@ -4,7 +4,7 @@ import { RateLimiter as Limiter } from "limiter"
|
||||
import * as path from "path"
|
||||
import { rootPath } from "../constants"
|
||||
import { authenticated, getCookieDomain, redirect, replaceTemplates } from "../http"
|
||||
import { getPasswordMethod, handlePasswordValidation, humanPath, sanitizeString } from "../util"
|
||||
import { getPasswordMethod, handlePasswordValidation, humanPath, sanitizeString, escapeHtml } from "../util"
|
||||
|
||||
export enum Cookie {
|
||||
Key = "key",
|
||||
@ -36,6 +36,7 @@ const getRoot = async (req: Request, error?: Error): Promise<string> => {
|
||||
} else if (req.args.usingEnvHashedPassword) {
|
||||
passwordMsg = "Password was set from $HASHED_PASSWORD."
|
||||
}
|
||||
|
||||
return replaceTemplates(
|
||||
req,
|
||||
content
|
||||
@ -111,6 +112,8 @@ router.post("/", async (req, res) => {
|
||||
|
||||
throw new Error("Incorrect password")
|
||||
} catch (error) {
|
||||
res.send(await getRoot(req, error))
|
||||
const html = await getRoot(req, error)
|
||||
const escapedHtml = escapeHtml(html)
|
||||
res.send(escapedHtml)
|
||||
}
|
||||
})
|
||||
|
Reference in New Issue
Block a user