Skip to content

Security hardening: input validation, HTTPS, and safer string handling#1

Merged
balgaly merged 3 commits into
mainfrom
claude/security-review-main-h1N3y
Apr 13, 2026
Merged

Security hardening: input validation, HTTPS, and safer string handling#1
balgaly merged 3 commits into
mainfrom
claude/security-review-main-h1N3y

Conversation

@balgaly
Copy link
Copy Markdown
Owner

@balgaly balgaly commented Apr 13, 2026

Summary

This PR improves security and robustness across the brif and statusline scripts through input validation, protocol upgrades, safer string handling, and proper file permissions.

Key Changes

Input Validation & Sanitization

  • Added session ID validation in brif, brif-pane.sh, and brif-pane.ps1 to reject IDs containing characters outside [a-zA-Z0-9._-]
  • Sanitize session ID in brif before truncation to prevent injection attacks
  • Validates against regex pattern ^[a-zA-Z0-9._-]+$ before using in file paths

HTTPS Protocol Upgrade

  • Changed http://ip-api.com to https://ip-api.com in statusline.sh and statusline.ps1 for secure geolocation lookups

Safer String Handling

  • Converted ANSI color code assignments from single-quoted strings to $'...' syntax in statusline.sh for proper escape sequence interpretation
  • Replaced printf '%b' (interpret backslashes) with printf '%s' (literal strings) throughout statusline.sh to prevent unintended escape sequence processing
  • Fixed accent line construction to use $'...' syntax and concatenate with ${C_RESET} variable instead of raw escape codes

File Permissions & Atomic Writes

  • Added chmod 700 to session directories in brif, hooks/post-tool-use.sh, hooks/user-prompt.sh, and install.sh to restrict access to owner only
  • Implemented atomic file creation in brif using temporary file + mv pattern for mission.json to prevent partial writes

Environment Variable Handling

  • Changed brif to pass SESSION_ID via tmux set-environment instead of inline shell variable to avoid quoting injection vulnerabilities
  • Updated corresponding tmux send-keys command to rely on environment variable instead of inline substitution

Implementation Details

  • Session ID validation happens early in script execution before any file operations
  • Atomic writes use .tmp suffix pattern to ensure data integrity
  • Directory permissions (700) ensure only the owning user can read/write session data
  • ANSI color code changes maintain visual output while improving correctness of escape sequence handling

https://claude.ai/code/session_01EpP9ZyDFTvZj8ZBeWJfVks

claude added 3 commits April 12, 2026 10:20
- brif: sanitize --resume arg before building SESSION_ID to prevent
  shell metacharacters from breaking tmux command strings; also pass
  BRIF_SESSION_ID via `tmux set-environment` instead of inline
  interpolation, eliminating the quoting injection surface entirely
- brif-pane.sh: add SESSION_ID regex validation (^[a-zA-Z0-9._-]+$)
  before using it to construct ~/.claude/brif/ file paths, matching
  the guard already present in statusline.sh and the hook scripts
- statusline.sh: upgrade ip-api.com geolocation fetch from HTTP to
  HTTPS to prevent plaintext network exposure of the request
- brif: write initial mission.json atomically via .tmp + mv, matching
  the pattern used in the hook scripts

https://claude.ai/code/session_01EpP9ZyDFTvZj8ZBeWJfVks
…sions

statusline.sh:
- Replace backslash-escape ANSI constants with $'\033' (actual ESC bytes)
  so printf '%b' is no longer needed; all output lines now use printf '%s',
  eliminating the risk of terminal-escape injection from user-controlled
  strings (directory names, git data, model names from JSON)

statusline.ps1:
- Upgrade ip-api.com geolocation fetch from HTTP to HTTPS (mirrors the
  Bash fix from the previous commit)

brif-pane.ps1:
- Add SessionId regex validation (^[a-zA-Z0-9._-]+$) before constructing
  ~/.claude/brif/<id>/... file paths, matching the guard in brif-pane.sh
  and the rest of the Bash toolchain

install.sh / brif / hooks/post-tool-use.sh / hooks/user-prompt.sh:
- Set chmod 700 on all brif session directories at creation time so
  events.jsonl (which logs full user prompt text) is not world-readable
  on multi-user systems

https://claude.ai/code/session_01EpP9ZyDFTvZj8ZBeWJfVks
@balgaly balgaly merged commit 1846bfd into main Apr 13, 2026
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