This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """PII detection and redaction to prevent sensitive information disclosure.""" | |
| import re | |
| from typing import Dict, List | |
| class PIIDetector: | |
| """Detects and redacts sensitive information in prompts and outputs.""" | |
| PATTERNS = { | |
| "email": r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b', | |
| "phone": r'\b(?:\+?1[-.]?)?\(?([0-9]{3})\)?[-.]?([0-9]{3})[-.]?([0-9]{4})\b', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """Test cases for output sanitization - validates protection against injection attacks.""" | |
| import pytest | |
| from app.security.output_sanitizer import OutputSanitizer | |
| class TestOutputSanitizer: | |
| """Test suite for insecure output handling prevention.""" | |
| def test_xss_detection(self): | |
| """Test XSS attack detection.""" | |
| malicious = "<script>alert('XSS')</script>" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """Output sanitization for LLM responses to prevent injection attacks.""" | |
| import re | |
| import html | |
| from typing import Dict | |
| class OutputSanitizer: | |
| """Sanitizes LLM outputs before downstream consumption.""" | |
| DANGEROUS_PATTERNS = [ | |
| r'<script[^>]*>.*?</script>', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| for ($i=1; $i <= 100; $i++) { | |
| if ((($i % 3) == 0) && (($i % 5) == 0)) { | |
| echo "FizzBuzz\n"; | |
| continue; | |
| } | |
| elseif (($i % 3) == 0) { | |
| echo "Fizz\n"; | |
| continue; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * is One Point within Another | |
| * @param point {Object} {latitude: Number, longitude: Number} | |
| * @param interest {Object} {latitude: Number, longitude: Number} | |
| * @param kms {Number} | |
| * @returns {boolean} | |
| */ | |
| const LocationChecker = (point, interest, kms) => { | |
| let R = 6371; // Earth radius | |
| let deg2rad = (n) => { return Math.tan(n * (Math.PI/180)) }; // function that converts degrees to radians |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const DeepClone = (obj) => { | |
| let copy; | |
| // Handle the 3 simple types, and null or undefined | |
| if (null === obj || "object" !== typeof obj) return obj; | |
| // Handle Date | |
| if (obj instanceof Date) { | |
| copy = new Date(); | |
| // A way to make one Date the same as another is by calling the setTime method |