Webhooks Do Not Use Proxy Settings #3899

Closed
opened 2025-11-02 05:30:01 -06:00 by GiteaMirror · 4 comments
Owner

Originally created by @cdoantsys on GitHub (Sep 4, 2019).

  • Gitea version (or commit ref): 1.9.2
  • Git version: 2.23.0
  • Operating system: linux/amd64
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

Description

In my environment Gitea does not have direct internet access, a proxy is required. I have been able to successfully mirror repositories and use the proxy to download other items. However, I am not able to post webhooks via Microsoft Teams. After further investigations it appears that the http client that is created in the InitDeliverHooks function in webhook.go does utilize any proxy settings.

Proposed Resolution

Current Implimentation

// InitDeliverHooks starts the hooks delivery thread
func InitDeliverHooks() {
	timeout := time.Duration(setting.Webhook.DeliverTimeout) * time.Second

	webhookHTTPClient = &http.Client{
		Transport: &http.Transport{
			TLSClientConfig: &tls.Config{InsecureSkipVerify: setting.Webhook.SkipTLSVerify},
			Dial: func(netw, addr string) (net.Conn, error) {
				conn, err := net.DialTimeout(netw, addr, timeout)
				if err != nil {
					return nil, err
				}

				return conn, conn.SetDeadline(time.Now().Add(timeout))

			},
		},
	}

	go DeliverHooks()
}

Proposed Implementation

// InitDeliverHooks starts the hooks delivery thread
func InitDeliverHooks() {
	timeout := time.Duration(setting.Webhook.DeliverTimeout) * time.Second

	webhookHTTPClient = &http.Client{
		Transport: &http.Transport{
			TLSClientConfig: &tls.Config{InsecureSkipVerify: setting.Webhook.SkipTLSVerify},
			Proxy: http.ProxyFromEnvironment,
			Dial: func(netw, addr string) (net.Conn, error) {
				conn, err := net.DialTimeout(netw, addr, timeout)
				if err != nil {
					return nil, err
				}

				return conn, conn.SetDeadline(time.Now().Add(timeout))

			},
		},
	}

	go DeliverHooks()
}

I have implemented this in my environment and it is currently working.

Originally created by @cdoantsys on GitHub (Sep 4, 2019). - Gitea version (or commit ref): 1.9.2 - Git version: 2.23.0 - Operating system: linux/amd64 - Database (use `[x]`): - [ ] PostgreSQL - [ ] MySQL - [ ] MSSQL - [x] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [x] Not relevant - Log gist: ## Description In my environment Gitea does not have direct internet access, a proxy is required. I have been able to successfully mirror repositories and use the proxy to download other items. However, I am not able to post webhooks via Microsoft Teams. After further investigations it appears that the [http client](https://github.com/go-gitea/gitea/blob/master/models/webhook.go#L927) that is created in the [InitDeliverHooks](https://github.com/go-gitea/gitea/blob/master/models/webhook.go#L924) function in [webhook.go](https://github.com/go-gitea/gitea/blob/master/models/webhook.go) does utilize any proxy settings. ## Proposed Resolution #### Current Implimentation ```go // InitDeliverHooks starts the hooks delivery thread func InitDeliverHooks() { timeout := time.Duration(setting.Webhook.DeliverTimeout) * time.Second webhookHTTPClient = &http.Client{ Transport: &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: setting.Webhook.SkipTLSVerify}, Dial: func(netw, addr string) (net.Conn, error) { conn, err := net.DialTimeout(netw, addr, timeout) if err != nil { return nil, err } return conn, conn.SetDeadline(time.Now().Add(timeout)) }, }, } go DeliverHooks() } ``` #### Proposed Implementation ```go // InitDeliverHooks starts the hooks delivery thread func InitDeliverHooks() { timeout := time.Duration(setting.Webhook.DeliverTimeout) * time.Second webhookHTTPClient = &http.Client{ Transport: &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: setting.Webhook.SkipTLSVerify}, Proxy: http.ProxyFromEnvironment, Dial: func(netw, addr string) (net.Conn, error) { conn, err := net.DialTimeout(netw, addr, timeout) if err != nil { return nil, err } return conn, conn.SetDeadline(time.Now().Add(timeout)) }, }, } go DeliverHooks() } ``` I have implemented this in my environment and it is currently working.
GiteaMirror added the type/enhancement label 2025-11-02 05:30:01 -06:00
Author
Owner

@lunny commented on GitHub (Sep 5, 2019):

@cdoantsys could you send a PR?

@lunny commented on GitHub (Sep 5, 2019): @cdoantsys could you send a PR?
Author
Owner

@wpmp commented on GitHub (Oct 8, 2019):

Will this issue also be resolved in 1.9.4 or 1.10.0 only?

@wpmp commented on GitHub (Oct 8, 2019): Will this issue also be resolved in 1.9.4 or 1.10.0 only?
Author
Owner

@lunny commented on GitHub (Oct 9, 2019):

It will be on 1.10.0 only

@lunny commented on GitHub (Oct 9, 2019): It will be on 1.10.0 only
Author
Owner

@wpmp commented on GitHub (Oct 9, 2019):

Too bad, thanks.
Hope 1.10.0 will come out soon :)

@wpmp commented on GitHub (Oct 9, 2019): Too bad, thanks. Hope 1.10.0 will come out soon :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#3899