Skip to content

Exception when setting API token expiration date far in the future #414

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

Open
bookoly opened this issue Jan 20, 2025 · 0 comments
Open

Exception when setting API token expiration date far in the future #414

bookoly opened this issue Jan 20, 2025 · 0 comments

Comments

@bookoly
Copy link

bookoly commented Jan 20, 2025

Hi everyone,

I encountered an issue when trying to set a very high expiration date for API tokens. Specifically, when choosing a year far in the future (e.g., 2304), an exception is thrown:

SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2304-01-01 19:13:32' for column 'expires_at' at row 1 (Connection: mysql, SQL: insert into personal_access_tokens (name, token, abilities, expires_at, tokenable_id, tokenable_type, updated_at, created_at) values (rwerew, 6ec27502fc48fe9f43f23df4d204326748d446a4f201b11809cf9f5ddecf698d, ["read"], 2304-01-01 19:13:32, 01jj27svz5tyank2kzxf45zhyp, App\Models\User, 2025-01-20 19:13:32, 2025-01-20 19:13:32))

It seems MySQL is unable to handle dates beyond a certain range in the datetime column.
Expected Behavior

The system should handle far-future dates gracefully by rejecting them with a proper error message or by automatically capping the maximum allowed date.

Actual Behavior

An unhandled SQL exception is thrown, causing the operation to fail.

Steps to Reproduce

Set an expiration date for an API token with a very high year (e.g., 2304).
Save the token to the database.
Observe the SQL exception being thrown.

Suggestion

How can we enforce a maximum expiration date, such as capping it to 50 years from now? This would ensure compatibility with MySQL's date limitations and provide a clear constraint.

Thank you in advance for your help!

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

No branches or pull requests

1 participant