Skip to content

fix: ignore trailing # comments in tokens/clients/groups files - #5

Merged
sujal-maheshwari2004 merged 1 commit into
mainfrom
fix/2-trailing-comments
Oct 18, 2026
Merged

sujal-maheshwari2004 merged 1 commit into
mainfrom
fix/2-trailing-comments

Conversation

@sujal-maheshwari2004

Copy link
Copy Markdown
Contributor

What was wrong

Only whole-line # comments were skipped. In a trailing comment every word became a field, and any non-keyword word was taken as the org (last one wins):

  • tokens file (authn.LoadTokens): <tok> acme rw # ci runner → token scoped to org runner.
  • clients.txt / groups.txt (configLines / parseGrant): prompt-admins rw # platform team (the README's own example) → tokens issued with org:"team".

Fix

  • A field starting with # (after the token / client id / group) ends the line.
  • A second org-looking field is now an error instead of a silent last-wins (LoadTokens returns an error; priompt-auth serve exits with <file>: client|group <name>: two orgs (...)). LoadTokens also rejects two expiries.

Tests

New: TestLoadTokensTrailingComment, TestLoadTokensRejectsExtraFields (authn), TestConfigTrailingComments, TestParseGrantRejectsExtraFields (cmd/priompt-auth).

Before the fix (on main):

--- FAIL: TestLoadTokensTrailingComment
    trailing comment changed scope: want org=acme rw, got {Org:runner ... Write:true}
    comment-only tail: want admin read-only, got {Org:orgs ...}
--- FAIL: TestLoadTokensRejectsExtraFields
    "tok acme rw ci runner": want an error, got map[tok:{Org:runner ...}]
--- FAIL: TestConfigTrailingComments
    trailing comments parsed as fields: [{group:prompt-admins grant:{org:team rw:true}} {group:acme-readers grant:{org:read-only rw:false}}]
    trailing comment changed the client grant: {secretHash:abcd grant:{org:runner rw:true}}

After: GOWORK=off go build ./... && go vet ./... && go test ./...

ok  	github.com/priompt/auth/authn
ok  	github.com/priompt/auth/cmd/priompt-auth

Live run: priompt-auth serve -clients-file clients.txt with ci-bot sha256:… acme rw # ci runner, then POST /token (client_credentials), decoded claims:

before: {"sub":"ci-bot","org":"runner","rw":true,...}
after:  {"sub":"ci-bot","org":"acme","rw":true,...}

And a line with no # (ci-bot sha256:abcd acme rw ci runner) now refuses to start:

bad.txt: client ci-bot: two orgs ("acme", "ci"); a trailing comment needs a leading #
exit=1

Fixes #2

🤖 Generated with Claude Code

Only whole-line comments were skipped, so `tok acme rw # ci runner`
scoped the token to org "runner" and `prompt-admins rw # platform team`
issued tokens with org "team". A field starting with # now ends the
line, and a second org (or second expiry) is rejected instead of the
last one silently winning.

Fixes #2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sujal-maheshwari2004
sujal-maheshwari2004 merged commit 69f96e7 into main Oct 18, 2026
1 check passed
@sujal-maheshwari2004
sujal-maheshwari2004 deleted the fix/2-trailing-comments branch October 18, 2026 17:49
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.

Trailing # comments in tokens/clients/groups files are parsed as fields (changes token scope)

1 participant