Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Paste protection doesn't work with clipboard managers

Aperta
#96 1 commento 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
macos, swift
Ambito
desktop, security

Direzione di ricerca

La issue non indica file o test del repository. Inizia dalla gestione esistente degli eventi di protezione dall’incolla e confrontala con l’approccio segnalato basato su CGEvent.tapCreate e pasteCallback; il lavoro è completo quando gli incolla selezionati tramite Raycast attivano l’avviso di protezione, mentre gli incolla ordinari con cmd+v continuano a essere coperti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

I've been playing with this feature and found that content pasted using Raycast, i.e. retrieved from the clipboard manager and pasted into the frontmost application, doesn't trigger the paste protection alert.

It turns out that paste operations from the Raycast clipboard manager don't send cmd+v so isn't caught as a paste event.

The code snippet below does reliably trigger for paste events both using cmd+v as well as pastes from the Raycast clipboard manager.
Code was generated by Gemini, don't hate me for the use of emojis.

import Foundation
import CoreGraphics
import AppKit

// Virtual Key Code for 'V' is 9
let kVK_ANSI_V: Int64 = 9

func pasteCallback(proxy: CGEventTapProxy, type: CGEventType, event: CGEvent, refcon: UnsafeMutableRawPointer?) -> Unmanaged<CGEvent>? {
    guard type == .keyDown else { return Unmanaged.passUnretained(event) }

    let keyCode = event.getIntegerValueField(.keyboardEventKeycode)
    let flags = event.flags

    if keyCode == kVK_ANSI_V && flags.contains(.maskCommand) {
        // 1. Get the PID of the process that created this event
        // For physical hardware, this is typically 0.
        // For Raycast/injected events, this is the PID of the source app.
        let sourcePID = event.getIntegerValueField(.eventSourceUnixProcessID)
        
        // 2. Get the PID of the process receiving the event
        let targetPID = event.getIntegerValueField(.eventTargetUnixProcessID)
        
        print("\n--- [PASTE EVENT DETECTED] ---")
        
        if sourcePID == 0 {
            print("👤 Type: HUMAN (Hardware)")
            print("   Action: User pressed physical keys")
        } else {
            let sourceName = getAppName(pid: Int32(sourcePID))
            print("🤖 Type: SYNTHETIC (Injected)")
            print("   Source: \(sourceName) (PID: \(sourcePID))")
        }
        
        let targetName = getAppName(pid: Int32(targetPID))
        print("   Target: \(targetName) (PID: \(targetPID))")
    }

    return Unmanaged.passUnretained(event)
}

// Helper to turn a PID into an App Name
func getAppName(pid: Int32) -> String {
    if let app = NSRunningApplication(processIdentifier: pid) {
        return app.localizedName ?? "Unknown App"
    }
    return "System/Background Process"
}

func run() {
    let mask = (1 << CGEventType.keyDown.rawValue)
    
    // Using .cgAnnotatedSessionEventTap is critical to see the PIDs
    guard let tap = CGEvent.tapCreate(
        tap: .cgAnnotatedSessionEventTap,
        place: .headInsertEventTap,
        options: .defaultTap,
        eventsOfInterest: CGEventMask(mask),
        callback: pasteCallback,
        userInfo: nil
    ) else {
        print("Error: Accessibility permissions required.")
        return
    }

    let runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, tap, 0)
    CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, .commonModes)
    CGEvent.tapEnable(tap: tap, enable: true)
    
    print("Monitoring source and target of all pastes...")
    CFRunLoopRun()
}

run()

I know this is a bit of an edge case and probably is straying into feature creep but thought it was worth mentioning.

Lingua principale
Objective-C
Stelle
859
Fork
50
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di objective-see/BlockBlock

Tutte le issue di objective-see/BlockBlock

Issue simili

Altre issue su Objective-C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.