Skip to content

fix(selfhost): avoid postgres url argv leaks - #2461

Merged
JSONbored merged 2 commits into
mainfrom
codex/propose-fix-for-postgres-password-exposure
Jul 2, 2026
Merged

fix(selfhost): avoid postgres url argv leaks#2461
JSONbored merged 2 commits into
mainfrom
codex/propose-fix-for-postgres-password-exposure

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Motivation

  • Prevent accidental disclosure of Postgres credentials by removing expanded Postgres URLs from psql and process argv, since command-line arguments can be read by other local users on typical systems.

Description

  • Route Postgres calls in the Grafana reporting exporter through libpq environment variable PGDATABASE instead of passing the full URL as a psql positional argument in scripts/export-grafana-reporting-db.sh.
  • Prefer environment-based usage by changing the self-host documentation example to DATABASE_URL=… and removing the expanded --postgres-url "$DATABASE_URL" command-line example in apps/gittensory-ui/src/routes/docs.self-hosting-backup-scaling.tsx.
  • Update the migrator usage text in scripts/migrate-selfhost-sqlite-to-postgres.ts to recommend DATABASE_URL and warn against using --postgres-url on shared hosts.
  • Add a regression assertion to the fake psql helper in test/unit/selfhost-grafana-reporting.test.ts that fails if a Postgres URL appears in psql argv or if the URL is not supplied via PGDATABASE.

Testing

  • Ran the unit suite for the modified exporter tests with npx vitest run test/unit/selfhost-grafana-reporting.test.ts, which passed (all tests green).
  • Ran UI lint with npm run ui:lint, which completed successfully with existing warnings only (no errors).
  • Ran type checking with npm run typecheck, which completed successfully.
  • Ran git diff --check and local formatting commands, which reported no blocking issues; npm run test:ci and npm audit --audit-level=moderate could not complete due to external network/setup constraints and therefore were not fully exercised.

Codex Task

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 2, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
gittensory-ui 6511de4 Commit Preview URL

Branch Preview URL
Jul 02 2026, 06:23 AM

@loopover-orb

loopover-orb Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Warning

🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨

⏸️ Gittensory review result - manual review recommended

Review updated: 2026-07-02 06:25:36 UTC

4 files · no blockers · readiness 68/100 · CI pending · blocked

⏸️ Suggested Action - Manual Review

  • The AI review could not be completed for this change, so the gate is held for a human reviewer rather than passed automatically. It re-evaluates on the next update.

Review summary
AI review is already running for this PR head in another Gittensory pass. Gittensory is holding this PR for manual review until that pass completes.

Nits — 2 non-blocking
  • AI review already in progress for this PR head — The gate is held for a human reviewer rather than passed automatically; it re-evaluates once the in-flight review completes or on the next update.
  • Readiness score is below the configured threshold — Use the readiness panel as advisory maintainer context; the score does not block this PR.
Signal Result Evidence
Code review ✅ No blockers No AI review summary
Linked issue ⚠️ Missing No linked issue or no-issue rationale found.
Related work ⚠️ 2 scoped overlaps Top overlaps are listed below; lower-confidence bulk is hidden.
Change scope ❌ 8/20 High review scope from cached public metadata (size label size:S; no linked issue context).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 65 registered-repo PR(s), 55 merged, 548 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 65 PR(s), 548 issue(s).
Gate result ⚠️ Not blocking Advisory; not blocking this PR.
Review context
  • Author: JSONbored
  • Role context: owner (maintainer lane)
  • Public audience mode: oss maintainer
  • Lane context: Repository registration is not available in the local Gittensory cache.
  • Public profile languages: not available
  • Official Gittensor activity: 65 PR(s), 548 issue(s).
  • Related work: Titles/paths share 7 meaningful terms. (PR #2459)
  • Related work: Titles/paths share 6 meaningful terms. (PR #2470, PR #2473)
Contributor next steps
  • Treat this as maintainer-lane context rather than normal contributor-lane activity.
  • Explain no-issue PR.
  • Review top overlaps.
  • Add a concise scope and risk note.
  • Triage stale or unlinked PRs.
  • No action.
  • Link the issue being solved, or explicitly explain why this is a no-issue PR.
  • Check active issues and PRs before submitting.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.

  • Re-run Gittensory review

@loopover-orb loopover-orb Bot added gittensor gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. labels Jul 2, 2026
@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.83%. Comparing base (9e657e1) to head (6511de4).
⚠️ Report is 81 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2461   +/-   ##
=======================================
  Coverage   95.83%   95.83%           
=======================================
  Files         224      224           
  Lines       24996    24996           
  Branches     9091     9091           
=======================================
  Hits        23954    23954           
  Misses        428      428           
  Partials      614      614           
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The postgres migrator now reads DATABASE_URL from the environment
instead of taking --postgres-url on argv (avoiding a credential leak
through process listings), and the docs were updated to match. But
the snippet set DATABASE_URL as a plain (non-exported) shell
assignment, so a user pasting the block verbatim would run the two
following npm run selfhost:postgres:migrate commands without the
variable in their environment, failing with "--postgres-url or
DATABASE_URL must be a postgres:// URL".
@JSONbored
JSONbored merged commit 65d43c8 into main Jul 2, 2026
12 checks passed
@JSONbored
JSONbored deleted the codex/propose-fix-for-postgres-password-exposure branch July 2, 2026 06:29
@github-project-automation github-project-automation Bot moved this from Todo to Done in gittensory - v1 roadmap Jul 2, 2026
JSONbored added a commit that referenced this pull request Jul 3, 2026
…nd manual-review classification (#2740)

* fix(selfhost): fix Grafana reporting exporter's Postgres connection and manual-review classification

PGDATABASE="$PG_DB" psql treats PGDATABASE as a literal database name,
not a connection URL -- libpq does not URI-expand it the way it does a
positional dbname argument, so every Postgres-backed reporting export
was silently falling back to a local Unix-socket connection attempt
and failing. Fix: split the postgres:// URL into PGHOST/PGPORT/PGUSER/
PGPASSWORD/PGDATABASE/PGSSLMODE and export them, so psql connects over
the intended TCP host while the credential never appears on argv
(preserving the process-listing leak protection from #2461).

Also broadens the manual-review classification: a 'neutral' gate
conclusion is now counted as 'manual' (matching gateHeld's held-for-
review definition), not silently bucketed as 'commented'/'comment'.

* fix(selfhost): handle bracketed IPv6 hosts in the Postgres URL splitter

postgres://u:p@[::1]:5432/db split host:port on the first colon, which
cuts a bracketed IPv6 literal apart (PGHOST='[', PGPORT=':1]:5432')
since the address itself contains colons. Handle the bracketed forms
(with and without a trailing port) before falling back to plain
first-colon splitting for an ordinary hostname/IPv4 host.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant