Skip to content

[Fixes #14244] Do not return WWW-Authenticate inside API exception response#14265

Merged
mattiagiupponi merged 3 commits into
masterfrom
fix_14244
May 27, 2026
Merged

[Fixes #14244] Do not return WWW-Authenticate inside API exception response#14265
mattiagiupponi merged 3 commits into
masterfrom
fix_14244

Conversation

@giohappy
Copy link
Copy Markdown
Contributor

@giohappy giohappy commented May 26, 2026

Checklist

Reviewing is a process done by project maintainers, mostly on a volunteer basis. We try to keep the overhead as small as possible and appreciate if you help us to do so by completing the following items. Feel free to ask in a comment if you have troubles with any of them.

For all pull requests:

  • Confirm you have read the contribution guidelines
  • You have sent a Contribution Licence Agreement (CLA) as necessary (not required for small changes, e.g., fixing typos in the documentation)
  • Make sure the first PR targets the master branch, eventual backports will be managed later. This can be ignored if the PR is fixing an issue that only happens in a specific branch, but not in newer ones.

The following are required only for core and extension modules (they are welcomed, but not required, for contrib modules):

  • There is a ticket in https://github.com/GeoNode/geonode/issues describing the issue/improvement/feature (a notable exemption is, changes not visible to end-users)
  • The issue connected to the PR must have Labels and Milestone assigned
  • PR for bug fixes and small new features are presented as a single commit
  • PR title must be in the form "[Fixes #<issue_number>] Title of the PR"
  • New unit tests have been added covering the changes, unless there is an explanation on why the tests are not necessary/implemented

Submitting the PR does not require you to check all items, but by the time it gets merged, they should be either satisfied or inapplicable.

@cla-bot cla-bot Bot added the cla-signed CLA Bot: community license agreement signed label May 26, 2026
@giohappy giohappy requested a review from mattiagiupponi May 26, 2026 08:53
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 modifies the custom exception handler to remove the 'WWW-Authenticate' header from 401 Unauthorized responses. However, calling .pop() on response.headers will raise an AttributeError because HttpHeaders in Django is not a mutable mapping. It is recommended to safely remove the header using the del operator on the response object directly.

Comment thread geonode/base/api/exceptions.py Outdated
Comment on lines +36 to +37
if response.status_code == 401:
response.headers.pop('WWW-Authenticate', None)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

In Django, response.headers returns an instance of HttpHeaders which inherits from CaseInsensitiveMapping (a subclass of collections.abc.Mapping, not MutableMapping). Because of this, it does not implement the pop() method, and calling response.headers.pop('WWW-Authenticate', None) will raise an AttributeError: 'HttpHeaders' object has no attribute 'pop'.

To safely and compatibly remove the header in Django, use the standard response.has_header() check and the del operator on the response object directly.

Suggested change
if response.status_code == 401:
response.headers.pop('WWW-Authenticate', None)
if response.status_code == 401 and response.has_header('WWW-Authenticate'):
del response['WWW-Authenticate']

@giohappy giohappy linked an issue May 26, 2026 that may be closed by this pull request
@codecov
Copy link
Copy Markdown

codecov Bot commented May 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.93%. Comparing base (91c4ec5) to head (e895079).
⚠️ Report is 10 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #14265   +/-   ##
=======================================
  Coverage   74.92%   74.93%           
=======================================
  Files         975      975           
  Lines       59902    59912   +10     
  Branches     8157     8159    +2     
=======================================
+ Hits        44884    44894   +10     
  Misses      13194    13194           
  Partials     1824     1824           
🚀 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.

@mattiagiupponi mattiagiupponi merged commit 3c9b610 into master May 27, 2026
17 checks passed
@mattiagiupponi mattiagiupponi deleted the fix_14244 branch May 27, 2026 09:44
mattiagiupponi pushed a commit that referenced this pull request May 27, 2026
…sponse (#14265) (#14272)

* Do not return WWW-Authenticate inside API exception response

* Test WWW-Authenticate stripped

* Fix test docstring

(cherry picked from commit 3c9b610)

Co-authored-by: Giovanni Allegri <giohappy@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 5.1.x cla-signed CLA Bot: community license agreement signed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

password prompt on private datasets.

2 participants