Skip to content

Kainaat Singh

— Geek is Chic —

Menu
  • Home
Menu

Shadow AI Data Leak Guard

Posted on March 16, 2026March 16, 2026 by Kainaat

Leveling Up My Python Coding: Refactoring and Native macOS Popups

Today was a great day for improving both the architecture and the user experience of my Python project, Shadow Guard—a tool that monitors my clipboard to prevent sensitive data leaks.

1. From Monolithic to Modular

When I first wrote guard.py, it was a single file containing everything: regex patterns, the clipboard monitoring loop, and the system notification logic. It worked, but I knew that as I added more features, it would become difficult to maintain.

Today, I took the time to refactor the monolithic script into a clean, modular package called shadow_guard. I broke it down into:

  • patterns.py: A dedicated file just for holding the targeted regex patterns (like API keys and passwords).
  • notifier.py: A separate module for handling system alerts.
  • monitor.py: The core ClipboardMonitor class that brings it all together using dependency injection.

Now, my main guard.py script is beautifully simple. It just imports the components and starts the monitor. This scalable structure means adding new rules or swapping out the notification logic in the future will be a breeze!

2. Wrangling macOS Desktop Notifications

The second challenge was the notifications themselves. Originally, I was using standard cross-platform Python libraries to trigger desktop alerts when a data leak was blocked. However, I noticed that these alerts were failing silently. MacOS was heavily restricting them from showing up in the Notification Center.

To guarantee that the alerts are always visible, I updated the notifier.py module to directly use Apple’s osascript. By invoking display alert, macOS now generates a prominent desktop dialog box right in the center of the screen whenever sensitive data is cleared from the clipboard. No more silent failures!

Overall, it was a solid session of taking a working prototype and turning it into a robust, scalable tool.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Incidence Response Evidence Collector
  • Shadow AI Data Leak Guard
  • My Master Thesis
  • Practically Understanding x86_64: Basic Concepts
  • Return Zero

Recent Comments

No comments to show.

Archives

  • March 2026
  • June 2024
  • September 2021

Categories

  • Back to Coding
  • Uncategorized
  • x86 Assembly
© 2026 Kainaat Singh | Powered by Superbs Personal Blog theme