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

Đang mở
#893 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@TimeToBuildBob đang làm issue này rồi.

Từ ngày 24/11/2026.

  • #894 của @TimeToBuildBob — đang mở
  • #895 của @TimeToBuildBob — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
22/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
backend, security

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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).

Ngôn ngữ chính
Rust
Star
322
Fork
107
Merge trung bình
2 ngày 16 giờ
Pull request đã merge (30 ngày)
25

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ActivityWatch/aw-server-rust

Tất cả issue của ActivityWatch/aw-server-rust

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.