4 Commits

Author SHA1 Message Date
4125a4c102 fix(security): keep credentials off argv and plaintext transports
- M7: ResolveToken accepts the token via the HF_TOKEN env var (so it need
  not appear in argv, where it's visible in ps/shell history); the HTTP
  client refuses to send a token / API key over plaintext http:// to a
  non-loopback host (use https://). Loopback http is still allowed for
  local dev.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-31 20:16:36 +01:00
h z
c0ab087436 Merge pull request 'fix(cli): assign-schedule-type dispatch at top level' (#8) from fix/assign-schedule-type-dispatch into main 2026-05-29 07:47:28 +00:00
3edabb72ba fix(cli): assign-schedule-type dispatch at top level
`assign-schedule-type` is registered in CommandSurface() as a Group, so
the default branch of main()'s switch picks it up via findGroup() and
hands it to handleGroup. handleGroup then treats args[0] (the agent-id)
as a subcommand name, fails findSubCommand, and errors:

    unknown assign-schedule-type subcommand: <agent-id>

The group has no subcommands — it's a leaf — so the call never reaches
handleAssignScheduleType. Add an explicit top-level case before the
default branch so the leaf bypasses the group dispatcher.

Pre-fix repro:
    $ AGENT_ID=ard hf assign-schedule-type analyst1 standard
    unknown assign-schedule-type subcommand: analyst1

Post-fix:
    $ AGENT_ID=ard CLAW_IDENTIFIER=server-t2 hf assign-schedule-type analyst1 standard
    Assigned schedule type 'standard' to agent 'analyst1'

Surfaced during recruitment workflow Step 5 on prod (sherlock/agent-resource-director).
2026-05-29 08:46:28 +01:00
h z
1c9e90b033 Merge pull request #7 2026-05-26 11:48:21 +00:00
3 changed files with 50 additions and 4 deletions

View File

@@ -68,6 +68,11 @@ func main() {
default:
output.Errorf("unknown agent subcommand: %s", args[1])
}
case "assign-schedule-type":
// Leaf command (no subcommands) — args are <agent-id> <type-name>.
// Must dispatch at top level because handleGroup treats args[0] as
// a subcommand name and would error "unknown ... subcommand: <agent-id>".
handleAssignScheduleType(args[1:])
default:
if group, ok := findGroup(args[0]); ok {
handleGroup(group, args[1:])

View File

@@ -5,7 +5,9 @@ import (
"encoding/json"
"fmt"
"io"
"net"
"net/http"
neturl "net/url"
"strings"
"time"
)
@@ -70,8 +72,39 @@ func (e *RequestError) Error() string {
return fmt.Sprintf("HTTP %d: %s", e.StatusCode, e.Body)
}
// guardPlaintextCreds refuses to transmit a token / API key over a plaintext
// http:// connection to a non-loopback host (prevents credential interception).
func (c *Client) guardPlaintextCreds() error {
if c.Token == "" && c.APIKey == "" {
return nil
}
u, err := neturl.Parse(c.BaseURL)
if err != nil || u.Scheme != "http" {
return nil // parse errors and https:// are fine
}
if isLoopbackHost(u.Hostname()) {
return nil
}
return fmt.Errorf("refusing to send credentials over plaintext http:// to non-loopback host %q — use an https:// base URL (hf config set-url ...)", u.Hostname())
}
// isLoopbackHost reports whether h is a loopback address or localhost name.
func isLoopbackHost(h string) bool {
h = strings.ToLower(h)
if h == "localhost" || strings.HasSuffix(h, ".localhost") {
return true
}
if ip := net.ParseIP(h); ip != nil {
return ip.IsLoopback()
}
return false
}
// Do executes an HTTP request and returns the response body bytes.
func (c *Client) Do(method, path string, body io.Reader) ([]byte, error) {
if err := c.guardPlaintextCreds(); err != nil {
return nil, err
}
url := c.BaseURL + path
req, err := http.NewRequest(method, url, body)
if err != nil {

View File

@@ -1,6 +1,9 @@
package commands
import (
"os"
"strings"
"git.hangman-lab.top/zhi/HarborForge.Cli/internal/mode"
"git.hangman-lab.top/zhi/HarborForge.Cli/internal/output"
"git.hangman-lab.top/zhi/HarborForge.Cli/internal/passmgr"
@@ -20,11 +23,16 @@ func ResolveToken(tokenFlag string) string {
}
return tok
}
// manual mode
if tokenFlag == "" {
output.Error("--token <token> required or execute this with pcexec")
}
// manual mode — prefer the explicit flag, else fall back to the HF_TOKEN
// env var so the token need not appear in argv (visible via `ps`/history).
if tokenFlag != "" {
return tokenFlag
}
if env := strings.TrimSpace(os.Getenv("HF_TOKEN")); env != "" {
return env
}
output.Error("--token <token> or HF_TOKEN env required, or execute this with pcexec")
return ""
}
// RejectTokenInPaddedCell checks if --token was passed in padded-cell mode