Python path: None title crashes the loop; bad privacy rule action crashes; invalid privacy rules fail open

Open
#180 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
javascript, python
Domain
desktop

Research direction

Start in main.py at heartbeat_loop: the transform_window call sits outside the try, and both it and research_filter.transform assume a string title. Reproduce with the three snippets, then read printAppStatus.jxa (only undefined is mapped, not null), compile_privacy_rules (the unhashable action), and the swift branch that refuses to start when rules are configured — that branch is the model for failing closed. Done means non-string titles are coerced, invalid rules are skipped without crashing, and a maintainer has answered whether main() should exit when len(compiled) < len(raw).

Written by the indexing model from the issue text.

Description

Three crash/fail-open cases in the Python path. Each is reproduced on master 76b3f6f with the snippet shown.

1. A None title crashes the loop. transform_window runs outside the try in heartbeat_loop (main.py), so an exception there ends the watcher.

transform_window({"app": "Finder", "title": None}, exclude_titles=[re.compile("x")])  # TypeError
research_filter.transform({"app": "Google Chrome", "title": None}, {"a": "b"})        # AttributeError

printAppStatus.jxa only replaces title === undefined. An AXTitle that is null would pass through as "title": null. I haven't confirmed that on a Mac, so treat the input source as plausible; the crash itself is certain. A likely fix is to also map null in the JXA, and/or coerce a non-string title to "" before the transforms.

2. A non-string privacy action crashes at startup instead of being skipped. The docstring promises invalid rules are "skipped with an error log":

compile_privacy_rules([{"pattern": "x", "action": ["drop"]}])  # TypeError: unhashable type: 'list'

3. An invalid privacy rule fails open. A rule with a bad regex (e.g. a stray () or an unknown action is logged and skipped, and the watcher then sends unfiltered titles on Linux, Windows and jxa/applescript. The swift branch refuses to start when any rule is configured "so titles are not leaked". An invalid exclude_titles regex also exits (try_compile_regex). Should main() exit when len(compiled) < len(raw)? That is a behaviour change, so I'm asking rather than opening a PR.

Dominant language
Python
Stars
133
Forks
92
Avg merge
5d 3h
Merged PRs (30d)
4

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ActivityWatch/aw-watcher-window

All issues in ActivityWatch/aw-watcher-window

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.