feat: 开放浏览器HTTP站点访问

This commit is contained in:
yu committed 2026-10-28 10:56:40 +08:00
1 parent 7d96badb1f
commit 5e9f0df57f
2 files changed
+3 -20

No files matched your search

-17
View File
@@ -12,16 +12,6 @@ import {
type BrowserSimilarElementOptions
} from "../engine/types";
const DEFAULT_DOMAINS = ["127.0.0.1", "localhost", "example.com"];
function allowedDomains(): string[] {
const extra = (process.env.RPA_ALLOWED_DOMAINS || "")
.split(",")
.map((item) => item.trim())
.filter(Boolean);
return [...DEFAULT_DOMAINS, ...extra];
}
function assertUrl(raw: string): URL {
let url: URL;
try {
@@ -32,13 +22,6 @@ function assertUrl(raw: string): URL {
if (url.protocol !== "http:" && url.protocol !== "https:") {
throw new RuntimeError("blocked_url", `只允许 http/https,当前为 ${url.protocol}`);
}
const host = url.hostname;
const allowed = allowedDomains().some((domain) => host === domain || host.endsWith(`.${domain}`));
if (!allowed) {
throw new RuntimeError("blocked_url", `域名不在白名单:${host}`, {
recommendation: `在设置中把 ${host} 加入白名单(或设置 RPA_ALLOWED_DOMAINS)`
});
}
return url;
}