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

Token prefix not being stripped #688

Open
utdrmac opened this issue Jan 19, 2025 · 4 comments
Open

Token prefix not being stripped #688

utdrmac opened this issue Jan 19, 2025 · 4 comments
Milestone

Comments

@utdrmac
Copy link

utdrmac commented Jan 19, 2025

In src/Application.php

        $service->loadAuthenticator('Authentication.Token', [
            'header' => 'X-Dipper-Auth',
            'tokenPrefix' => 'dipper_',
        ]);

Testing like this:

$ curl --verbose -H 'X-Dipper-Auth: dipper_sdfasdfadsf' https://domain.com/

dipper_ is the token prefix. It is not being stripped before being passed to my identifier. Looking at the code in vendor/cakephp/authentication/src/Authenticator/TokenAuthenticator.php, I found the function stripTokenPrefix() which does something odd:

     	return str_ireplace($prefix . ' ', '', $token);

Why is the replace concatenated with an empty space? That's not part of my prefix.

@markstory
Copy link
Member

Why is the replace concatenated with an empty space? That's not part of my prefix.

Because it is meant to handle value prefixes like

Authorization: Bearer foo_abc123

@markstory markstory added this to the 3.x milestone Jan 20, 2025
@utdrmac
Copy link
Author

utdrmac commented Jan 20, 2025

Ok, but what about prefixes like: (foo_ is the prefix)

Authorization: foo_abc123

If you have a space in your prefix, then include that in the config; don't force it upon everyone.

@markstory
Copy link
Member

If you have a space in your prefix, then include that in the config; don't force it upon everyone.

That's not how the class was designed/built though. Changing it now will break existing usage and can't be done. We could add another option to remove the prefix on the token value 🤷

@ADmad
Copy link
Member

ADmad commented Jan 20, 2025

Changing

return str_ireplace($prefix . ' ', '', $token);

to

return trim(str_ireplace($prefix, '', $token));

would retain the current behavior and also allow what @utdrmac expects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants