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

Fix broken webhooks #29690

Merged
merged 5 commits into from
Mar 10, 2024
Merged

Fix broken webhooks #29690

merged 5 commits into from
Mar 10, 2024

Conversation

lunny
Copy link
Member

@lunny lunny commented Mar 9, 2024

Fix #29689
This PR makes the default http method of webhook as POST instead of GET

@lunny lunny added type/bug skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. labels Mar 9, 2024
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 9, 2024
@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Mar 9, 2024
@wxiaoguang
Copy link
Contributor

How does this change fix the bug? newDefaultRequest uses POST by default by a fallthrough.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Mar 9, 2024

And I can see JS error on the "add webhook" page (regression of #29211)

WebHookEditor.js:26 Uncaught TypeError: Cannot read properties of null (reading 'value')
    at updateContentType (WebHookEditor.js:26:58)
    at initCompWebHookEditor (WebHookEditor.js:29:3)
    at HTMLDocument.<anonymous> (index.js:109:24)

  const updateContentType = function () {
    const visible = document.getElementById('http_method').value === 'POST';  // <--------- HERE
    toggleElem(document.getElementById('content_type').parentNode.parentNode, visible);
  };

Maybe something is caused by the refactoring, while something is already broken before the refactoring.

Update: the JS error has been fixed by #29692

@lunny
Copy link
Member Author

lunny commented Mar 9, 2024

How does this change fix the bug? newDefaultRequest uses POST by default by a fallthrough.

I have tested in production env, it fixed. I haven't looked into the logic.

@wxiaoguang
Copy link
Contributor

I think the real bug is here:

image

@wxiaoguang
Copy link
Contributor

I have tested in production env, it fixed. I haven't looked into the logic.

I guess you only tested WeCom(WechatWork)

But the underlying bug affects almost all webhooks.

@lunny
Copy link
Member Author

lunny commented Mar 9, 2024

I have tested in production env, it fixed. I haven't looked into the logic.

I guess you only tested WeCom(WechatWork)

But the underlying bug affects almost all webhooks.

The w.HTTPMethod should be POST but now it's GET and the database field http_method is empty. Some webhooks types accept GET like feishu/lark, so they haven't been affected.

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Mar 9, 2024

I have tested in production env, it fixed. I haven't looked into the logic.

I guess you only tested WeCom(WechatWork)
But the underlying bug affects almost all webhooks.

The w.HTTPMethod should be POST but now it's GET and the database field http_method is empty. Some webhooks types accept GET like feishu/lark, so they haven't been affected.

I think the logic should be checked carefully. Do all these webhooks accept "GET"? Should it default the empty HTTP method to POST (just like newDefaultRequest)? Or even ignore the HTTPMethod, always use "POST" for the "JSON body"?

image

@lunny
Copy link
Member Author

lunny commented Mar 9, 2024

I have tested in production env, it fixed. I haven't looked into the logic.

I guess you only tested WeCom(WechatWork)
But the underlying bug affects almost all webhooks.

The w.HTTPMethod should be POST but now it's GET and the database field http_method is empty. Some webhooks types accept GET like feishu/lark, so they haven't been affected.

I think the logic should be checked carefully. Do all these webhooks accept "GET"? Should it default the empty HTTP method to POST (just like newDefaultRequest)?

Maybe we need to fill HTTPMethod clearly for every webhookParams. At present, Gitea, matrix filled the HTTPMethod when creating.

图片

@wxiaoguang
Copy link
Contributor

But I do not see why it should use "GET" method for a "JSON body"

@silverwind
Copy link
Member

silverwind commented Mar 9, 2024

Please don't use GET with body, unless the other end requires it. Either move params to query or make it a POST.

@lunny
Copy link
Member Author

lunny commented Mar 9, 2024

Please don't use GET with body, unless the other end requires it. Either move params to query or make it a POST.

I believe #29145 accidently make the default methods as GET, we are talking about how to fix it.

@lunny
Copy link
Member Author

lunny commented Mar 9, 2024

But I do not see why it should use "GET" method for a "JSON body"

I just pointed out that feishu/lark hasn't been affected by the POST -> GET change because they support GET. But I don't mean it should be GET.

@wxiaoguang
Copy link
Contributor

But I do not see why it should use "GET" method for a "JSON body"

I just pointed out that feishu/lark hasn't been affected by the POST -> GET change because they support GET. But I don't mean it should be GET.

I was talking about #29690 (comment) : after the feishu/lark comment, it is for the Maybe we need to fill HTTPMethod clearly for every webhookParams. At present, Gitea, matrix filled the HTTPMethod when creating, my suggestion is use "POST" for "JSON body" in the "newJSONRequest" (if it is the old behavior)

@lunny
Copy link
Member Author

lunny commented Mar 9, 2024

But I do not see why it should use "GET" method for a "JSON body"

I just pointed out that feishu/lark hasn't been affected by the POST -> GET change because they support GET. But I don't mean it should be GET.

I was talking about #29690 (comment) : after the feishu/lark comment, it is for the Maybe we need to fill HTTPMethod clearly for every webhookParams. At present, Gitea, matrix filled the HTTPMethod when creating, my suggestion is use "POST" for "JSON body" in the "newJSONRequest" (if it is the old behavior)

6052ecf

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 9, 2024
@jessielw
Copy link

jessielw commented Mar 9, 2024

Can confirm that latest nightly broke discord webhooks as well

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 9, 2024
@lunny lunny changed the title Fix wechatwork webhook Fix broken webhooks Mar 10, 2024
@lunny lunny enabled auto-merge (squash) March 10, 2024 01:06
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 10, 2024
@lunny lunny merged commit 6e8762f into go-gitea:main Mar 10, 2024
26 checks passed
@GiteaBot GiteaBot added this to the 1.23.0 milestone Mar 10, 2024
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 10, 2024
@lunny lunny deleted the lunny/fix_wechat_webhook branch March 10, 2024 01:33
@lunny lunny modified the milestones: 1.23.0, 1.22.0 Mar 10, 2024
zjjhot added a commit to zjjhot/gitea that referenced this pull request Mar 11, 2024
* giteaofficial/main:
  Use repo object format name instead of detecting from git repository (go-gitea#29702)
  Improve CSV rendering (go-gitea#29638)
  Remove jQuery AJAX from the comment edit history (go-gitea#29703)
  fix: rendering internal file links in org (go-gitea#29669)
  Fix broken webhooks (go-gitea#29690)
  Suppress error from monaco-editor (go-gitea#29684)
DennisRasey pushed a commit to DennisRasey/forgejo that referenced this pull request Mar 13, 2024
silverwind pushed a commit that referenced this pull request Mar 14, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WechatWork webhook can NOT use after apply PR:[REFACTOR] store webhook event in database
6 participants