Avoid multiple requests without a valid token#313
Avoid multiple requests without a valid token#313mateodurante wants to merge 1 commit intocerttools:developfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR tightens client-side authentication behavior in the IntelMQ Manager frontend by preventing authenticated AJAX calls from being issued without a session token and by logging the user out when the backend returns 401 Unauthorized.
Changes:
- In
authenticatedAjax, short-circuit requests whensessionStoragehas nologin_tokenby returning a rejected promise with a synthetic 401. - In
ajax_fail_callback, automatically calllogout()when a request fails with HTTP 401.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Good idea, we have problems with this specialy when we use Intelmq during trainings, the students restart the docker and everything look like freeze! |
That would be a great solution, but the main issue is that the login is currently a modal that loads across all pages rather than a dedicated route. To implement a clean redirect, we would really need a standalone login page. I’ve experimented with forcing the modal to open automatically or trying a workaround, but the user experience feels clunky and 'off.' Ideally, we should move toward having a primary login page to handle these redirects properly. In the meantime, the current approach serves as a safeguard: it prevents an infinite loop of requests and ensures the 'logged in user' state is cleared/updated if the token is no longer valid. |
This pull request improves client-side authentication handling in the
intelmq_manager/static/js/static.jsfile. The main changes focus on preventing unauthorized requests and ensuring users are logged out if their session is no longer valid.This PR prevents multiple 401 requests issue:

Authentication handling improvements:
authenticatedAjaxfunction, added a check to prevent AJAX requests from being sent if there is no login token insessionStorage; instead, the function now immediately rejects the request with a 401 Unauthorized error and an appropriate message.ajax_fail_callbackfunction, added logic to automatically calllogout()if a 401 Unauthorized response is received, ensuring users are logged out when their session expires or becomes invalid.