Skip to content

Commit 31471af

Browse files
fix(cli): send GitHub PAT in POST body, not the URL query string (#159)
GetNullifyToken exchanged the GitHub PAT for a Nullify token via GET /auth/github_token?token=…, putting the secret in the URL where it leaks into access logs and proxies. Send {owner, token} as a JSON POST body instead. Requires the backend POST support (nullify monorepo auth/ PR #5485) to be deployed first; the backend keeps GET for older CLIs. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent cd192a8 commit 31471af

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎internal/lib/get_token.go‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package lib
22

33
import (
4+
"bytes"
45
"context"
56
"encoding/json"
67
"errors"
78
"fmt"
89
"net/http"
9-
"net/url"
1010
"os"
1111
"strings"
1212
"time"
@@ -60,13 +60,19 @@ func GetNullifyToken(
6060

6161
owner := parts[0]
6262

63-
// TODO(security): Migrate to POST with JSON body on the backend (security-droid) to avoid sending GitHub token in query string.
64-
tokenURL := fmt.Sprintf("https://%s/auth/github_token?token=%s&owner=%s", nullifyHost, url.QueryEscape(githubTokenFlag), url.QueryEscape(owner))
63+
// Send the PAT in a POST body, never the URL, so it can't leak into
64+
// access logs or proxies. (The backend retains GET for older CLIs.)
65+
reqBody, err := json.Marshal(map[string]string{"owner": owner, "token": githubTokenFlag})
66+
if err != nil {
67+
return "", err
68+
}
69+
tokenURL := fmt.Sprintf("https://%s/auth/github_token", nullifyHost)
6570

66-
req, err := http.NewRequestWithContext(ctx, http.MethodGet, tokenURL, nil)
71+
req, err := http.NewRequestWithContext(ctx, http.MethodPost, tokenURL, bytes.NewReader(reqBody))
6772
if err != nil {
6873
return "", err
6974
}
75+
req.Header.Set("Content-Type", "application/json")
7076

7177
httpClient := &http.Client{Timeout: 30 * time.Second}
7278
res, err := httpClient.Do(req)

0 commit comments

Comments
 (0)