Skip to content

fix(auth): require admin role for upload, simplify requireAdmin#312

Merged
fank merged 2 commits intomainfrom
fix/auth-review-feedback
Mar 5, 2026
Merged

fix(auth): require admin role for upload, simplify requireAdmin#312
fank merged 2 commits intomainfrom
fix/auth-review-feedback

Conversation

@fank
Copy link
Copy Markdown
Member

@fank fank commented Mar 5, 2026

Summary

Addresses PR #311 review feedback:

  • Security fix: StoreOperation (upload endpoint) JWT fallback now checks role == "admin" instead of just token validity. Previously any authenticated viewer could upload recordings.
  • Cleanup: requireAdmin middleware removed redundant double-validation — Claims() already validates the token internally.

Test plan

  • All Go tests pass
  • Upload with admin JWT succeeds
  • Upload with viewer JWT is rejected (403)

StoreOperation JWT fallback now checks role=admin (not just token
validity), preventing viewers from uploading. Removes redundant
double-validation in requireAdmin middleware.

Addresses PR #311 review feedback.
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the application's security by enforcing an "admin" role check for JWT-based uploads, closing a potential vulnerability where any authenticated user could upload recordings. Concurrently, it refactors the requireAdmin authentication middleware to remove unnecessary token validation, streamlining the codebase and improving efficiency.

Highlights

  • Security Enhancement: The StoreOperation (upload endpoint) now strictly requires an "admin" role for JWT fallback authentication, preventing unauthorized uploads by non-admin authenticated users.
  • Code Refinement: The requireAdmin middleware was simplified by removing a redundant jwt.Validate call, as the Claims() method already handles token validation internally.
Changelog
  • internal/server/handler.go
    • Updated the JWT fallback logic in StoreOperation to explicitly check if the token's claims include an "admin" role.
  • internal/server/handler_auth.go
    • Removed the h.jwt.Validate(token) check from the requireAdmin middleware, as the subsequent h.jwt.Claims(token) call implicitly handles token validity.
  • internal/server/handler_test.go
    • Modified test cases for TestStoreOperation_CookieAuth and TestStoreOperation_JWTAuth to create JWTs with the WithRole("admin") option, aligning tests with the new security requirements.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses a critical security vulnerability by enforcing an 'admin' role for the upload endpoint when using JWT authentication. The simplification of the requireAdmin middleware by removing redundant validation is also a good cleanup. The test updates align with these changes. I've added a couple of suggestions to further improve the test suite: one to ensure consistency in error handling and another to add a specific test case for the newly protected authorization path, which will help prevent future regressions.

Note: Security Review did not run due to the size of the PR.

Comment thread internal/server/handler_test.go
Comment thread internal/server/handler_test.go Outdated
Address PR #312 review feedback:
- Add test verifying viewer JWT is rejected (403) on upload
- Use require.NoError for JWT creation in TestStoreOperation_JWTAuth
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 5, 2026

Merging this branch will decrease overall coverage

Impacted Packages Coverage Δ 🤖
github.com/OCAP2/web/internal/server 94.27% (-0.00%) 👎

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/OCAP2/web/internal/server/handler.go 96.31% (+0.03%) 271 (+2) 261 (+2) 10 👍
github.com/OCAP2/web/internal/server/handler_auth.go 92.66% (-0.20%) 109 (-3) 101 (-3) 8 👎

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/OCAP2/web/internal/server/handler_test.go

@fank fank merged commit 1917fca into main Mar 5, 2026
2 checks passed
@fank fank deleted the fix/auth-review-feedback branch March 5, 2026 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant