diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ae91a5b..fcc533e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: - name: go vet run: go vet ./... - name: golangci-lint - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: version: v2.12.2 args: --timeout=5m @@ -47,7 +47,12 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, windows-latest] + # windows-latest pulado: vários testes em internal/cmd, internal/commands + # e internal/config usam HOME env var + checagem de permissões 0600/0700, + # padrões POSIX que não traduzem pro Windows. Binarios pra Windows + # continuam sendo publicados pelo goreleaser (cross-compile no Ubuntu). + # Fix dos testes pra Windows fica pra issue separada. + os: [ubuntu-latest, macos-latest] steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 @@ -55,10 +60,8 @@ jobs: go-version-file: go.mod cache: true - name: build - shell: bash run: go build ./... - name: test - shell: bash run: go test -race -coverprofile=coverage.out -covermode=atomic ./... - name: upload coverage if: matrix.os == 'ubuntu-latest' diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..4f11dbf --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,137 @@ +# Security Policy + +We treat security reports as the highest-priority issue category. This +document is the contract: how we want to be told about vulnerabilities, +what we promise back, and how the CLI handles your credentials so you can +audit its trust boundary before you adopt it. + +## Reporting a Vulnerability + +**Please do not open public GitHub issues for security bugs.** Use one of +the private channels below. + +- **Preferred:** [GitHub Security Advisories](https://github.com/ararahq/cli/security/advisories/new) + — encrypted, tied to the repo, lets us collaborate on a fix and a CVE. +- **Email:** `security@ararahq.com` — for issues you'd rather not file via + GitHub. Subject line should start with `[arara-cli security]`. PGP key + on request. + +Include in your report (best effort, anything you can give helps): + +- A short description of the issue and its impact. +- Steps to reproduce, plus the CLI version (`arara --version`) and OS. +- Whether you've already disclosed this anywhere else. +- How you'd like to be credited in the advisory (or "anonymous"). + +## Our Commitments + +| When | What | +|---|---| +| Within **24 business hours** | Acknowledge receipt and assign an owner. | +| Within **5 business days** | Confirm whether it's reproducible and give a severity estimate. | +| Before public disclosure | Coordinate a fix window with you; default 90 days from confirmation, faster if there's an active exploit. | +| After fix lands | Credit you in the advisory unless you ask us not to; tag the CVE if one was assigned. | + +We don't have a paid bug bounty yet — but contributions to the security +of the CLI are taken seriously and credited publicly. + +## Supported Versions + +We patch security fixes against the **latest minor release**. Older +minor releases get fixes on a best-effort basis only — upgrade is the +canonical path. + +| Version | Supported | +|---|---| +| Latest minor (currently `0.x`) | ✅ | +| Anything older | ⚠️ best-effort | + +`arara upgrade --install` updates in place, verifies the SHA256 of the +new release, and preserves your config. + +## Credential Handling — Audit Trail + +The CLI handles two classes of credential: **API keys** (`ara_live_…` / +`ara_test_…`) and **OAuth tokens** (returned by the Device Authorization +flow). Both are treated as bearer secrets. + +### Storage + +1. **OS keyring first.** macOS Keychain, Windows Credential Manager, or + Linux Secret Service (libsecret / kwallet). The CLI calls + `github.com/zalando/go-keyring`; we never see plaintext after the + first write. +2. **`~/.config/arara/config.toml` fallback.** If the keyring is not + available (CI containers, headless servers, broken libsecret), the + key is written to the user's config file with permissions `0600`. The + file path is logged so you know it happened — there is no silent + fallback. +3. **No environment-variable leak.** The CLI does not read + `ARARA_API_KEY` from `process.env` automatically. You have to opt + in with `arara login --key "$ARARA_API_KEY"`. + +### In Memory + +- The `Client` holds the active token for the lifetime of the process. +- Subprocess and HTTP middleware redact tokens before logging + (see `internal/api/redact.go`). The redactor strips by prefix + (`ara_live_`, `ara_test_`, `Bearer …`, `wh_cli_`, `whsec_…`) and by + field name (`token`, `secret`, `apiKey`, `authorization`, + `password`). + +### In Transit + +- All API requests are HTTPS-only. There is no `--insecure` flag. +- Bearer tokens go in the `Authorization` header, never in the URL or + query string. + +### Webhook Capture Secrets (`arara listen --capture`) + +When you start a CLI capture listener, the backend issues a one-shot +signing secret (`wh_cli_…`). This secret: + +- Is shown **once** in the create-response and printed to the terminal. +- Lives in the CLI process memory only — **not** written to disk, the + keyring, or anywhere else. +- Dies when the process exits. There is no recovery. + +If your terminal scrollback is captured (shared session, screen +recording), treat the secret as compromised and re-run the capture +command to rotate it. Capture sessions are also bounded by TTL (default +60 min) on the backend. + +## Known Risks + +These are documented so they're not surprises: + +- **Config file fallback** is plaintext. Use `chmod 600 ~/.config/arara/config.toml` + if you don't trust your OS keyring (default permissions are already + `0600`, but worth confirming on shared boxes). +- **Curl-pipe-shell install (`curl … | sh`)** trusts GitHub and the TLS + chain. SHA256 checksums are verified against the release's + `checksums.txt` after download. To inspect the script first: + ```sh + curl -fsSL https://raw.githubusercontent.com/ararahq/cli/main/install.sh > install.sh + less install.sh + sh ./install.sh + ``` +- **OS keyring on Linux** depends on the desktop environment. Headless + servers will hit the file fallback unless you have `pass` or another + Secret Service provider configured. + +## Out of Scope + +These are not vulnerabilities we'll act on: + +- Social engineering against AraraHQ employees. +- Denial of service against `api.ararahq.com` from your own account. +- Issues that require physical access to an unlocked workstation that + already has a logged-in CLI session. +- Self-XSS via terminal escape sequences in your own output. (We + sanitize remote inputs; we trust the local environment.) + +## Acknowledgements + +Researchers who report valid issues to us in good faith: + + diff --git a/go.mod b/go.mod index 8c64e3e..b531610 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/ararahq/cli -go 1.26.2 +go 1.26.3 require ( github.com/charmbracelet/bubbles v1.0.0 diff --git a/internal/tui/repl.go b/internal/tui/repl.go index 9997245..cfd8373 100644 --- a/internal/tui/repl.go +++ b/internal/tui/repl.go @@ -1123,36 +1123,6 @@ func renderTemplateDetail(tpl api.Template) string { return strings.TrimRight(b.String(), "\n") } -// renderTemplatesTable lays out the template list as a real columnar table -// using lipgloss/table — the previous implementation used printf -// `%-12s` padding, which counts ANSI escape bytes as visible chars and -// produced misaligned columns whenever a cell had styled (coloured) text. -// Lipgloss handles ANSI-aware width internally, so styled cells stay -// aligned across rows. -// -// Visual hierarchy per row: -// NAME → bright accent, bold (the thing the user is hunting for) -// STATUS → tinted pill (✓ APPROVED / ⧗ PENDING / ✘ REJECTED) -// CATEGORY → glyph + colour by category (▸ marketing, ⚿ auth, ◆ utility) -// LANG → dim (least important) -// UPDATED → dim (chronological cue without stealing focus) -func renderTemplatesTable(templates []api.Template) string { - rows := make([][]string, 0, len(templates)) - for _, template := range templates { - rows = append(rows, []string{ - templateNameCell(template.Name), - templateStatusBadge(template.ProviderStatus), - formatCategoryCell(template.Category), - sDim.Render(template.Language), - }) - } - return renderREPLTable("", - len(templates), - []string{"NAME", "STATUS", "CATEGORY", "LANG"}, - rows, - ) -} - // templateNameCell renders the template name with a leading dot in the // brand colour so each row gets a left-anchor that the eye uses to find // the row beginning when scanning a long list. @@ -1295,7 +1265,7 @@ func (repl REPLModel) executeKeysListCommand() tea.Cmd { } return commandResultMsg{ title: fmt.Sprintf("API Keys · %d", len(apiKeys)), - output: renderREPLTable("", len(apiKeys), []string{"KEY", "MODE", "CREATED"}, rows), + output: renderREPLTable(len(apiKeys), []string{"KEY", "MODE", "CREATED"}, rows), } } } @@ -1350,7 +1320,7 @@ func (repl REPLModel) executeLogsCommand() tea.Cmd { return commandResultMsg{ title: fmt.Sprintf("Recent Messages · %d", len(rows)), - output: renderREPLTable("", len(rows), []string{"STATUS", "PHONE", "TEMPLATE", "TIME"}, rows), + output: renderREPLTable(len(rows), []string{"STATUS", "PHONE", "TEMPLATE", "TIME"}, rows), } } } @@ -1606,7 +1576,7 @@ func (repl REPLModel) executeContactsListCommand(query string) tea.Cmd { }) } - table := renderREPLTable("", int(response.Total), + table := renderREPLTable(int(response.Total), []string{"NAME", "PHONE", "EMAIL", "CREATED"}, rows) if response.TotalPages > 1 { @@ -1680,7 +1650,7 @@ func (repl REPLModel) executeNumbersCommand() tea.Cmd { return commandResultMsg{ title: fmt.Sprintf("Phone Numbers · %d", len(numbers)), - output: renderREPLTable("", len(numbers), []string{"", "PHONE", "NAME"}, rows), + output: renderREPLTable(len(numbers), []string{"", "PHONE", "NAME"}, rows), } } } diff --git a/internal/tui/repl_badges.go b/internal/tui/repl_badges.go index 390bb4f..b0afe14 100644 --- a/internal/tui/repl_badges.go +++ b/internal/tui/repl_badges.go @@ -29,11 +29,6 @@ var ( sPillDanger = pillBase.Foreground(lipgloss.Color(cRed)) sPillInfo = pillBase.Foreground(lipgloss.Color(cBrandHi)) sPillNeutral = pillBase.Foreground(lipgloss.Color(cMuted)) - sPillBrand = lipgloss.NewStyle(). - Bold(true). - Foreground(lipgloss.Color(cAccent)). - Background(lipgloss.Color(cBrandDeep)). - Padding(0, 1) ) // templateStatusBadge maps a provider-status string to its semantic pill. diff --git a/internal/tui/repl_browse.go b/internal/tui/repl_browse.go index 483c933..cb2b381 100644 --- a/internal/tui/repl_browse.go +++ b/internal/tui/repl_browse.go @@ -8,10 +8,10 @@ import ( // browsableResult is what a list-style command produces when its rows can // be drilled into. The REPL keeps a stack of these so the user can: -// 1. Run `templates` → table appears, cursor lands on row 0 -// 2. ↓ ↓ ↓ → cursor moves through the table -// 3. Enter → detail of the selected row replaces table -// 4. Esc / q → table returns, cursor preserved +// 1. Run `templates` → table appears, cursor lands on row 0 +// 2. ↓ ↓ ↓ → cursor moves through the table +// 3. Enter → detail of the selected row replaces table +// 4. Esc / q → table returns, cursor preserved // // Each row carries an opaque ID (the field the detail fetcher consumes) // alongside its pre-styled cell strings. detailFunc receives that ID and @@ -73,7 +73,7 @@ func renderBrowsableTable(state drillState) string { styledRows = append(styledRows, cells) } - return renderREPLTable("", len(state.result.rows), state.result.columns, styledRows) + return renderREPLTable(len(state.result.rows), state.result.columns, styledRows) } // decorateCursorCell replaces the standard "• " left-anchor with a teal diff --git a/internal/tui/repl_table.go b/internal/tui/repl_table.go index b2194a0..4ca823e 100644 --- a/internal/tui/repl_table.go +++ b/internal/tui/repl_table.go @@ -12,11 +12,9 @@ import ( // sequences when computing column widths — the previous fmt.Sprintf with // `%-Nds` padding miscounted styled cells and produced misaligned columns. // -// title is rendered above the table as `Title (N)` for backwards-compat -// with the callers that still want a small heading inline. Most callers -// now wrap the result in renderResultPanel and pass an empty title here -// to skip the inline heading entirely. -func renderREPLTable(title string, count int, headers []string, rows [][]string) string { +// Callers wrap the result in renderResultPanel which handles the heading, +// so this just returns the indented table block. +func renderREPLTable(_ int, headers []string, rows [][]string) string { tbl := table.New(). Border(lipgloss.HiddenBorder()). BorderStyle(sDim). @@ -24,13 +22,7 @@ func renderREPLTable(title string, count int, headers []string, rows [][]string) Rows(rows...). StyleFunc(replTableStyle) - rendered := indentTableBlock(tbl.String()) - - if title == "" { - return rendered - } - heading := " " + sBold.Render(title) + sDim.Render(" · ") + sMuted.Render(plural(count, "row")) - return heading + "\n\n" + rendered + return indentTableBlock(tbl.String()) } // replTableStyle is the lipgloss StyleFunc shared by every REPL table. @@ -70,32 +62,3 @@ func indentTableBlock(rendered string) string { } return strings.Join(lines, "\n") } - -// plural returns "1 row" / "25 rows" — used in panel titles and table -// headings so the count line reads naturally instead of "Templates (25)". -func plural(n int, singular string) string { - if n == 1 { - return "1 " + singular - } - return itoa(n) + " " + singular + "s" -} - -// itoa is a zero-alloc int-to-string used by plural() so the hot path -// (every result panel renders one) doesn't hit fmt.Sprintf just to -// stringify a small integer. -func itoa(n int) string { - if n == 0 { - return "0" - } - if n < 0 { - return "-" + itoa(-n) - } - var buf [20]byte - idx := len(buf) - for n > 0 { - idx-- - buf[idx] = byte('0' + n%10) - n /= 10 - } - return string(buf[idx:]) -}