Skip to content

armgit / ARTEX

Public Imported from GitHub
0

ARTEX - AI autonomous penetration testing system (English translation; upstream: Autumn-27/ARTEX, AGPL-3.0)

fix(db): drop userinfo from an asset URL that cannot be parsed

Coff0xca133b79a0ed3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5af6fb6..c12b2d1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@ All notable changes to this project are documented in this file. The format is b
### Fixed
+- **Asset URLs drop userinfo when parsing fails**: a URL `url.Parse` rejects is no longer stored unchanged. The `scheme://userinfo@` prefix is removed first, so a password in that prefix does not land in the asset row.
- **Docker Compose database passwords with URL-special characters**: `docker-compose.yml` no longer pastes `POSTGRES_PASSWORD` into `ARTEX_PG_DSN`. The server builds the URL from `ARTEX_PG_HOST`, `ARTEX_PG_PORT`, `ARTEX_PG_USER`, `ARTEX_PG_PASSWORD`, `ARTEX_PG_DBNAME` and `ARTEX_PG_SSLMODE`, percent-encoding the user and password, so `/`, `?`, `%`, `@`, `:` and spaces connect. An explicit `ARTEX_PG_DSN` still wins and is not rewritten. `ARTEX_PG_PASSWORD` is removed from the environment with the other startup secrets (#450).
## [0.7.0] - 2026-11-21
diff --git a/db/assets.go b/db/assets.go
index 7cb2d25..899cee9 100644
--- a/db/assets.go
+++ b/db/assets.go
@@ -165,7 +165,7 @@ func calcCSegment(ipStr string) string {
func normalizeURL(raw string) string {
u, err := url.Parse(raw)
if err != nil {
- return raw
+ return stripURLUserinfo(raw)
}
u.Scheme = strings.ToLower(u.Scheme)
u.Host = strings.ToLower(u.Host)
@@ -177,6 +177,25 @@ func normalizeURL(raw string) string {
return s
}
+// stripURLUserinfo removes scheme://userinfo@ when url.Parse cannot. The
+// userinfo is the span before the last @ that still sits in the authority.
+func stripURLUserinfo(raw string) string {
+ i := strings.Index(raw, "://")
+ if i < 0 {
+ return raw
+ }
+ rest := raw[i+3:]
+ authEnd := len(rest)
+ if j := strings.IndexAny(rest, "/?#"); j >= 0 {
+ authEnd = j
+ }
+ at := strings.LastIndex(rest[:authEnd], "@")
+ if at < 0 {
+ return raw
+ }
+ return raw[:i+3] + rest[at+1:]
+}
+
// parseURL extracts domain, port, service_name from a URL.
func parseURL(raw string) (domain string, port int, serviceName string) {
u, err := url.Parse(raw)
diff --git a/db/assets_test.go b/db/assets_test.go
index ff1d7ef..b216eb3 100644
--- a/db/assets_test.go
+++ b/db/assets_test.go
@@ -908,6 +908,7 @@ func TestNormalizeURL(t *testing.T) {
{"https://[email protected]/", "https://example.com"},
{"https://u:[email protected]:8443/users/@alice?x=1", "https://example.com:8443/users/@alice?x=1"},
{"https://example.com/@me?r=http://a:b@x/", "https://example.com/@me?r=http://a:b@x/"},
+ {"http://user:secret@ex ample.com/a", "http://ex ample.com/a"},
}
for _, tc := range tests {
got := normalizeURL(tc.raw)