Skip to content

fix: percent-encode reserved chars in actor/group gate URLs#54

Open
redac wants to merge 4 commits into
tompave:masterfrom
redac:fix/url-encode-slash-in-flag-names
Open

fix: percent-encode reserved chars in actor/group gate URLs#54
redac wants to merge 4 commits into
tompave:masterfrom
redac:fix/url-encode-slash-in-flag-names

Conversation

@redac
Copy link
Copy Markdown

@redac redac commented Apr 10, 2026

Fixes #53.

Why

Actor IDs and group names are free-text input in the admin UI (Utils.validate/1 only rejects blank and ?), so operators can legitimately create gates with values like w:foo/bar or tenants/eu. Once created, every toggle and clear action on these gates returns 404 because the literal / in the rendered URL gets split into extra path segments by the HTTP adapter, and Plug.Router's single-segment :actor_id / :group_name params can't match.

What changed

  • Tightened Templates.url_safe/1 to percent-encode all non-unreserved chars (including /)
  • Added encode_segment/1 in Router to wrap the 4 redirect sites that interpolate gate values into Location headers

Notes

  • Flag names are unaffected — already validated to ^\w+$ by Utils.validate_flag_name/2, so no encoding needed there
  • Percent-encoding is sufficient because Plug's adapters decode per-segment after splitting on /, so %2F survives as a single segment

redac added 2 commits April 10, 2026 10:14
Templates.url_safe/1 used URI.encode/1 whose default predicate keeps
reserved characters like / verbatim. Actor IDs and group names containing
/ (e.g. w:foo/bar) rendered form actions with a literal slash, which
Plug.Router split into multiple segments and couldn't match — returning
404 on every toggle/clear action.

Tighten url_safe/1 to URI.encode(&URI.char_unreserved?/1) and wrap the
4 redirect_to sites that interpolate actor_id/group_name with a new
encode_segment/1 helper. Flag names are unaffected (already validated
to ^\w+$ by Utils.validate_flag_name/2).

Fixes tompave#53
@redac redac marked this pull request as ready for review April 10, 2026 12:20
@redac
Copy link
Copy Markdown
Author

redac commented Apr 10, 2026

scr-2026-04-10-14.19.30.mp4

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.

404 on actor/group gates whose names contain URL-reserved characters (e.g. /)

1 participant