Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Session timeout notification #12093

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

Merged
merged 3 commits into from
Apr 7, 2025

Conversation

kevin-vuong99
Copy link
Contributor

Re-creation of #12054

Description

Issue: Session timeout without letting the user either extend the time or have any type of indication that the session is about to expire.
A warning will appear shortly before the session expires using Bootstrap's modal components warning the user their session will expire soon.

Impact on Users

People with physical disabilities often need more time to react, to type and to complete activities. People with low vision need more time to locate things on screen and to read. People who are blind and using screen readers may need more time to understand screen layouts, to find information and to operate controls. People who have cognitive or language limitations need more time to read and to understand. People who are deaf and communicate in sign language may need more time to read information printed in text (which may be a second language for some).

In circumstances where a sign-language interpreter may be relating audio content to a user who is deaf, control over time limits is also important.

People with reading disabilities, cognitive limitations, and learning disabilities who may need more time to read or comprehend information can have additional time to read the information by pausing the content.

Remediation

image

The user is warned before time expires.
I used a context processor to pass the session cookie age value to base.html. Since no view directly renders base.html, I didn't think I could use a view-based approach. If there is a better idea, I can modify the PR.

@github-actions github-actions bot added settings_changes Needs changes to settings.py based on changes in settings.dist.py included in this PR ui labels Mar 24, 2025
Copy link

dryrunsecurity bot commented Mar 24, 2025

DryRun Security Summary

A patch implements a session expiry notification feature with context processor and frontend modal, addressing potential session management vulnerabilities while using Django's built-in session management and XSS mitigation techniques.

Expand for full summary

Summary: A patch introduces a new session expiry notification feature across multiple files, adding a context processor, configuration settings, and a frontend modal to warn users about session timeouts.

Security Findings:

  1. Potential Session Management Vulnerabilities

    • Broad exception handling in context processor could mask specific error conditions
    • Potential timing synchronization risks between client and server session management
  2. Input Handling Considerations

    • Uses escapejs filter to mitigate potential XSS risks
    • Timestamp conversion uses Math.floor(Date.now() / 1000)
  3. Configuration Security Notes

    • Configurable session expiry warning time
    • Relies on Django's built-in session management settings

No critical security vulnerabilities were identified in the provided summaries.

Code Analysis

We ran 7 analyzers against 3 files and 1 analyzer had findings. 6 analyzers had no findings.

Analyzer Findings
Configured Codepaths Analyzer 5 findings

Overall Riskiness

🔴 Risk threshold exceeded.

We've notified @mtesauro, @grendel513.

View PR in the DryRun Dashboard.

return {}
else:
return {
"session_expiry_time": expiry_time,
Copy link
Contributor

Choose a reason for hiding this comment

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

expiry time doesn't appear to ultimately be used -- can it just be removed from here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Done.


function session_notifcation() {
var warningTime = "{{ session_notify_time|default:0|escapejs }}"; // When the warning will show
var expiryTime = "{{ session_expiry_time|default:0|escapejs }}"; // When the session will expire
Copy link
Contributor

Choose a reason for hiding this comment

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

This var is unused and can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also done

@Maffooch Maffooch added this to the 2.46.0 milestone Apr 3, 2025
@Maffooch Maffooch requested a review from dogboat April 3, 2025 18:25
Copy link
Contributor

@mtesauro mtesauro left a comment

Choose a reason for hiding this comment

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

Approved

@mtesauro mtesauro merged commit 4d2cafc into DefectDojo:dev Apr 7, 2025
76 of 77 checks passed
Maffooch added a commit that referenced this pull request Apr 7, 2025
@Maffooch
Copy link
Contributor

Maffooch commented Apr 7, 2025

Hi @kevin-vuong99 this one ended up breaking unit tests once it got fully into the dev branch. For the sake of getting the release out today, I am reverting this PR. I am not sure exactly why tests did not fail on this PR directly.. Sometimes there are conflicting features on separate branches (sometimes by different contributors) and when they are introduced, we find that the two PRs do not work well together.

Here are some of the errors that are occurring:

Browser:

login:1 Blocked aria-hidden on an element because its descendant retained focus. The focus must not be hidden from assistive technology users. Avoid using aria-hidden on a focused element or its ancestor. Consider using the inert attribute instead, which will also prevent focus. For more details, see the aria-hidden section of the WAI-ARIA specification at https://w3c.github.io/aria/#aria-hidden.

Unit test failures:

integration-tests-1  | ======================================================================
integration-tests-1  | ERROR: test_login (base_test_class.BaseTestCase.test_login)
integration-tests-1  | ----------------------------------------------------------------------
integration-tests-1  | Traceback (most recent call last):
integration-tests-1  |   File "/app/tests/base_test_class.py", line 158, in test_login
integration-tests-1  |     return self.login_page()
integration-tests-1  |            ^^^^^^^^^^^^^^^^^
integration-tests-1  |   File "/app/tests/base_test_class.py", line 132, in login_page
integration-tests-1  |     driver.find_element(By.CSS_SELECTOR, "button.btn.btn-success").click()
integration-tests-1  |   File "/usr/local/lib/python3.11/site-packages/selenium/webdriver/remote/webelement.py", line 94, in click
integration-tests-1  |     self._execute(Command.CLICK_ELEMENT)
integration-tests-1  |   File "/usr/local/lib/python3.11/site-packages/selenium/webdriver/remote/webelement.py", line 403, in _execute
integration-tests-1  |     return self._parent.execute(command, params)
integration-tests-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
integration-tests-1  |   File "/usr/local/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 440, in execute
integration-tests-1  |     self.error_handler.check_response(response)
integration-tests-1  |   File "/usr/local/lib/python3.11/site-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response
integration-tests-1  |     raise exception_class(message, screen, stacktrace)
integration-tests-1  | selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <button class="btn btn-success">...</button> is not clickable at point (609, 207). Other element would receive the click: <div class="modal fade in" id="sessionTimeoutModal" tabindex="-1" role="dialog" aria-labelledby="sessionModalLabel" aria-hidden="true" style="display: block; padding-right: 15px;">...</div

Maffooch added a commit that referenced this pull request Apr 7, 2025
@kevin-vuong99
Copy link
Contributor Author

Hi @kevin-vuong99 this one ended up breaking unit tests once it got fully into the dev branch. For the sake of getting the release out today, I am reverting this PR. I am not sure exactly why tests did not fail on this PR directly.. Sometimes there are conflicting features on separate branches (sometimes by different contributors) and when they are introduced, we find that the two PRs do not work well together.

Here are some of the errors that are occurring:

Browser:

login:1 Blocked aria-hidden on an element because its descendant retained focus. The focus must not be hidden from assistive technology users. Avoid using aria-hidden on a focused element or its ancestor. Consider using the inert attribute instead, which will also prevent focus. For more details, see the aria-hidden section of the WAI-ARIA specification at https://w3c.github.io/aria/#aria-hidden.

Unit test failures:

integration-tests-1  | ======================================================================
integration-tests-1  | ERROR: test_login (base_test_class.BaseTestCase.test_login)
integration-tests-1  | ----------------------------------------------------------------------
integration-tests-1  | Traceback (most recent call last):
integration-tests-1  |   File "/app/tests/base_test_class.py", line 158, in test_login
integration-tests-1  |     return self.login_page()
integration-tests-1  |            ^^^^^^^^^^^^^^^^^
integration-tests-1  |   File "/app/tests/base_test_class.py", line 132, in login_page
integration-tests-1  |     driver.find_element(By.CSS_SELECTOR, "button.btn.btn-success").click()
integration-tests-1  |   File "/usr/local/lib/python3.11/site-packages/selenium/webdriver/remote/webelement.py", line 94, in click
integration-tests-1  |     self._execute(Command.CLICK_ELEMENT)
integration-tests-1  |   File "/usr/local/lib/python3.11/site-packages/selenium/webdriver/remote/webelement.py", line 403, in _execute
integration-tests-1  |     return self._parent.execute(command, params)
integration-tests-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
integration-tests-1  |   File "/usr/local/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 440, in execute
integration-tests-1  |     self.error_handler.check_response(response)
integration-tests-1  |   File "/usr/local/lib/python3.11/site-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response
integration-tests-1  |     raise exception_class(message, screen, stacktrace)
integration-tests-1  | selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <button class="btn btn-success">...</button> is not clickable at point (609, 207). Other element would receive the click: <div class="modal fade in" id="sessionTimeoutModal" tabindex="-1" role="dialog" aria-labelledby="sessionModalLabel" aria-hidden="true" style="display: block; padding-right: 15px;">...</div

Hi @Maffooch, do you know what would the next steps be for this?

@Maffooch
Copy link
Contributor

Maffooch commented Apr 7, 2025

Will need to create a new PR, and if tests fail, do whatever it takes to make them pass. If tests do not fail, then we'll need to figure out what that looks like. Please be sure to update your branch with the latest version of the dev branch before starting, as that seemed to have an impact here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
settings_changes Needs changes to settings.py based on changes in settings.dist.py included in this PR ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants