Skip to content

fix(cmd): address security, bugs, and maintainability in plikd CLI#620

Merged
camathieu merged 4 commits intomasterfrom
fix/plikd-cmd-review
Feb 22, 2026
Merged

fix(cmd): address security, bugs, and maintainability in plikd CLI#620
camathieu merged 4 commits intomasterfrom
fix/plikd-cmd-review

Conversation

@camathieu
Copy link
Copy Markdown
Member

What

Comprehensive review and fix of the plikd server CLI (server/cmd/), addressing security issues, bugs, maintainability, and documentation gaps.

Why

A critical review of the CLI code surface uncovered several issues ranging from a panic on plikd import with no arguments, to a dangerous silent fallthrough to mass-delete in file delete, to credential leakage in log output.

Changes

Security

  • Remove DB connection strings from logsexport.go, import.go no longer print ConnectionString (may contain credentials)
  • Require explicit flag for file deletefile delete now requires --file, --upload, or --all instead of silently falling through to mass-delete when no flag is provided
  • Fix user delete orderingdeleteUser now soft-deletes uploads → cleans data backend → deletes user metadata, preventing orphaned blobs

Bugs

  • Fix panic in importplikd import with no arguments would panic due to missing os.Exit(1) after error message
  • Fix os.Exit in sync.Once — Init functions now store errors and check after Do(), avoiding fragile os.Exit inside closures
  • Fix copy-paste errors in token.go — Three error messages incorrectly referenced "users" instead of "tokens"
  • Refactor signal handling — Main goroutine now blocks on signal channel directly, enabling proper cleanup and error checking on Shutdown()

Maintainability

  • Extract parseMaxSize/parseMaxTTL helpers — Removes ~50 lines of duplicated parsing logic between createUser and updateUser
  • Use cmd.Flags().Changed() consistentlyupdateUser now checks all fields (including name/email) via Changed() instead of mixing empty-string checks
  • Add success messages — Delete operations now confirm completion
  • Add progress output to clean — Prints start/completion messages

Documentation

  • Add Example fields — All subcommands now have cobra Example for --help output
  • Document positional argsimport/export Use strings now show [input-file]/[output-file]
  • Config search order--config flag help text now documents the full search order
  • Update ARCHITECTURE.md — CMD table reflects new subcommands and flag requirements

Testing

  • make lint
  • make client server
  • make test ✅ (full test suite, exit 0)

ca.mathieu and others added 3 commits February 21, 2026 23:27
Security:
- Remove database connection strings from export/import log output
- Require explicit --file, --upload, or --all flag for file delete
  (no more silent fallthrough to mass-delete)
- Reorder deleteUser: soft-delete uploads → clean data → delete user
  to prevent orphaned blobs

Bugs:
- Add missing os.Exit(1) in import.go (no-arg invocation would panic)
- Move os.Exit out of sync.Once closures in init functions
- Fix copy-paste error messages in token.go
- Refactor signal handling to block on channel directly

Maintainability:
- Extract parseMaxSize/parseMaxTTL helpers (remove ~50 lines duplication)
- Use cmd.Flags().Changed() consistently in updateUser
- Add success confirmation messages to delete operations
- Add progress output to clean command

Documentation:
- Add cobra Example fields to all subcommands
- Document positional args in import/export Use strings
- Add config search order to --config flag help text
- Update ARCHITECTURE.md cmd table
- New operations/server-cli.md page covering user, token, file, and
  clean commands with flags, examples, and warnings
- Fix stale sample output in import-export.md (remove connection strings)
- Add Server CLI entry to sidebar navigation
Copy link
Copy Markdown
Member

@bodji bodji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@camathieu camathieu merged commit 5aa8944 into master Feb 22, 2026
4 checks passed
@camathieu camathieu deleted the fix/plikd-cmd-review branch March 7, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants