Repository navigation
fix(tracking): validate app ids in the local tracking client - #946
elijahbenizzy wants to merge 2 commits into
Conversation
The local tracking client turned app ids (and the parent app ids used for fork/spawn links) straight into directory names under the storage directory. Apply the rule the project name already used -- letters, digits, '_', '-', ':' and '.', non-empty, not '.' or '..', at most 255 characters -- to every identifier that becomes a path, and check that joined paths stay inside the storage directory. The rule lives in burr.tracking.common.identifiers so the server side can share it. Errors surface as ValueError from ApplicationBuilder.build().
sangkyoonnam
left a comment
There was a problem hiding this comment.
The allowlist plus join_within stops the app_id traversal I tried against the client (../../../escaped, absolute paths, both separators, NUL, overlong ids), and pytest tests/tracking passes on this branch. Two things before it lands.
The identifier pattern still accepts a trailing newline (inline below); the same file is in #948.
Ids outside the allowlist that main accepted, like user@example.com or chat session 1, can no longer be loaded, forked or checked with app_log_exists, which now raises instead of returning a bool. Is rejecting previously valid app ids intentional, and what should existing applications do on upgrade?
| ) | ||
| if value in (".", ".."): | ||
| raise ValueError(f"{what} must not be '.' or '..', got {value!r}") | ||
| if not IDENTIFIER_PATTERN.match(value) or (on_windows and ":" in value): |
There was a problem hiding this comment.
IDENTIFIER_PATTERN.match(value) with a pattern ending in $ accepts "x\n" and "..\n"; $ matches before a final newline. IDENTIFIER_PATTERN.fullmatch(value) (or \Z in the pattern) rejects them.
|
One remaining integration gap: the bundled demo routers pass URL Before merging, please:
Keeping validation in |
…turn 400 from demo routes
|
@skrawcz addressed all three: (1) |
LocalTrackingClientvalidated project names but notapp_id, even though both become directory names understorage_dir. This change applies one rule to both (letters, digits,_,-,.,:; non-empty; not./..; at most 255 chars) and adds a containment check on every path the client builds, so a malformed id fails atApplicationBuilder.build()rather than producing files in unexpected places.Side effects: project names may now contain
.; the project-name error message is shorter. The validation helper lives inburr/tracking/common/identifiers.pyso the tracking server can share it.Update after review. The identifier rule is now "any single path segment" rather than a character allowlist, so ids that worked before (
user@example.com,chat session 1, non-ASCII names) keep working. Rejected: empty,.,..,/,\, NUL and other control characters (so a trailing newline no longer passes), over 255 characters, and:on Windows. Validation failures raiseInvalidIdentifier(aValueError); the tracking server maps it to HTTP 400, so the bundled demo routes return 400 on a bad id instead of 500. Integration test covers an encoded..against the counter create route and asserts nothing is written.