feat(task): replace built-in task adaptors with a sandboxed JS plugin system (#7076)

This commit is contained in:
Calcium-Ion
2026-08-29 18:51:57 +08:00
committed by GitHub
parent 7037ac15bd
commit eb48396d5f
336 changed files with 52333 additions and 6369 deletions
+41
View File
@@ -0,0 +1,41 @@
package jsplugin
import (
"fmt"
"net"
"net/url"
"strings"
)
// ValidateRequestURL prevents plugins from directing a channel credential to
// hosts other than the configured base URL or an administrator-approved host.
func ValidateRequestURL(requestURL, baseURL string, allowedHosts []string) error {
request, err := url.Parse(requestURL)
if err != nil || request.Scheme == "" || request.Host == "" {
return fmt.Errorf("plugin request URL must be absolute")
}
base, err := url.Parse(baseURL)
if err != nil || base.Host == "" {
return fmt.Errorf("channel base URL is invalid")
}
requestHost := canonicalHost(request)
if requestHost == canonicalHost(base) {
return nil
}
for _, allowed := range allowedHosts {
allowedURL, parseErr := url.Parse("https://" + strings.TrimSpace(allowed))
if parseErr == nil && requestHost == canonicalHost(allowedURL) {
return nil
}
}
return fmt.Errorf("plugin request host %q is not allowed", request.Host)
}
func canonicalHost(value *url.URL) string {
host := strings.ToLower(value.Hostname())
port := value.Port()
if port == "" || port == "80" && value.Scheme == "http" || port == "443" && value.Scheme == "https" {
return host
}
return net.JoinHostPort(host, port)
}