|
@@ -119,20 +119,17 @@ func WebhooksNew(c *context.Context, orCtx *orgRepoContext) {
|
|
c.Success(orCtx.TmplNew)
|
|
c.Success(orCtx.TmplNew)
|
|
}
|
|
}
|
|
|
|
|
|
-func validateWebhook(actor *db.User, l macaron.Locale, w *db.Webhook) (field, msg string, ok bool) {
|
|
|
|
- if !actor.IsAdmin {
|
|
|
|
- // 🚨 SECURITY: Local addresses must not be allowed by non-admins to prevent SSRF,
|
|
|
|
- // see https://github.com/gogs/gogs/issues/5366 for details.
|
|
|
|
- payloadURL, err := url.Parse(w.URL)
|
|
|
|
- if err != nil {
|
|
|
|
- return "PayloadURL", l.Tr("repo.settings.webhook.err_cannot_parse_payload_url", err), false
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if netutil.IsLocalHostname(payloadURL.Hostname(), conf.Security.LocalNetworkAllowlist) {
|
|
|
|
- return "PayloadURL", l.Tr("repo.settings.webhook.err_cannot_use_local_addresses"), false
|
|
|
|
- }
|
|
|
|
|
|
+func validateWebhook(l macaron.Locale, w *db.Webhook) (field, msg string, ok bool) {
|
|
|
|
+ // 🚨 SECURITY: Local addresses must not be allowed by non-admins to prevent SSRF,
|
|
|
|
+ // see https://github.com/gogs/gogs/issues/5366 for details.
|
|
|
|
+ payloadURL, err := url.Parse(w.URL)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return "PayloadURL", l.Tr("repo.settings.webhook.err_cannot_parse_payload_url", err), false
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if netutil.IsBlockedLocalHostname(payloadURL.Hostname(), conf.Security.LocalNetworkAllowlist) {
|
|
|
|
+ return "PayloadURL", l.Tr("repo.settings.webhook.url_resolved_to_blocked_local_address"), false
|
|
|
|
+ }
|
|
return "", "", true
|
|
return "", "", true
|
|
}
|
|
}
|
|
|
|
|
|
@@ -144,7 +141,7 @@ func validateAndCreateWebhook(c *context.Context, orCtx *orgRepoContext, w *db.W
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- field, msg, ok := validateWebhook(c.User, c.Locale, w)
|
|
|
|
|
|
+ field, msg, ok := validateWebhook(c.Locale, w)
|
|
if !ok {
|
|
if !ok {
|
|
c.FormErr(field)
|
|
c.FormErr(field)
|
|
c.RenderWithErr(msg, orCtx.TmplNew, nil)
|
|
c.RenderWithErr(msg, orCtx.TmplNew, nil)
|
|
@@ -348,7 +345,7 @@ func validateAndUpdateWebhook(c *context.Context, orCtx *orgRepoContext, w *db.W
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- field, msg, ok := validateWebhook(c.User, c.Locale, w)
|
|
|
|
|
|
+ field, msg, ok := validateWebhook(c.Locale, w)
|
|
if !ok {
|
|
if !ok {
|
|
c.FormErr(field)
|
|
c.FormErr(field)
|
|
c.RenderWithErr(msg, orCtx.TmplNew, nil)
|
|
c.RenderWithErr(msg, orCtx.TmplNew, nil)
|