fix(auth): set explicit User-Agent on Jira/Confluence sessions#1326
Open
StefanWinter-ViREQ wants to merge 2 commits into
Open
fix(auth): set explicit User-Agent on Jira/Confluence sessions#1326StefanWinter-ViREQ wants to merge 2 commits into
StefanWinter-ViREQ wants to merge 2 commits into
Conversation
Some WAFs in front of Jira/Confluence Server/DC instances block requests that carry the default `python-requests/X.Y` User-Agent and return 403 even when the bearer token is valid. The error surfaces in mcp-atlassian as a misleading "Authentication failed for Jira API (403). Token may be expired or invalid", although the same token used via `curl` works fine. Always set `User-Agent: mcp-atlassian/<version>` on the session in `JiraClient` and `ConfluenceClient` after the underlying `atlassian` client is created and before user-supplied custom headers are applied, so `JIRA_CUSTOM_HEADERS=User-Agent=...` (or `CONFLUENCE_CUSTOM_HEADERS=...`) can still override it.
|
This pull request has been automatically marked as stale because it has not had recent activity for 14 days. It will be closed if no further activity occurs. Please leave a comment or remove the 'stale' label if you believe this PR is still relevant. Thank you for your contributions! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
python-requests/X.YUser-Agent and return 403, even when the bearer token is valid. The error surfaces in mcp-atlassian as a misleadingAuthentication failed for Jira API (403). Token may be expired or invalid— although the same PAT works viacurl.JiraClientandConfluenceClientnow setUser-Agent: mcp-atlassian/<version>on the session right after the underlyingatlassianclient is created, before_apply_custom_headers(), so user-suppliedJIRA_CUSTOM_HEADERS=User-Agent=.../CONFLUENCE_CUSTOM_HEADERS=User-Agent=...still wins.utils/user_agent.py::get_default_user_agent()(usesimportlib.metadata.version("mcp-atlassian"), falls back to0.0.0when not installed — same pattern as the package__version__).Reproduction (Jira DC 9.12.4 behind a WAF)
Direct
curlwith the same URL + Bearer token consistently returns200. The WAF blocks only the defaultpython-requests/X.YUA — any identifiable UA (curl/*,Mozilla/*,mcp-atlassian/*, …) is allowed.Test plan
uv run pytest tests/unit/jira/test_client.py tests/unit/confluence/test_client.py tests/unit/jira/test_custom_headers.py tests/unit/confluence/test_custom_headers.py— all greenpre-commit run(ruff, ruff-format, mypy) — greenmain(test_stdio_lifecycle,test_date::…boundary_max_valid,test_media::…[zip]) verified unrelated to this changetest_jira_client_sets_default_user_agent/test_confluence_client_sets_default_user_agent— default UA is set on the sessiontest_jira_client_custom_user_agent_overrides_default/ equivalent for Confluence —custom_headersstill winstest_no_custom_headers_applied(Jira & Confluence) to expect the default UA being present