mirror of
https://github.com/Shiva108/ai-llm-red-team-handbook.git
synced 2026-05-14 12:48:16 +02:00
b3d3bac51f
- Extracted all code examples from handbook chapters - Organized into 15 attack categories - Created shared utilities (api_client, validators, logging, constants) - Added workflow orchestration scripts - Implemented install.sh for easy setup - Renamed all scripts to descriptive functional names - Added comprehensive README and documentation - Included pytest test suite and configuration
44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
41.3.1 The `Privacy_Vault`
|
|
|
|
Source: Chapter_41_Industry_Best_Practices
|
|
Category: compliance
|
|
"""
|
|
|
|
import argparse
|
|
import sys
|
|
|
|
class PIIFilter:
|
|
def __init__(self):
|
|
self.patterns = {
|
|
"EMAIL": re.compile(r'[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}'),
|
|
"SSN": re.compile(r'\b\d{3}-\d{2}-\d{4}\b'),
|
|
"CREDIT_CARD": re.compile(r'\b(?:\d{4}-){3}\d{4}\b|\b\d{16}\b'),
|
|
"API_KEY": re.compile(r'sk-[a-zA-Z0-9]{48}') # OpenAI Key format
|
|
}
|
|
|
|
def redact(self, text: str) -> str:
|
|
redacted_text = text
|
|
for label, pattern in self.patterns.items():
|
|
redacted_text = pattern.sub(f"<{label}_REDACTED>", redacted_text)
|
|
return redacted_text
|
|
|
|
# Usage
|
|
leaky_output = "Sure, the admin email is admin@corp.com and key is sk-1234..."
|
|
print(PIIFilter().redact(leaky_output))
|
|
|
|
# Output: "Sure, the admin email is <EMAIL_REDACTED> and key is <API_KEY_REDACTED>..."
|
|
|
|
|
|
def main():
|
|
"""Command-line interface."""
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--verbose", "-v", action="store_true", help="Verbose output")
|
|
args = parser.parse_args()
|
|
|
|
# TODO: Add main execution logic
|
|
pass
|
|
|
|
if __name__ == "__main__":
|
|
main() |