Skip to content

fix: validate team names to prevent teams/ path traversal (#140)#147

Merged
fujibee merged 1 commit into
mainfrom
fix/team-name-traversal
Jun 17, 2026
Merged

fix: validate team names to prevent teams/ path traversal (#140)#147
fujibee merged 1 commit into
mainfrom
fix/team-name-traversal

Conversation

@fujibee

@fujibee fujibee commented Jun 17, 2026

Copy link
Copy Markdown
Owner

What

Fixes #140 — team names were used directly as filesystem path segments in the team registry (teams/<name>/config.json), so a name containing /, \, or equal to . / .. could escape teams/ and create/read/move/delete config files and team directories outside the agmsg state tree.

Affected entry points: join.sh, leave.sh, team.sh, rename.sh, rename-team.sh.

How

  • New scripts/lib/validate.shagmsg_validate_team_name, called at every entry point that turns a team name into a path.
  • It is a deny-list of path-dangerous constructs (empty, ., .., /, \, leading -, control characters), not an ASCII allow-list. Team names are intentionally arbitrary UTF-8 (Japanese team names are already in use); multibyte UTF-8 bytes are all >= 0x80 and never match the control-character class, so legitimate names stay valid.
  • scripts/lib/ ships via the installer's recursive copy — no install change needed.

Verification

The issue's repro is now rejected (exit 1, no escaped files), and legitimate ASCII + UTF-8 names still join:

join.sh "../../outside-team" ...   → agmsg: invalid team name '../../outside-team': must not contain '/' or '\' (path traversal)  (exit 1)
team.sh "../../outside-team"        → rejected
rename-team.sh oldteam "../../x"    → rejected, source team untouched
join.sh "testチーム" ...            → joined (UTF-8 preserved)

Tests added to tests/test_team.bats: traversal / .+.. / leading-dash / empty rejection across all five scripts, no-escape assertions for join and rename-team, and a UTF-8 acceptance regression. bats tests/test_team.bats → 42/42.

Closes #140

Team names were used directly as filesystem path segments in the team registry
(teams/<name>/config.json). A name containing "/", "\", or equal to "." / ".."
could escape teams/ and create, read, move, or delete config files and team
directories outside the agmsg state tree — via join.sh, leave.sh, team.sh,
rename.sh, and rename-team.sh.

Add scripts/lib/validate.sh with agmsg_validate_team_name and call it at every
entry point that turns a team name into a path. It is a deny-list of
path-dangerous constructs (empty, ".", "..", "/", "\", leading "-", control
characters), NOT an ASCII allow-list — arbitrary UTF-8 team names (e.g.
Japanese names already in use) stay valid; multibyte UTF-8 bytes are all
>= 0x80 and never match the control-character class.

scripts/lib/ ships via the installer's recursive copy, so no install change is
needed. Tests: traversal / "."/".." / leading-dash / empty rejection across
join/leave/team/rename/rename-team, no-escape assertions, and a UTF-8 name
acceptance regression (test_team.bats).

Closes #140
@fujibee fujibee merged commit f6c0ed3 into main Jun 17, 2026
3 checks passed
@fujibee fujibee deleted the fix/team-name-traversal branch June 17, 2026 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Team names can escape teams/ via path traversal

1 participant