From 0704009dd77dd515f1f4d34c693ef50d0c7f5a5e Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 6 Apr 2022 01:32:24 +0800 Subject: [PATCH] Revert the minimal golang version requirement from 1.17 to 1.16 and add a warning in Makefile (#19319) * Revert the minimal golang version requirement from 1.17 to 1.16 and add a warning in Makefile * Apply suggestions from code review Co-authored-by: John Olheiser * 1.16 * Update modules/util/net.go Co-authored-by: Gusted * correct bool conditional yay tests for catching this :) * Update hostmatcher.go Co-authored-by: John Olheiser Co-authored-by: techknowlogick Co-authored-by: Gusted --- .drone.yml | 2 +- Makefile | 7 +++++-- docs/config.yaml | 2 +- go.mod | 2 +- modules/hostmatcher/hostmatcher.go | 6 ++++-- modules/util/net.go | 19 +++++++++++++++++++ 6 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 modules/util/net.go diff --git a/.drone.yml b/.drone.yml index b3b1682619a3..7bfdefa266e0 100644 --- a/.drone.yml +++ b/.drone.yml @@ -109,7 +109,7 @@ steps: depends_on: [test-frontend] - name: build-backend-no-gcc - image: golang:1.17 # this step is kept as the lowest version of golang that we support + image: golang:1.16 # this step is kept as the lowest version of golang that we support pull: always environment: GO111MODULE: on diff --git a/Makefile b/Makefile index bbd099ed2823..a15caf7a8f4d 100644 --- a/Makefile +++ b/Makefile @@ -203,10 +203,13 @@ help: go-check: $(eval MIN_GO_VERSION_STR := $(shell grep -Eo '^go\s+[0-9]+\.[0-9.]+' go.mod | cut -d' ' -f2)) $(eval MIN_GO_VERSION := $(shell printf "%03d%03d%03d" $(shell echo '$(MIN_GO_VERSION_STR)' | tr '.' ' '))) - $(eval GO_VERSION := $(shell printf "%03d%03d%03d" $(shell $(GO) version | grep -Eo '[0-9]+\.[0-9.]+' | tr '.' ' ');)) + $(eval GO_VERSION_STR := $(shell $(GO) version | grep -Eo '[0-9]+\.[0-9.]+')) + $(eval GO_VERSION := $(shell printf "%03d%03d%03d" $(shell echo '$(GO_VERSION_STR)' | tr '.' ' '))) @if [ "$(GO_VERSION)" -lt "$(MIN_GO_VERSION)" ]; then \ - echo "Gitea requires Go $(MIN_GO_VERSION_STR) or greater to build. You can get it at https://go.dev/dl/"; \ + echo "Gitea requires Go $(MIN_GO_VERSION_STR) or greater to build, but $(GO_VERSION) was found. You can get an updated version at https://go.dev/dl/"; \ exit 1; \ + else \ + echo "WARNING: Please ensure Go $(GO_VERSION_STR) is still maintained to avoid possible security problems. You can check it at https://go.dev/dl/"; \ fi .PHONY: git-check diff --git a/docs/config.yaml b/docs/config.yaml index c3614e4bc860..e77f98bd21d8 100644 --- a/docs/config.yaml +++ b/docs/config.yaml @@ -19,7 +19,7 @@ params: author: The Gitea Authors website: https://docs.gitea.io version: 1.16.4 - minGoVersion: 1.17 + minGoVersion: 1.16 goVersion: 1.18 minNodeVersion: 12.17 diff --git a/go.mod b/go.mod index 2fc582fa786a..57234d70c298 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module code.gitea.io/gitea -go 1.17 +go 1.16 require ( cloud.google.com/go v0.99.0 // indirect diff --git a/modules/hostmatcher/hostmatcher.go b/modules/hostmatcher/hostmatcher.go index 6c5c2a74d98c..9492a479f107 100644 --- a/modules/hostmatcher/hostmatcher.go +++ b/modules/hostmatcher/hostmatcher.go @@ -8,6 +8,8 @@ import ( "net" "path/filepath" "strings" + + "code.gitea.io/gitea/modules/util" ) // HostMatchList is used to check if a host or IP is in a list. @@ -102,11 +104,11 @@ func (hl *HostMatchList) checkIP(ip net.IP) bool { for _, builtin := range hl.builtins { switch builtin { case MatchBuiltinExternal: - if ip.IsGlobalUnicast() && !ip.IsPrivate() { + if ip.IsGlobalUnicast() && !util.IsIPPrivate(ip) { return true } case MatchBuiltinPrivate: - if ip.IsPrivate() { + if util.IsIPPrivate(ip) { return true } case MatchBuiltinLoopback: diff --git a/modules/util/net.go b/modules/util/net.go new file mode 100644 index 000000000000..e4fbf393b431 --- /dev/null +++ b/modules/util/net.go @@ -0,0 +1,19 @@ +// Copyright 2021 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package util + +import ( + "net" +) + +// IsIPPrivate for net.IP.IsPrivate. +func IsIPPrivate(ip net.IP) bool { + if ip4 := ip.To4(); ip4 != nil { + return ip4[0] == 10 || + (ip4[0] == 172 && ip4[1]&0xf0 == 16) || + (ip4[0] == 192 && ip4[1] == 168) + } + return len(ip) == net.IPv6len && ip[0]&0xfe == 0xfc +}