mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-20 17:13:49 +00:00
fix(security): fully escape forge HTML
This commit is contained in:
3 files changed
+22
-2
No files matched your search
@@ -33,7 +33,10 @@ function colorToTemplate(color?: number): FeishuTemplate {
|
||||
* up (a zero-width space after `<`) and shows as text.
|
||||
*/
|
||||
function noMentions(content: string): string {
|
||||
return content.replace(/<(\/?)(at)\b/gi, "<\u200b$1$2");
|
||||
// Escape every angle bracket, not only `<at`. Replacing just the mention
|
||||
// prefix still leaves values such as `<script` in Feishu markdown, where an
|
||||
// incomplete tag can be interpreted as HTML by the client.
|
||||
return content.replace(/</g, "<").replace(/>/g, ">");
|
||||
}
|
||||
|
||||
function mdText(content: string): { tag: "lark_md"; content: string } {
|
||||
|
||||
@@ -207,7 +207,11 @@ function stripHtml(input: string): string {
|
||||
.replace(/<\/(p|div|tr|h[1-6]|ul|ol|table|blockquote)>/gi, "\n")
|
||||
.replace(/<\/t[dh]>/gi, " ")
|
||||
.replace(/<li[^<>]*>/gi, "\n• ")
|
||||
.replace(/<[^<>]+>/g, "");
|
||||
// A prefix such as `<script` is still dangerous when the closing `>` is
|
||||
// absent or is supplied later by a renderer. Remove the opening bracket
|
||||
// itself after known HTML has been converted to text.
|
||||
.replace(/<[^<>]+>/g, "")
|
||||
.replace(/</g, "");
|
||||
out = out
|
||||
.replace(/ /gi, " ")
|
||||
.replace(/</gi, "<")
|
||||
|
||||
@@ -1556,6 +1556,19 @@ describe("round 30", () => {
|
||||
expect(/<\/?at\b/i.test(card)).toBe(false);
|
||||
});
|
||||
|
||||
it("does not leave HTML tag prefixes in Feishu markdown", async () => {
|
||||
const { renderNeutralMessage } = await import("../server/lib/drivers/feishu/render");
|
||||
const card = JSON.stringify(
|
||||
renderNeutralMessage({
|
||||
title: "repo: <script>alert(1)</script>",
|
||||
description: "<script>alert(2)",
|
||||
footer: "<img src=x>",
|
||||
}),
|
||||
);
|
||||
expect(card).not.toContain("<script");
|
||||
expect(card).not.toContain("<img");
|
||||
});
|
||||
|
||||
it("reads a delivery's finished targets in one query", async () => {
|
||||
const { markTargetsDone, targetDoneChecker } = await import("../server/lib/queue/delivery");
|
||||
const { db } = createSqliteD1();
|
||||
|
||||
Reference in new issue
Block a user