Skip to content

Conversation

lavalleeale
Copy link
Contributor

@lavalleeale lavalleeale commented May 23, 2025

Please check if the PR fulfills these requirements:

  • Tests for the changes have been added/updated (if possible)
  • Documentation has been updated/added if relevant
  • Screenshots are attached to Github PR if visual/UI changes were made

What is the current behavior?

Any WebSocket page can be opened and monitored by anyone with the correct page name and basic authentication.

What is the new behavior?

Connection requests to a given WebSocket page are now entirely authorized through a WebSocket authorization token, managed by the web server. The proposed window for the token is 5 minutes, during which old authorized pages that have not been revisited within their expiration window will eventually be filtered out on the next token refresh request through a sliding window approach.

{
  "iat": 1753797357.504631,
  "iss": "http://localhost:1511/",
  "sub": "instructor",
  "authorized_pages": { 
    "f25-sample-chatrooms": 1753800957,
    "f25-sample-chatrooms-1": 1753800957,
    "f25-sample-polls-3-instructor": 1753800912
  },
  "expire_time": 1753800957
}

Other information?

This implementation replaces the original authorization logic with a JWT-based system, significantly reducing authentication time during WebSocket connection setup as we no longer make an external request to the database. The testing data is based on various new WebSocket page creations for new connections and page reload cases.

  • Worst-Case:
    • Before: 1.814 ms
    • After: 0.386 ms
    • Percent Improvement: ~78.72%
  • Best-Case:
    • Before: 0.701 ms
    • After: 0.069 ms
    • Percent Improvement: ~90.16%
  • Average:
    • Before: 0.998 ms
    • After: 0.101 ms
    • Percent Improvement: ~89.86%
<Before>

0.829, 0.767, 0.993, 0.746, 0.811, 1.377, 0.813, 0.701, 0.843, 0.953,
0.805, 0.708, 0.754, 0.872, 0.717, 0.744, 0.742, 0.751, 1.152, 0.986,
0.776, 0.944, 1.048, 0.855, 0.992, 1.061, 0.834, 0.935, 1.035, 1.022, 
1.763, 0.954, 0.745, 1.102, 1.012, 1.088, 0.935, 1.279, 1.775, 1.241, 
1.150, 1.078, 1.458, 1.114, 1.001, 1.264, 1.814, 1.095, 0.755, 0.733

<After>

0.241, 0.078, 0.095, 0.087, 0.086, 0.082, 0.092, 0.096, 0.083, 0.087,
0.081, 0.077, 0.084, 0.086, 0.098, 0.085, 0.386, 0.077, 0.101, 0.081,
0.084, 0.108, 0.072, 0.073, 0.075, 0.088, 0.094, 0.089, 0.070, 0.069,
0.076, 0.080, 0.076, 0.079, 0.096, 0.073, 0.101, 0.097, 0.075, 0.085,
0.088, 0.085, 0.078, 0.078, 0.079, 0.157, 0.235, 0.126, 0.176, 0.115

@github-project-automation github-project-automation bot moved this to Seeking Reviewer in Submitty Development May 23, 2025
@lavalleeale lavalleeale marked this pull request as draft May 23, 2025 19:59
@automateprojectmangement automateprojectmangement bot moved this from Seeking Reviewer to Work in Progress in Submitty Development May 23, 2025
Copy link

codecov bot commented May 23, 2025

Codecov Report

❌ Patch coverage is 24.51923% with 157 lines in your changes missing coverage. Please review.
✅ Project coverage is 21.70%. Comparing base (db9d942) to head (b33719f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main   #11634      +/-   ##
============================================
+ Coverage     21.66%   21.70%   +0.03%     
- Complexity     9531     9582      +51     
============================================
  Files           268      268              
  Lines         36395    36560     +165     
  Branches        475      475              
============================================
+ Hits           7886     7936      +50     
- Misses        28038    28153     +115     
  Partials        471      471              
Flag Coverage Δ
autograder 21.31% <ø> (ø)
js 2.07% <ø> (ø)
migrator 100.00% <ø> (ø)
php 20.72% <24.51%> (+0.05%) ⬆️
python_submitty_utils 80.08% <ø> (ø)
submitty_daemon_jobs 90.72% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor Author

@lavalleeale lavalleeale left a comment

Choose a reason for hiding this comment

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

I can't approve or request changes since I technically am the author, but one change needs to get made and then it should be looking pretty good.

@github-actions github-actions bot added the Abandoned PR - Needs New Owner No activity on PR for more than 2 weeks -- seeking new owner to complete label Jun 18, 2025
bmcutler pushed a commit that referenced this pull request Jun 30, 2025
### Please check if the PR fulfills these requirements:

* [ ] Tests for the changes have been added/updated (if possible)
* [ ] Documentation has been updated/added if relevant
* [ ] Screenshots are attached to Github PR if visual/UI changes were
made

### What is the current behavior?
When viewing a poll, the authorization logic is handled within the polls
controller which makes it inaccessible to anywhere else in the codebase
that might need to verify if a user should have access to a poll.

### What is the new behavior?
The logic is moved to Access.php under `poll.view` and
`poll.view.histogram`

### Other information?
<!-- Is this a breaking change? -->
<!-- How did you test -->
Needed for #11634

---------

Co-authored-by: William Allen <16820599+williamjallen@users.noreply.github.com>
@jeffrey-cordero jeffrey-cordero removed DO NOT MERGE Abandoned PR - Needs New Owner No activity on PR for more than 2 weeks -- seeking new owner to complete labels Jun 30, 2025
@jeffrey-cordero jeffrey-cordero moved this from Work in Progress to In Review in Submitty Development Jun 30, 2025
@jeffrey-cordero jeffrey-cordero moved this from In Review to Work in Progress in Submitty Development Jun 30, 2025
@jeffrey-cordero jeffrey-cordero marked this pull request as ready for review July 1, 2025 18:36
@jeffrey-cordero jeffrey-cordero requested a review from martig7 July 1, 2025 18:38
@automateprojectmangement automateprojectmangement bot moved this from Work in Progress to Seeking Reviewer in Submitty Development Jul 1, 2025
@automateprojectmangement automateprojectmangement bot moved this from Seeking Reviewer to In Review in Submitty Development Jul 1, 2025
Copy link
Contributor

@martig7 martig7 left a comment

Choose a reason for hiding this comment

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

Maybe we should consider adding a method to revoke websocket tokens.

@github-project-automation github-project-automation bot moved this from In Review to Work in Progress in Submitty Development Aug 4, 2025
@jeffrey-cordero jeffrey-cordero requested a review from martig7 August 5, 2025 12:23
@automateprojectmangement automateprojectmangement bot moved this from Work in Progress to In Review in Submitty Development Aug 5, 2025
Copy link
Contributor

@martig7 martig7 left a comment

Choose a reason for hiding this comment

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

This PR makes multiple improvements to the ease of development of websocket features, and makes them more secure as well.

@github-project-automation github-project-automation bot moved this from In Review to Awaiting Maintainer Review in Submitty Development Aug 6, 2025
@jeffrey-cordero jeffrey-cordero moved this from Awaiting Maintainer Review to In Review in Submitty Development Aug 8, 2025
Copy link
Member

@cjreed121 cjreed121 left a comment

Choose a reason for hiding this comment

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

Overall, this looks good. Still looking at a couple security aspects. Left a couples comments and may have some more follow up once some questions are answered.

I think the short lived 5 minute tokens work fine but there is a downside to their lifetime. Sometimes the websocket server needs a manual restart (or has even crashed) which unfortunately drops all connections and makes everyone reconnect. With this approach, after 5 minutes of being on the page, they won't be able to reconnect until a page reload which is unfortunate. A good solution to this would be to recognize the expiration time or the auth failure, and request a new websocket token via AJAX. However this can definitely be a future improvement issue as this PR is already quite large.

@github-project-automation github-project-automation bot moved this from In Review to Work in Progress in Submitty Development Aug 13, 2025
@automateprojectmangement automateprojectmangement bot moved this from Work in Progress to In Review in Submitty Development Aug 14, 2025
Copy link
Member

@cjreed121 cjreed121 left a comment

Choose a reason for hiding this comment

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

Code looks good to me. No concerns security wise. Just one minor comment about the testing which can quickly be fixed (and worst case it could be addressed in a future PR). Note this is just a code review and I have not locally tested this.

@github-project-automation github-project-automation bot moved this from In Review to Awaiting Maintainer Review in Submitty Development Aug 19, 2025
@bmcutler bmcutler merged commit 3708b4f into main Aug 22, 2025
47 of 48 checks passed
@bmcutler bmcutler deleted the websocket-verification branch August 22, 2025 16:04
@github-project-automation github-project-automation bot moved this from Awaiting Maintainer Review to Done in Submitty Development Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants