query: categorize rules can pin unbounded memory in the regex cache and run past query_timeout

未关闭
#893 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@TimeToBuildBob 已经在做这个了。

开始于 2026年11月24日。

  • #894 来自 @TimeToBuildBob —— 未关闭
  • #895 来自 @TimeToBuildBob —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
22/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
rust
领域
backend, security

调研方向

Start with aw-transform/src/classify.rs (the global REGEX_CACHE and the backtrack-error handling near line 124) and aw-query/src/interpret.rs (the deadline check near line 31). Reproduce both problems with cargo test -p aw-server --test bughunt_dos from the linked branch. Done means the repro tests pass, with a bounded regex cache and a deadline that stops a long categorize call. Choosing between the proposed fixes needs maintainer input.

由索引模型根据 Issue 内容生成。

描述

Two resource-exhaustion problems in categorize/tag rules sent through /api/0/query. Both were found in a security-lens bug hunt and reproduced with failing tests on master ea6f09c, on branch TimeToBuildBob:bughunt-2026-11-24-security-dos-repros (aw-server/tests/bughunt_dos.rs, run with cargo test -p aw-server --test bughunt_dos).

Reach: /api/0/query is closed to wildcard moz-extension:// origins by ExtensionCorsScope. That leaves local clients and the user's own webui. So this is mostly about robustness against an unlucky or hostile category rule, not a remote attack.

1. The regex cache keeps compiled regexes of any size

aw-transform/src/classify.rs:11-13,107-111: REGEX_CACHE is a process-global LRU of up to 512 compiled fancy_regex::Regex, with no limit on their size. A counted repetition such as a{200000}z is about 20 bytes of query text and compiles to roughly 10 MB, just under the regex crate's 10 MiB compile limit. The compiled regex stays resident until it is evicted.

1175-byte query body, status 200 OK, retained RSS growth 158 MB

That is 16 rules. Filling all 512 slots leaves several GB resident from a single query of about 37 KB.

Possible fix: build rules with fancy_regex::RegexBuilder and a smaller delegate_size_limit / delegate_dfa_size_limit, or skip caching patterns whose compiled size is large.

2. One backtracking rule runs far past query_timeout_secs

A rule that needs fancy-regex's backtracking VM, such as ^(a|aa|(?=a)a)*$, uses up the 1M backtrack limit on each non-matching value. classify.rs:124 then treats the error as "no match". The deadline is only checked between statements (aw-query/src/interpret.rs:31), so one categorize call over many distinct titles runs until it finishes:

query took 14.1s with a 1s budget, status 503 Service Unavailable

That is 60 events, 1 rule, a debug build, and a 1 s budget. The query handler is synchronous, so each such request holds a Rocket worker for the whole time.

Possible fix: pass the deadline into categorize / tag / filter_keyvals_regex and check it per event, or lower backtrack_limit through RegexBuilder.

Neither duplicates #882 (parser and lexer issues) or #881 (non-finite numbers).

主要语言
Rust
星标
322
派生
107
平均合并
2 天 16 小时
30 天内合并 PR
25

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ActivityWatch/aw-server-rust 的其他 Issue

查看 ActivityWatch/aw-server-rust 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。