Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not send body in GET requests #306

Merged
merged 2 commits into from
Apr 5, 2023
Merged

Do not send body in GET requests #306

merged 2 commits into from
Apr 5, 2023

Conversation

ahoneiser
Copy link
Contributor

No description provided.

if "files" in kwargs:
kwargs.setdefault("data", payload)

else:
kwargs.setdefault("data", utils.json_dumps(payload))
kwargs["headers"].setdefault("Content-Type", "application/json")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
kwargs["headers"].setdefault("Content-Type", "application/json")
kwargs["headers"].setdefault("Content-Type", "application/json")
if method.lower() in ("get", "head") and kwargs.get("data"):
raise KintoException("GET requests are not allowed to have a body!")

Because in the bug we found, data is not specified, but we have payload = payload or {} and kwargs.setdefault("data", payload)

By moving it down here, we cover all cases.

with pytest.raises(KintoException) as err:
session.request("GET", "/", data={"foo": "bar"})


Copy link
Contributor

Choose a reason for hiding this comment

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

You can also add a test that fails with current master, which is:

Suggested change
def test_get_does_not_send_body(session_setup: Tuple[MagicMock, Session]):
requests_mock, _ = session_setup
response = get_200()
requests_mock.request.return_value = response
session = Session("https://example.org", timeout=4)
assert session.auth is None
session.request("GET", "/test")
requests_mock.request.assert_called_with(
"GET",
"https://example.org/test",
timeout=4,
headers=requests_mock.request.headers,
)

@leplatrem leplatrem changed the title fix: don't allow GET requests with bodies Do not send body in GET requests Apr 5, 2023
@leplatrem leplatrem merged commit eb00e55 into Kinto:master Apr 5, 2023
@ahoneiser ahoneiser deleted the no-body-for-get-requests branch April 5, 2023 16:31
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.

None yet

2 participants