-
Notifications
You must be signed in to change notification settings - Fork 23
IALERT-3185: Manage 401 Requests to Ensure Unauthenticated Users Are Logged Out #2694
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
base: master
Are you sure you want to change the base?
IALERT-3185: Manage 401 Requests to Ensure Unauthenticated Users Are Logged Out #2694
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements automatic logout functionality for unauthenticated users by creating an HTTP interceptor that monitors API responses for 401 status codes. The interceptor ensures users are logged out when their session expires, while avoiding logout triggers for specific authentication endpoints.
Key changes:
- Creates a new
HttpInterceptorclass to monitor HTTP responses - Implements global fetch interception to handle 401 responses automatically
- Integrates the interceptor into the application startup process
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| ui/src/main/js/common/util/HttpInterceptor.js | New interceptor class that monitors fetch requests and triggers logout on 401 responses from Alert API endpoints |
| ui/src/main/js/Index.js | Initializes the HTTP interceptor during application startup |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| try { | ||
| const response = await originalFetch(...args); | ||
| if (this.shouldHandleUnauthorized(response, args[0])) { | ||
| // if (this.shouldHandleUnauthorized({status: 401, ...response}, args[0])) { |
Copilot
AI
Sep 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this commented-out debugging code before merging to production.
| // if (this.shouldHandleUnauthorized({status: 401, ...response}, args[0])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping this in for testing purposes
| if (this.shouldHandleUnauthorized(response, args[0])) { | ||
| // if (this.shouldHandleUnauthorized({status: 401, ...response}, args[0])) { |
Copilot
AI
Sep 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The URL parameter (args[0]) may not always be a string. When using fetch with a Request object, args[0] would be a Request instance, not a URL string. Consider extracting the URL properly: const url = typeof args[0] === 'string' ? args[0] : args[0].url;
| if (this.shouldHandleUnauthorized(response, args[0])) { | |
| // if (this.shouldHandleUnauthorized({status: 401, ...response}, args[0])) { | |
| const url = typeof args[0] === 'string' ? args[0] : args[0].url; | |
| if (this.shouldHandleUnauthorized(response, url)) { |
Description
IALERT-3185 was created to ensure that an invalid user is automatically logged out after a certain amount of time. This occurs when a request returns a 401 error (more on that here).
Proposed Fix
I created a class
HttpInterceptor, with the goal of intercepting requests, checking that they are valid and then proceeding from there. The way this works is any request that is sent, will be intercepted by this class and checked on it's status, determines if it's a url that should be handled by a 401, and ensures that it's a alert call. More explained on these below:AUTH_ENDPOINTS) for the sole reason that we could create infinite loops and because a 401 based on that url might have a different meaning. Here are the reasonings for each of those:/alert/api/login: 401 means invalid password credentials - we should just show a "wrong password" message/alert/api/verify: 401 means a session check failed - this is normal as the user is not logged in yet/alert/api/verify/saml: Same as/alert/api/verify/alert/api/csrf: 401 means a CSRF token request - this is also normal as we are waiting to get a new token for the user/alert/api/logout: 401 means the session has expired and the user should be logged out