Add Tier-2 policy-driven DetectionEngine with multi-turn, agent-chain, response scanning and feedback endpoint#65
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: da8fdfd12e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return self._score_patterns(response_text, patterns) | ||
|
|
||
| def _session_key(self, organization_id: Optional[str], session_id: Optional[str]) -> str: | ||
| return f"{organization_id or 'default'}:{session_id or 'anon'}" |
There was a problem hiding this comment.
Separate anonymous requests from shared session accumulator
session_id is optional for analysis requests, but _session_key maps every missing session_id to default:anon, so unrelated traffic shares one risk history. After a handful of high-risk prompts, benign prompts from other users can be marked suspicious/malicious purely because session risk is reused, which creates cross-user contamination whenever clients omit session_id.
Useful? React with 👍 / 👎.
| logger.info("Using sklearn backend") | ||
| return | ||
|
|
||
| model_id = os.getenv("TRANSFORMER_MODEL_ID", "distilbert-base-uncased-finetuned-sst-2-english") |
There was a problem hiding this comment.
Stop defaulting transformer scoring to sentiment model
The default TRANSFORMER_MODEL_ID is distilbert-base-uncased-finetuned-sst-2-english (sentiment), while the engine uses this backend by default; combined with the maliciousness mapping in _model_score, benign but negatively worded prompts can be scored as attacks. Because final risk_score takes the max signal, this default can systematically skew verdicts toward false positives unless every deployment overrides the model ID.
Useful? React with 👍 / 👎.
🤖 TENET Agent Review📋 SummaryThis pull request introduces a significant upgrade to the TENET AI project by implementing a Tier-2 🔐 Security Findings
🧹 Code Quality
✅ What's Done Well
📝 Overall Verdict[REQUEST CHANGES] - Address the identified security and code quality concerns, particularly regarding default API keys, SIEM data handling, and session state management. |
🤖 TENET Agent Review📋 SummaryThis pull request introduces a significant upgrade to the TENET AI analyzer service by implementing a Tier-2 🔐 Security Findings
🧹 Code Quality
✅ What's Done Well
📝 Overall Verdict[REQUEST CHANGES] - Address the |
Motivation
Description
services/analyzer/detection_engine.pyimplementingDetectionEnginethat supports policy-driven pattern scoring, session-level risk accumulation, agentic chain/tool-call monitoring, response/data-leak scanning, optional transformer backend scoring (bert/debertaviaTRANSFORMER_MODEL_ID) and a sklearn fallback interface.services/analyzer/policy/default_policy.yamlwith thresholds, prompt rules, agentic-chain patterns, response leak patterns, and org-specific overrides.DetectionEngineintoservices/analyzer/app.py, extending the/v1/analyzerequest schema withsession_id,organization_id,response_text, andagent_trace, and returning normalizedAnalysisResponse./v1/feedbackendpoint andDetectionEngine.append_feedbackwhich persists analyst FP/FN corrections to a JSONL feedback sink for retraining.tests/unit/test_detection_engine.pycovering response scanning, multi-turn session tracking, and feedback persistence.requirements.txtto includetransformersandPyYAMLfor transformer backends and YAML policy parsing.Testing
pytest tests/unit/test_analyzer.py tests/unit/test_detection_engine.py -q, and all tests passed with warnings:31 passed, 4 warnings.tests/unit/test_detection_engine.pyexercised response scanning, session escalation, and feedback write behavior and succeeded.Codex Task