Skip to content

Conversation

@iceljc
Copy link
Collaborator

@iceljc iceljc commented Nov 13, 2025

PR Type

Bug fix


Description

  • Add null token validation in HTTP response interceptor

  • Redirect to login when user token is missing or invalid

  • Prevent token refresh attempts with null token state


Diagram Walkthrough

flowchart LR
  A["HTTP Response"] --> B["Check User Token"]
  B --> C{Token Exists?}
  C -->|No| D["Redirect to Login"]
  C -->|Yes| E["Continue Processing"]
  D --> F["Reject Promise"]
Loading

File Walkthrough

Relevant files
Bug fix
http.js
Add token validation and login redirect logic                       

src/lib/helpers/http.js

  • Added null token validation in response interceptor success handler
  • Added null token check in error handler before token refresh logic
  • Redirects to login page when user token is missing
  • Prevents unnecessary token refresh attempts with invalid token state
+8/-0     

@qodo-merge-pro
Copy link

qodo-merge-pro bot commented Nov 13, 2025

PR Compliance Guide 🔍

(Compliance updated until commit 616fc11)

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status:
Missing audit logs: The new branches that redirect to login on missing token and handle 401s add no audit
logging of this critical security event, making it unclear which user/session triggered
the action.

Referred Code
    const user = getUserStore();
    if (!user?.token) {
        redirectToLogin();
    }
    return response;
},
(error) => {
    loaderStore.set(false);
    const originalRequest = error?.config || {};
    const user = getUserStore();
    if (!user?.token) {
        redirectToLogin();
        return Promise.reject(error);
    }

    // If token expired or 401 returned, attempt a single token refresh and retry requests in queue.
    if ((error?.response?.status === 401 || isTokenExired(user.expires))
        && originalRequest

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
Limited error context: Errors leading to redirect are rejected without contextual logging or differentiation of
causes, which may hinder debugging and monitoring of edge cases like null tokens versus
expired tokens.

Referred Code
if (!user?.token) {
    redirectToLogin();
    return Promise.reject(error);
}

// If token expired or 401 returned, attempt a single token refresh and retry requests in queue.
if ((error?.response?.status === 401 || isTokenExired(user.expires))
    && originalRequest

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status:
Token handling path: While null-token checks are added, there is no visible authorization validation or secure
handling evidence for token refresh/retry in this diff, requiring verification against the
broader implementation.

Referred Code
    const user = getUserStore();
    if (!user?.token) {
        redirectToLogin();
    }
    return response;
},
(error) => {
    loaderStore.set(false);
    const originalRequest = error?.config || {};
    const user = getUserStore();
    if (!user?.token) {
        redirectToLogin();
        return Promise.reject(error);
    }

    // If token expired or 401 returned, attempt a single token refresh and retry requests in queue.
    if ((error?.response?.status === 401 || isTokenExired(user.expires))
        && originalRequest

Learn more about managing compliance generic rules or creating your own custom rules

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

Previous compliance checks

Compliance check up to commit 616fc11
Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status:
Missing audit logs: New auth-flow actions (redirect on missing token) are performed without emitting any audit
log entries capturing user, action, and outcome.

Referred Code
    const user = getUserStore();
    if (!user?.token) {
        redirectToLogin();
    }
    return response;
},
(error) => {
    loaderStore.set(false);
    const originalRequest = error?.config || {};
    const user = getUserStore();
    if (!user?.token) {
        redirectToLogin();
        return Promise.reject(error);
    }

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
Early redirect path: The early redirect/reject on missing token lacks contextual error handling or logging,
making operational diagnosis of this edge case difficult.

Referred Code
    const user = getUserStore();
    if (!user?.token) {
        redirectToLogin();
    }
    return response;
},
(error) => {
    loaderStore.set(false);
    const originalRequest = error?.config || {};
    const user = getUserStore();
    if (!user?.token) {
        redirectToLogin();
        return Promise.reject(error);
    }

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status:
Token state handling: Redirect and retry logic is added around auth state, but there is no visible validation or
sanitization of external inputs or assurance against replay/refresh edge cases in the
added paths.

Referred Code
    const user = getUserStore();
    if (!user?.token) {
        redirectToLogin();
    }
    return response;
},
(error) => {
    loaderStore.set(false);
    const originalRequest = error?.config || {};
    const user = getUserStore();
    if (!user?.token) {
        redirectToLogin();
        return Promise.reject(error);
    }

    // If token expired or 401 returned, attempt a single token refresh and retry requests in queue.
    if ((error?.response?.status === 401 || isTokenExired(user.expires))
        && originalRequest

Learn more about managing compliance generic rules or creating your own custom rules

@iceljc iceljc merged commit 5e94cf4 into SciSharp:main Nov 13, 2025
1 of 2 checks passed
@qodo-merge-pro
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Prevent race conditions on redirect

In the axios response interceptor, return a non-resolving promise after calling
redirectToLogin() to prevent race conditions and halt further execution before
the redirect completes.

src/lib/helpers/http.js [116-123]

 (response) => {
     loaderStore.set(false);
     const user = getUserStore();
     if (!user?.token) {
         redirectToLogin();
+        return new Promise(() => {});
     }
     return response;
 },
  • Apply / Chat
Suggestion importance[1-10]: 8

__

Why: The suggestion correctly identifies a race condition introduced in the PR, where promise handlers could execute during a page redirect, and proposes a valid fix to prevent potential UI errors.

Medium
  • More

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant