403 status code for failed CSRF check (teamcity 2020.2)
- Dominant language
- Python
- Stars
- 36
- Forks
- 11
- PR merge metrics
- No merged PRs in 30d
Description
on teamcity 2021.2 when i try use on of the functions for a post request i get the following CSRF errors:
```
dohq_teamcity.rest.ApiException: (403)
Reason:
HTTP response headers: HTTPHeaderDict({'TeamCity-Node-Id': 'MAIN_SERVER', 'X-Content-Type-Options': 'nosniff', 'Content-Type': 'text/plain;charset=UTF-8', 'Content-Length': '347', 'Date': 'Fri, 02 Jul 2021 18:53:05 GMT'})
HTTP response body: 403 Forbidden: Responding with 403 status code due to failed CSRF check: authenticated POST request is made, but neither tc-csrf-token parameter nor X-TC-CSRF-Token header are provided.. For a temporary workaround, you can set internal property teamcity.csrf.paranoid=false and provide valid Origin=http://localhost:8111 header with your request
```
the solution to this is apparently here: https://www.jetbrains.com/help/teamcity/csrf-protection.html#Implications+for+CORS+clients
should the library be updated to take this into account as well?
==========================
the website says to:
- token: recommend using token-based authentication and disabling cookie support (if you dont want to use use CSRF token)
- http authentication: apply for CSRF token otherwise
currently the method: rest.py::RESTClientObject::request(...) function always sets cookies if they are received.
```
if not 200 <= r.status <= 299:
raise ApiException(http_resp=r)
if self.cookie is None:
self.cookie = r.getheader('Set-Cookie')
# pass
print("\n=============out cookie:", r.getheader('Set-Cookie'), "=============\n")
return r
```
i think you should add an option to not store cookies (and do the 2 methods they suggested above)?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in rest.py at RESTClientObject.request(...), where received cookies are stored in self.cookie, and review the documented TeamCity CSRF requirements linked in the issue. Reproduce an authenticated POST against TeamCity 2021.2, then define and test the requested cookie-storage option and the two documented authentication approaches; done means the client can make the affected POST without the reported CSRF failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100