Skip to content

Commit a0b03eb

Browse files
Refine Operational Security role with redaction and better validation
- Implemented credential redaction in `CloudSecurityAI` to avoid exposing full secrets. - Added robust error handling and type validation to Flask security endpoints. - Refactored `OfficialAssistance.jsx` to move tool configurations into a declarative structure. - Replaced realistic-looking simulated credentials with obviously fake ones. - Updated unit tests to verify redaction logic. Co-authored-by: GYFX35 <134739293+GYFX35@users.noreply.github.com>
1 parent 0dbafe6 commit a0b03eb

4 files changed

Lines changed: 59 additions & 32 deletions

File tree

social_media_analyzer/operational_security.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@
55
class CloudSecurityAI:
66
"""AI for scanning cloud credentials and sensitive information."""
77

8+
def _redact(self, value):
9+
"""Redacts a sensitive string, keeping only the first 4 and last 4 characters."""
10+
if len(value) <= 10:
11+
return "****"
12+
return f"{value[:4]}...{value[-4:]}"
13+
814
def scan_content(self, text_content):
915
findings = {}
1016
for pattern_name, regex in SENSITIVE_DATA_PATTERNS.items():
1117
matches = regex.findall(text_content)
1218
if matches:
13-
findings[pattern_name] = matches
19+
# Redact each match to avoid full exposure
20+
findings[pattern_name] = [self._redact(m) for m in matches]
1421
return findings
1522

1623
class IoTSecurityAI:

social_media_analyzer/test_operational_security.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ def test_cloud_security_scan(self):
77
content = "My AWS Key is AKIA1234567890ABCDEF"
88
findings = ai.scan_content(content)
99
self.assertIn("AWS Access Key ID", findings)
10-
self.assertEqual(findings["AWS Access Key ID"], ["AKIA1234567890ABCDEF"])
10+
# Verify redaction: AKIA1234567890ABCDEF -> AKIA...CDEF
11+
self.assertEqual(findings["AWS Access Key ID"], ["AKIA...CDEF"])
1112

1213
def test_iot_security_analyze(self):
1314
ai = IoTSecurityAI()

src/OfficialAssistance.jsx

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,30 @@ const assistanceRoles = {
3636
icon: '🔐',
3737
description: 'Cloud, IoT, and AI-driven security operations for modern infrastructure.',
3838
tools: [
39-
{ id: 'cloud_guard', name: 'Cloud Guard', icon: '☁️', desc: 'AI scanner for leaked credentials and sensitive cloud data.' },
40-
{ id: 'iot_shield', name: 'IoT Shield', icon: '🌐', desc: 'Real-time anomaly detection for industrial IoT networks.' },
41-
{ id: 'opsec_analyzer', name: 'OpSec Analyzer', icon: '🕵️', desc: 'AI-driven analysis of operational logs for procedural threats.' }
39+
{
40+
id: 'cloud_guard',
41+
name: 'Cloud Guard',
42+
icon: '☁️',
43+
desc: 'AI scanner for leaked credentials and sensitive cloud data.',
44+
endpoint: '/analyze/cloud',
45+
getPayload: () => ({ content: "Cloud scan simulation with fake AWS key: AKIA0000000000000000 and fake Google API Key: AIza00000000000000000000000000000000000" })
46+
},
47+
{
48+
id: 'iot_shield',
49+
name: 'IoT Shield',
50+
icon: '🌐',
51+
desc: 'Real-time anomaly detection for industrial IoT networks.',
52+
endpoint: '/analyze/iot',
53+
getPayload: () => ({ device_data: { voltage: 2.6, temperature: 82, rssi: -95 } })
54+
},
55+
{
56+
id: 'opsec_analyzer',
57+
name: 'OpSec Analyzer',
58+
icon: '🕵️',
59+
desc: 'AI-driven analysis of operational logs for procedural threats.',
60+
endpoint: '/analyze/opsec',
61+
getPayload: () => ({ logs: ["unauthorized access attempt", "nmap scan detected", "large outbound transfer", "sudo usage"] })
62+
}
4263
]
4364
}
4465
};
@@ -48,38 +69,24 @@ export default function OfficialAssistance() {
4869
const [analysisResult, setAnalysisResult] = useState(null);
4970
const [loading, setLoading] = useState(false);
5071

51-
const handleLaunch = async (toolId, toolName) => {
52-
if (!['cloud_guard', 'iot_shield', 'opsec_analyzer'].includes(toolId)) {
53-
alert(`Launching ${toolName}... (Simulation mode)`);
72+
const handleLaunch = async (tool) => {
73+
if (!tool.endpoint) {
74+
alert(`Launching ${tool.name}... (Simulation mode)`);
5475
return;
5576
}
5677

5778
setLoading(true);
5879
setAnalysisResult(null);
5980

6081
try {
61-
let endpoint = '';
62-
let body = {};
63-
64-
if (toolId === 'cloud_guard') {
65-
endpoint = '/analyze/cloud';
66-
body = { content: "Sample content with simulated AWS key: AKIA1234567890ABCDEF and Google API Key: AIzaSyA12345678901234567890123456789012" };
67-
} else if (toolId === 'iot_shield') {
68-
endpoint = '/analyze/iot';
69-
body = { device_data: { voltage: 2.6, temperature: 82, rssi: -95 } };
70-
} else if (toolId === 'opsec_analyzer') {
71-
endpoint = '/analyze/opsec';
72-
body = { logs: ["unauthorized access attempt", "nmap scan detected", "large outbound transfer", "sudo usage"] };
73-
}
74-
75-
const response = await fetch(endpoint, {
82+
const response = await fetch(tool.endpoint, {
7683
method: 'POST',
7784
headers: { 'Content-Type': 'application/json' },
78-
body: JSON.stringify(body)
85+
body: JSON.stringify(tool.getPayload())
7986
});
8087

8188
const data = await response.json();
82-
setAnalysisResult({ title: toolName, data });
89+
setAnalysisResult({ title: tool.name, data });
8390
} catch (error) {
8491
console.error("Error launching tool:", error);
8592
alert("Failed to connect to security backend. Make sure the Flask server is running.");
@@ -117,7 +124,7 @@ export default function OfficialAssistance() {
117124
</div>
118125
<button
119126
className="action-btn"
120-
onClick={() => handleLaunch(tool.id, tool.name)}
127+
onClick={() => handleLaunch(tool)}
121128
disabled={loading}
122129
>
123130
{loading ? 'Processing...' : 'Launch'}

text_message_analyzer/app.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ def analyze_cloud():
6464
return jsonify({"error": "Missing 'content' in request body"}), 400
6565

6666
content = data['content']
67-
result = operational_security.analyze_cloud_security(content)
68-
return jsonify(result)
67+
try:
68+
result = operational_security.analyze_cloud_security(content)
69+
return jsonify(result)
70+
except Exception as e:
71+
return jsonify({"error": f"Failed to analyze cloud security: {str(e)}"}), 500
6972

7073
@app.route('/analyze/iot', methods=['POST'])
7174
def analyze_iot():
@@ -74,8 +77,11 @@ def analyze_iot():
7477
return jsonify({"error": "Missing 'device_data' in request body"}), 400
7578

7679
device_data = data['device_data']
77-
result = operational_security.analyze_iot_security(device_data)
78-
return jsonify(result)
80+
try:
81+
result = operational_security.analyze_iot_security(device_data)
82+
return jsonify(result)
83+
except Exception as e:
84+
return jsonify({"error": f"Failed to analyze IoT security: {str(e)}"}), 500
7985

8086
@app.route('/analyze/opsec', methods=['POST'])
8187
def analyze_opsec():
@@ -84,8 +90,14 @@ def analyze_opsec():
8490
return jsonify({"error": "Missing 'logs' in request body"}), 400
8591

8692
logs = data['logs']
87-
result = operational_security.analyze_opsec_security(logs)
88-
return jsonify(result)
93+
if not isinstance(logs, list) or not all(isinstance(log, str) for log in logs):
94+
return jsonify({"error": "'logs' must be a list of strings"}), 400
95+
96+
try:
97+
result = operational_security.analyze_opsec_security(logs)
98+
return jsonify(result)
99+
except Exception as e:
100+
return jsonify({"error": f"Failed to analyze operational security: {str(e)}"}), 500
89101

90102

91103
if __name__ == '__main__':

0 commit comments

Comments
 (0)