Skip to content

fix: mask app_secret input and guard confirm() against non-TTY crash - #1

Open
datin-antasena wants to merge 1 commit into
saadiq:mainfrom
datin-antasena:fix/security-masked-secret-input
Open

datin-antasena wants to merge 1 commit into
saadiq:mainfrom
datin-antasena:fix/security-masked-secret-input

Conversation

@datin-antasena

Copy link
Copy Markdown

Summary

Two fixes:

1. Mask app_secret during auth login

Previously, Threads App secret: input used readline.question() which echoed the secret in plain text to the terminal. Anyone looking at the screen could see the full credential.

Now uses readSecret() from display.ts — a masked input function that:

  • Prints * for each typed character (TTY mode)
  • Supports backspace
  • Handles Ctrl+C gracefully
  • Falls back to plain input when stdin is not a TTY (CI, pipes)

2. Fix confirm() crash in non-TTY environments

confirm() called process.stdin.setRawMode() without checking process.stdin.isTTY. When stdin was piped or redirected (CI, subprocess), setRawMode throws an error, crashing the tool.

Now checks isTTY first: exits early with false and a log message in non-interactive mode.

Changes

  • src/utils/display.ts: Added readSecret() function, added isTTY guard to confirm()
  • src/commands/auth.ts: Replaced question() with readSecret() for app_secret prompt

Testing

  • readSecret tested manually in TTY and non-TTY modes
  • confirm no longer crashes when stdin is a pipe
  • Existing tests unchanged and passing

- Replace readline.question() for Threads App secret with readSecret() that uses raw-mode input and prints asterisks instead of echoing characters to the terminal
- Add isTTY check in confirm() to prevent setRawMode crash in non-interactive environments (CI, pipes, subprocesses)
- Add readSecret() utility to display.ts supporting both TTY (masked) and non-TTY (plain) modes
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.

1 participant