mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 21:07:01 -06:00
fix(link-understanding): strip markdown links whose label contains brackets (#96476)
Merged via squash.
Prepared head SHA: 2d69ed259f
Co-authored-by: ly-wang19 <94427531+ly-wang19@users.noreply.github.com>
Co-authored-by: vincentkoc <25068+vincentkoc@users.noreply.github.com>
Reviewed-by: @vincentkoc
This commit is contained in:
@@ -20,6 +20,15 @@ describe("extractLinksFromMessage", () => {
|
||||
expect(links).toEqual(["https://bare.example"]);
|
||||
});
|
||||
|
||||
it("ignores markdown links whose label contains brackets", () => {
|
||||
// The closing "]" inside the label must not break markdown stripping, otherwise
|
||||
// the citation URL leaks out as a bare link (with a stray trailing ")").
|
||||
const links = extractLinksFromMessage(
|
||||
"Check [my notes [v2]](https://internal.example/doc) for details",
|
||||
);
|
||||
expect(links).toStrictEqual([]);
|
||||
});
|
||||
|
||||
it("blocks 127.0.0.1", () => {
|
||||
const links = extractLinksFromMessage("http://127.0.0.1/test https://ok.test");
|
||||
expect(links).toEqual(["https://ok.test"]);
|
||||
|
||||
@@ -3,7 +3,10 @@ import { isBlockedHostnameOrIp } from "../infra/net/ssrf.js";
|
||||
import { DEFAULT_MAX_LINKS } from "./defaults.js";
|
||||
|
||||
// Remove markdown link syntax so only bare URLs are considered.
|
||||
const MARKDOWN_LINK_RE = /\[[^\]]*]\((https?:\/\/\S+?)\)/gi;
|
||||
// The link-text portion allows "]" that is not the closing "](" boundary so
|
||||
// markdown links whose label contains brackets (e.g. "[my notes [v2]](...)")
|
||||
// are still stripped instead of leaking their URL to BARE_LINK_RE.
|
||||
const MARKDOWN_LINK_RE = /\[(?:[^\]]|](?!\())*]\((https?:\/\/\S+?)\)/gi;
|
||||
const BARE_LINK_RE = /https?:\/\/\S+/gi;
|
||||
|
||||
function stripMarkdownLinks(message: string): string {
|
||||
|
||||
Reference in New Issue
Block a user