[GH-ISSUE #3326] [Other] strata_bench redactor: the user-name substitution runs before the folder substitutions, so reports keep /home/<user>/Strata instead of <strata> #1349

Closed
opened 2026-11-04 01:50:33 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @Dmitry-B on GitHub (Oct 20, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/3326

Problem: tools/strata_bench.py sorts its redactions by the length of the pattern, so a short user name
wins over the longer path that contains it. On a machine whose user name is short, the repository folder
is never replaced with <strata>: instead of <strata>/strata-x.json the report gets
/home/<user>/Strata/strata-x.json. The tool's own test for this fails on such machines.

Environment: Strata e88ee39d (0.2.0-beta), Ubuntu 26.04.1, Python 3.14.4. User name dgbox (5 chars),
home /home/dgbox, repository /home/dgbox/Strata, host name dgbox-ubuntu-server. No GPU involved.

Reproduce:

python -m unittest tools.test_strata_bench.RedactionTests.test_paths_names_ips_and_keys

Expected:

ok

Actual:

AssertionError: '<strata>' not found in 'loading /home/<user>/Strata/strata-x.json'

The same call directly:

red = strata_bench.redactor()
red("loading /home/dgbox/Strata/strata-x.json")
# 'loading /home/<user>/Strata/strata-x.json'      (expected: 'loading <strata>/strata-x.json')

Why: in redactor() (tools/strata_bench.py, ~line 90) the substitutions are collected and then
subs.sort(key=lambda p: -len(p[0].pattern)) - ordered by the compiled pattern length, and the patterns
of user and host names are wrapped in (?<!\[\w-]) … (?![\w-]) (+20 characters). The name pattern is
therefore always longer than the folder pattern that contains that name (len(name)+20 against
len(name)+13 for /home/<name>/Strata), so <user> is substituted first and the <strata> and
<home> patterns have nothing left to match. The generic path_user regex then rewrites the path to
/home/<user>/….

Isolation of the condition: the same test passes when the repository is not under the home folder - in a
worktree at /tmp/gold-check (git worktree add /tmp/gold-check e88ee39d, same commit, same venv):

$ python -m unittest tools.test_strata_bench.RedactionTests.test_paths_names_ips_and_keys
.
Ran 1 test in 0.001s
OK

So the order is what matters, not the length of the user name: for any normal install (the repository
under the user's home) the folder substitutions are dead.

Reproduction status: reproduced locally in the working tree and in a clean worktree of e88ee39d; the
worktree at /tmp/gold-check is the control that isolates the condition. Consequence for published
reports: reports written by the tool on such an install keep /home/<user>/Strata/… where the format
expects <strata>/….

Originally created by @Dmitry-B on GitHub (Oct 20, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/3326 Problem: `tools/strata_bench.py` sorts its redactions by the length of the pattern, so a short user name wins over the longer path that contains it. On a machine whose user name is short, the repository folder is never replaced with `<strata>`: instead of `<strata>/strata-x.json` the report gets `/home/<user>/Strata/strata-x.json`. The tool's own test for this fails on such machines. Environment: Strata `e88ee39d` (0.2.0-beta), Ubuntu 26.04.1, Python 3.14.4. User name `dgbox` (5 chars), home `/home/dgbox`, repository `/home/dgbox/Strata`, host name `dgbox-ubuntu-server`. No GPU involved. Reproduce: ```bash python -m unittest tools.test_strata_bench.RedactionTests.test_paths_names_ips_and_keys ``` Expected: ``` ok ``` Actual: ``` AssertionError: '<strata>' not found in 'loading /home/<user>/Strata/strata-x.json' ``` The same call directly: ```python red = strata_bench.redactor() red("loading /home/dgbox/Strata/strata-x.json") # 'loading /home/<user>/Strata/strata-x.json' (expected: 'loading <strata>/strata-x.json') ``` Why: in `redactor()` (tools/strata_bench.py, ~line 90) the substitutions are collected and then `subs.sort(key=lambda p: -len(p[0].pattern))` - ordered by the compiled pattern length, and the patterns of user and host names are wrapped in `(?<!\[\w-]) … (?![\w-])` (+20 characters). The name pattern is therefore always longer than the folder pattern that contains that name (`len(name)+20` against `len(name)+13` for `/home/<name>/Strata`), so `<user>` is substituted first and the `<strata>` and `<home>` patterns have nothing left to match. The generic `path_user` regex then rewrites the path to `/home/<user>/…`. Isolation of the condition: the same test passes when the repository is not under the home folder - in a worktree at `/tmp/gold-check` (`git worktree add /tmp/gold-check e88ee39d`, same commit, same venv): ``` $ python -m unittest tools.test_strata_bench.RedactionTests.test_paths_names_ips_and_keys . Ran 1 test in 0.001s OK ``` So the order is what matters, not the length of the user name: for any normal install (the repository under the user's home) the folder substitutions are dead. Reproduction status: reproduced locally in the working tree and in a clean worktree of `e88ee39d`; the worktree at `/tmp/gold-check` is the control that isolates the condition. Consequence for published reports: reports written by the tool on such an install keep `/home/<user>/Strata/…` where the format expects `<strata>/…`.
Author
Owner

@Niko1221 commented on GitHub (Oct 26, 2026):

Thanks, this is fixed by #3619, ported to 0.2.7. Closing with it.

<!-- gh-comment-id:6423229536 --> @Niko1221 commented on GitHub (Oct 26, 2026): Thanks, this is fixed by #3619, ported to 0.2.7. Closing with it.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#1349
No description provided.