Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve provider name handling #213

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cyb3r4nt
Copy link
Contributor

The problem occurs when the provider name contains underscore characters _.
If provider name is like provider_prod and full claims.User.ID in the JWT token looks like provider_prod_user1,
then Authenticator.isProviderAllowed() check fails and provider with such name cannot be used.
This was initially discovered in #201 (comment).

It might be better to add an explicit provider name into the JWT token claims,
and avoid parsing already serialized string back to tokens.

Provider name passed into Service.AddProvider() also becomes a part of https://host:port/auth/provider_prod/login URL, and therefore it requires special handling.
One solution is to url-encode it, but then it will be still possible to use names containing spaces or special characters (by accident or with purpose).
Another solution is to forbid all provider names which require url-encoding.
It might be better to forbid empty names as well.
_ underscore has been mentioned in the README examples for some time now, i am not sure about it.
But those names may be even more strict and contain only ASCII alphanumeric symbols.
What do you think?

It is not possible to return errors from Service.AddProvider(), therefore invalid providers are just ignored and ERROR level message is logged.

@cyb3r4nt cyb3r4nt requested a review from umputun as a code owner August 29, 2024 21:49
@cyb3r4nt
Copy link
Contributor Author

golangci-lint fixes are in #214

@coveralls
Copy link

coveralls commented Sep 2, 2024

Pull Request Test Coverage Report for Build 12588015969

Details

  • 64 of 64 (100.0%) changed or added relevant lines in 8 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.3%) to 83.582%

Totals Coverage Status
Change from base Build 12447109182: 0.3%
Covered Lines: 2688
Relevant Lines: 3216

💛 - Coveralls

Copy link
Collaborator

@paskal paskal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I guess it shouldn't break anything.

I would suggest creating separate small PR with all changes not related to name handing improvement, e.g. README.md, provider/apple_pubkeys.go, provider/apple_test.go, provider/telegram_test.go.

Add provider name into JWT token claims
to allow provider names with multiple underscore "_" symbols.
Forbid provider names containing URL reserved symbols.
@paskal paskal force-pushed the fix-providers-names branch from 5a80324 to 3157345 Compare January 2, 2025 19:59
@paskal
Copy link
Collaborator

paskal commented Jan 2, 2025

Rebased on top of master, without altering anything. @umputun could you please take a look?


path, err := url.PathUnescape(name)
if err != nil || path != name {
formatForbidden(name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small thing: in debug mode, this function's redirect for logging will lose the source line information. I'd suggest creating an error message instead and logging it directly.

Copy link
Member

@umputun umputun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx, lgtm. just a minor suggestion

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.

4 participants