From 6f0d9d53cd7fda38f1063733ec9cef43a98ab7a2 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 29 May 2026 15:25:21 +0200 Subject: [PATCH] Keep sensitive clipboard contents out of history Restore the clipboard watcher behavior that drops CLIPBOARD_STATE=sensitive events, which password managers use for copied secrets. Use the same sensitive foreground clipboard path for emoji insertion instead of a custom history marker, and keep the password-manager MIME hint ignored as a fallback. --- bin/omarchy-menu-emoji-insert | 3 --- shell/plugins/clipboard/capture.sh | 22 ++++------------------ test/shell.d/clipboard-test.sh | 20 ++++++++++---------- test/shell.d/emojis-test.sh | 9 +++------ 4 files changed, 17 insertions(+), 37 deletions(-) diff --git a/bin/omarchy-menu-emoji-insert b/bin/omarchy-menu-emoji-insert index 389cce6b..583702e0 100755 --- a/bin/omarchy-menu-emoji-insert +++ b/bin/omarchy-menu-emoji-insert @@ -6,13 +6,10 @@ # omarchy:hidden=true emoji="${1:-}" -emoji_ignore_file="${XDG_RUNTIME_DIR:-${TMPDIR:-/tmp}}/omarchy-emoji-insert-ignore" copy_pid="" [[ -n $emoji ]] || exit -mkdir -p "${emoji_ignore_file%/*}" -printf '%s' "$emoji" >"$emoji_ignore_file" printf '%s' "$emoji" | wl-copy --type text/plain --sensitive --foreground & copy_pid=$! diff --git a/shell/plugins/clipboard/capture.sh b/shell/plugins/clipboard/capture.sh index f0d87100..ced86fa1 100755 --- a/shell/plugins/clipboard/capture.sh +++ b/shell/plugins/clipboard/capture.sh @@ -4,28 +4,14 @@ set -o pipefail STATE_DIR="${XDG_STATE_HOME:-$HOME/.local/state}/omarchy" IMAGE_DIR="$STATE_DIR/clipboard-images" -EMOJI_IGNORE_FILE="${XDG_RUNTIME_DIR:-${TMPDIR:-/tmp}}/omarchy-emoji-insert-ignore" mkdir -p "$IMAGE_DIR" -should_ignore_next_copy() { - local marker_mtime=0 - - [[ -f $EMOJI_IGNORE_FILE ]] || return 1 - - marker_mtime=$(stat -c %Y "$EMOJI_IGNORE_FILE" 2>/dev/null || printf '0') - if (( $(date +%s) - marker_mtime > 5 )); then - rm -f "$EMOJI_IGNORE_FILE" - return 1 - fi - - rm -f "$EMOJI_IGNORE_FILE" - return 0 -} - -should_ignore_next_copy && exit 0 - types=$(wl-paste --list-types 2>/dev/null || true) +if [[ ${CLIPBOARD_STATE:-} == "sensitive" ]] || grep -qx 'x-kde-passwordManagerHint' <<<"$types"; then + exit 0 +fi + emit_image() { local mime="$1" local ext="$2" diff --git a/test/shell.d/clipboard-test.sh b/test/shell.d/clipboard-test.sh index 1b22cad9..68c63481 100644 --- a/test/shell.d/clipboard-test.sh +++ b/test/shell.d/clipboard-test.sh @@ -138,7 +138,7 @@ SH cat >"$TMPDIR/bin/wl-paste" <<'SH' #!/bin/bash if [[ $1 == "--list-types" ]]; then - printf 'text/plain\n' + printf '%b' "${WL_PASTE_TYPES:-text/plain\n}" elif [[ $1 == "--type" && $2 == "text" ]]; then printf '%s' "${WL_PASTE_TEXT:-terminal copy}" fi @@ -167,17 +167,17 @@ SH chmod +x "$TMPDIR/bin/wl-copy" "$TMPDIR/bin/wl-paste" "$TMPDIR/bin/wtype" "$TMPDIR/bin/omarchy-launch-browser" "$TMPDIR/bin/omarchy-launch-editor" "$TMPDIR/bin/satty" +capture_output=$(XDG_RUNTIME_DIR="$TMPDIR" PATH="$TMPDIR/bin:$PATH" "$ROOT/shell/plugins/clipboard/capture.sh") +[[ $capture_output == '{"type":"text","text":"terminal copy"}' ]] || fail "clipboard capture records normal text events" +pass "clipboard capture records normal text events" + capture_output=$(CLIPBOARD_STATE=sensitive XDG_RUNTIME_DIR="$TMPDIR" PATH="$TMPDIR/bin:$PATH" "$ROOT/shell/plugins/clipboard/capture.sh") -[[ $capture_output == '{"type":"text","text":"terminal copy"}' ]] || fail "clipboard capture records sensitive text events" -pass "clipboard capture records sensitive text events" +[[ -z $capture_output ]] || fail "clipboard capture ignores sensitive clipboard events" +pass "clipboard capture ignores sensitive clipboard events" -printf '😀' >"$TMPDIR/omarchy-emoji-insert-ignore" -capture_output=$(WL_PASTE_TEXT="😀" XDG_RUNTIME_DIR="$TMPDIR" PATH="$TMPDIR/bin:$PATH" "$ROOT/shell/plugins/clipboard/capture.sh") -[[ -z $capture_output ]] || fail "clipboard capture ignores transient emoji insert" -pass "clipboard capture ignores transient emoji insert" - -[[ ! -e "$TMPDIR/omarchy-emoji-insert-ignore" ]] || fail "clipboard capture consumes transient emoji marker" -pass "clipboard capture consumes transient emoji marker" +capture_output=$(WL_PASTE_TYPES="text/plain\nx-kde-passwordManagerHint\n" XDG_RUNTIME_DIR="$TMPDIR" PATH="$TMPDIR/bin:$PATH" "$ROOT/shell/plugins/clipboard/capture.sh") +[[ -z $capture_output ]] || fail "clipboard capture ignores password manager hint" +pass "clipboard capture ignores password manager hint" jq -n --arg text "$(printf 'large block line 1\nlarge block line 2\n')" '[{type:"text", text:"ignored"}, {type:"text", text:$text}]' >"$TMPDIR/home/.local/state/omarchy/clipboard-history.json" diff --git a/test/shell.d/emojis-test.sh b/test/shell.d/emojis-test.sh index 983ebe00..003fcc9a 100644 --- a/test/shell.d/emojis-test.sh +++ b/test/shell.d/emojis-test.sh @@ -49,7 +49,7 @@ JS TMPDIR=$(mktemp -d) trap 'rm -rf "$TMPDIR"' EXIT -mkdir -p "$TMPDIR/bin" "$TMPDIR/runtime" +mkdir -p "$TMPDIR/bin" cat >"$TMPDIR/bin/wl-copy" <<'SH' #!/bin/bash @@ -76,15 +76,12 @@ SH chmod +x "$TMPDIR/bin/wl-copy" "$TMPDIR/bin/wtype" "$TMPDIR/bin/sleep" WL_COPY_OUT="$TMPDIR/copy" WL_COPY_EMOJI_OUT="$TMPDIR/emoji" WTYPE_OUT="$TMPDIR/wtype" PATH="$TMPDIR/bin:$PATH" \ - XDG_RUNTIME_DIR="$TMPDIR/runtime" "$ROOT/bin/omarchy-menu-emoji-insert" "😀" + "$ROOT/bin/omarchy-menu-emoji-insert" "😀" [[ $(<"$TMPDIR/emoji") == "😀" ]] || fail "emoji insert helper copies emoji transiently" pass "emoji insert helper copies emoji transiently" -[[ $(<"$TMPDIR/runtime/omarchy-emoji-insert-ignore") == "😀" ]] || fail "emoji insert helper marks transient emoji for history ignore" -pass "emoji insert helper marks transient emoji for history ignore" - -[[ $(<"$TMPDIR/emoji.args") == "--type text/plain --sensitive --foreground" ]] || fail "emoji insert helper serves transient clipboard in foreground" +[[ $(<"$TMPDIR/emoji.args") == "--type text/plain --sensitive --foreground" ]] || fail "emoji insert helper serves sensitive transient clipboard in foreground" pass "emoji insert helper serves transient clipboard in foreground" [[ $(<"$TMPDIR/wtype") == "-M shift -k Insert -m shift" ]] || fail "emoji insert helper pastes with shift insert"