[插件 mimosa] 请求误报豁免机制(suppression)与 SQLAlchemy 参数化/哈希净化器建模
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 22
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
环境
- 插件:mimosa@zcode-plugins-official 1.0.3
- 场景:git commit/push 门禁钩子 + 编辑写入闸门
背景
一段符合最佳实践的会话 cookie 校验代码,每次 commit/push 都被报 medium 疑似跨文件污点,且实测无法通过任何代码改写消除。这会让 medium 告警长期沦为噪音,稀释真信号。
最小复现(Python + SQLAlchemy,教科书式安全写法)
raw = request.cookies.get("session") # taint source
def hash_session_token(raw: str) -> str: # 哈希净化
return hashlib.sha256(raw.encode()).hexdigest()
def find_active_editor(conn, raw_token):
digest = hash_session_token(raw_token)
row = conn.execute(
text("SELECT ... WHERE s.token_hash = :h AND ..."), # 绑定参数
{"h": digest},
).first()
无任何字符串拼接、无注入面,但污点规则把 cookies.get() → conn.execute 串成跨文件路径,
不把中间的哈希函数建模为净化器。
三路实测(均无法消除)
| 改法 | 结果 |
|---|---|
| 哈希放在 service 函数内部(如上) | medium 照报:规则穿透 hash_session_token |
边界加格式校验守卫(re.fullmatch 后才继续) |
medium 照报:守卫不被识别为净化器 |
| 哈希上移到边界、只传 digest 进 service | 写入闸门报 high「SQL 注入」拦截:text("… :h …") + {"h": digest} 的 SQLAlchemy 绑定参数被当成拼接 |
即:commit 侧污点规则与写入侧注入规则对同一段安全代码的要求互相矛盾,用户无论怎么写都会被至少一条命中。
另实测 MIMOSA_HOOK_STATUS=quiet|important 对 finding 输出无影响(只作用于基础设施状态消息),无法用于降噪。
诉求(按优先级)
- 误报豁免机制:内联注释(如
# mimosa:ignore <rule> <理由>)或项目基线文件(记录 finding id + 处置结论,钩子重扫时对表跳过已处置项)。基线文件方案对门禁场景更合适——团队可 review、可审计。 - SQLAlchemy 参数化建模:
conn.execute(text("… :name …"), {"name": value})应识别为参数化查询,不应触发注入/污点 sink。 - 净化器可配置:允许用户把指定函数(如项目内的 token 哈希函数)声明为 taint 净化器。
期望效果
安全写法不再报;已人工复核的误报有官方途径沉淀;钩子输出只剩真信号。
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No repository files, tests, or implementation entry points are named. Start by reproducing the Python and SQLAlchemy example from the issue, then locate the mimosa taint, SQL-injection, and hook configuration code; done means reviewed findings can be suppressed or baselined, SQLAlchemy bound parameters are modeled safely, and configured hash functions act as sanitizers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, sqlalchemy
- Domain
- security, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100