8000 Add support for custom auth token expire date in UI and API by michalkleiner · Pull Request #23340 · matomo-org/matomo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add support for custom auth token expire date in UI and API #23340

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

Draft
wants to merge 1 commit into
base: dev-19113
Choose a base branch
from

Conversation

michalkleiner
Copy link
Contributor

Description:

Please include a description of this change and which issue it fixes. If no issue exists yet please include context and what problem it solves.

Review

Copy link
snyk-io bot commented Jun 1, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

Copy link
Member
@sgiehl sgiehl left a comment

Choose a reason for hiding this comment

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

Generally seems to work as expected. Left some comments on possible bugs and code improvements. Some additional tests might also be beneficial.

Comment on lines +391 to +392
if (!empty($_POST['token_expire_date'])) {
$tokenExpireDate = \Piwik\Request::fromRequest()->getStringParameter('token_expire_date');
Copy link
Member

Choose a reason for hiding this comment

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

What is that check supposed to do? Do you want to ensure it's sent by POST? Currently if the value would be sent by GET and POST, it would actually use the GET value. The already existing code might already haven been broken 🤔
You could simply use \Piwik\Request::fromPost() for that.
And it might be beneficial to only call \Piwik\Request::fromPost() once and assign it to a variable that can be reused.

Comment on lines +348 to +349
bool $hasTokenExpiryDate = false,
string $tokenExpiryDate = null
Copy link
Member

Choose a reason for hiding this comment

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

What are those new parameters for? They seem to be unused.

name="has_expiration"
:title="translate('UsersManager_TokenExpireDateCheckboxLabel')"
:required="false"
:inline-help="translate('UsersManager_TokenExpireDateCheckboxHelp')"
Copy link
Member

Choose a reason for hiding this comment

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

That one has a placehoder, which currently has no provided value.

<input
type="text"
name="token_expire_date"
:value="tokenExpireDate"
Copy link
Member

Choose a reason for hiding this comment

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

wondering if it could make sense to have a required attribute here, that is set based on the value of tokenHasExpiration


$noDescription = null;
$description = '';
if (!empty($_POST['description'])) {
Copy link
Member

Choose a reason for hiding this comment

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

As mentioned above: we should never directly access $_POST. Better to use Request::fromPost.

Comment on lines +410 to +412
} elseif (isset($_POST['description'])) {
$noDescription = true;
}
Copy link
Member

Choose a reason for hiding this comment

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

Can't that be simplified in some way? If I see that correctly the variable is used to be passed through the template to vue.js. The vue component assumes the value to be passed as boolean, so passing the default null value, that is set, if the POST parameter is missing, might actually result in unexpected behavior.

try {
$invalidExpireDate = true;
if (preg_match('/^(\d{4})-(\d{2})-(\d{2})$/', $tokenExpireDate)) {
Date::factory($tokenExpireDate);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe some check if the date is actually in the future might be helpful. Otherwise someone might by accident create a token that is already expired and would never show up in the list of tokens afterwards.

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

Successfully merging this pull request may close these issues.

2 participants
0