Skip to content

Instantly share code, notes, and snippets.

View ugochukwu95's full-sized avatar

Ugochukwu Oguejiofor ugochukwu95

View GitHub Profile
@ugochukwu95
ugochukwu95 / pii_detector.py
Created November 7, 2025 21:08
PII Detector tool
"""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',
@ugochukwu95
ugochukwu95 / test_output_sanitizer.py
Created November 7, 2025 19:33
Test cases that validates sanitization logic
"""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>"
@ugochukwu95
ugochukwu95 / output_sanitizer.py
Created November 7, 2025 19:28
Functions to handle insecure output handling form LLMs
"""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>',
@ugochukwu95
ugochukwu95 / index.php
Created January 17, 2020 18:03
Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.
<?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;
}
@ugochukwu95
ugochukwu95 / LocationChecker.js
Created January 15, 2020 16:42
A NodeJS/JavaScript program that reads our list of partners and outputs the company names and addresses of matching partners (with offices within 100km) sorted by company name (ascending).
/**
* 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
@ugochukwu95
ugochukwu95 / DeepClone.js
Created January 15, 2020 16:30
A function called DeepClone.js which takes an object and creates a copy of it. Tested using jest (see DeepClone.test.js)
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