Skip to content

Update relevant 401 codes to 403 in middleware - #2622

Open
hminsky2002 wants to merge 1 commit into
mainfrom
2547-use-http-403-in-place-of-401-when-needed
Open

hminsky2002 wants to merge 1 commit into
mainfrom
2547-use-http-403-in-place-of-401-when-needed

Conversation

@hminsky2002

Copy link
Copy Markdown
Contributor

an authenticated user who isn't an admin will get a 401 response on certain middleware responses, when they should be getting 403. This commit updates the relevant middleware and handlers to accomodate this!

Closes #2547

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The implementation, tests, OpenAPI contracts, and changelog consistently apply the corrected authorization semantics.

0 open findings

What changed in this PR

Corrects authorization semantics by returning 403 for authenticated users lacking required permissions while preserving 401 for unauthenticated requests.

Changes:

  • Updates administrator and permission checks to use ForbiddenError.
  • Aligns integration tests and OpenAPI responses with the new status codes.
  • Documents the behavior change in the changelog.
File Description
CHANGELOG.md Documents corrected authorization responses.
src/​middleware/​requireAdministratorRole.ts Distinguishes unauthenticated and forbidden requests.
src/​middleware/​__tests__/​requireAdministratorRole.int.test.ts Tests the middleware’s 401/403 behavior.
src/​handlers/​terminologySetsHandlers.ts Returns 403 for insufficient terminology-set permissions.
src/​handlers/​opportunitiesHandlers.ts Returns 403 when terminology-set reference permission is absent.
src/​__tests__/​terminologySets.int.test.ts Updates terminology and opportunity expectations.
src/​__tests__/​sources.int.test.ts Updates administrator-only deletion expectation.
src/​__tests__/​funders.int.test.ts Updates administrator-only funder expectations.
src/​__tests__/​defaultPermissionGrants.int.test.ts Updates administrator-only grant expectations.
src/​__tests__/​dataProviders.int.test.ts Updates administrator-only provider expectation.
src/​__tests__/​changemakers.int.test.ts Updates administrator-only patch expectation.
src/​__tests__/​baseFieldsCopyTasks.int.test.ts Updates administrator-only task expectations.
src/​__tests__/​baseFields.int.test.ts Updates administrator-only field expectations.
src/​openapi/​paths/​terminologySets.json Documents POST 403 response.
src/​openapi/​paths/​terminologySet.json Documents PATCH 403 response.
src/​openapi/​paths/​source.json Documents DELETE 403 response.
src/​openapi/​paths/​funderCollaborativeMember.json Documents member-operation 403 responses.
src/​openapi/​paths/​funder.json Documents PUT 403 response.
src/​openapi/​paths/​defaultPermissionGrants.json Documents collection-level 403 responses.
src/​openapi/​paths/​defaultPermissionGrant.json Documents item-level 403 responses.
src/​openapi/​paths/​dataProvider.json Documents PUT 403 response.
src/​openapi/​paths/​changemakerFiscalSponsor.json Documents fiscal-sponsor 403 responses.
src/​openapi/​paths/​changemaker.json Documents PATCH 403 response.
src/​openapi/​paths/​baseFieldsCopyTasks.json Documents task-operation 403 responses.
src/​openapi/​paths/​baseFieldLocalization.json Documents localization PUT 403 response.
src/​openapi/​paths/​baseField.json Documents base-field PUT 403 response.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.19%. Comparing base (65810c7) to head (324c3b8).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2622   +/-   ##
=======================================
  Coverage   94.19%   94.19%           
=======================================
  Files         345      345           
  Lines        4425     4428    +3     
  Branches      582      583    +1     
=======================================
+ Hits         4168     4171    +3     
  Misses        256      256           
  Partials        1        1           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 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.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

🔎 A preview deployment of this pull request is available at https://utilities.philanthropydatacommons.org/pdc-service-preview-2622-jzkgl/ (and upstream https://pdc-service-preview-2622-jzkgl.ondigitalocean.app) assuming this PR is still open. 🔍

@hminsky2002
hminsky2002 requested a review from slifty October 12, 2026 13:58
an authenticated user who isn't an admin will get a 401 response on certain middleware responses, when they should be getting 403. this commit updates the relevant middleware and handlers to accomodate this

Issue #2547 Use HTTP 403 in place of 401 where needed
@hminsky2002
hminsky2002 force-pushed the 2547-use-http-403-in-place-of-401-when-needed branch from ca79c52 to 324c3b8 Compare October 12, 2026 13:59

This branch has not been deployed

No deployments
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.

Use HTTP 403 in place of 401 where needed

3 participants