share: remove the allowShare guard
We have determined that since x/website prevents /_/share traffic from
being served for golang.google.cn, we no longer need to guard sharing in
x/playground based on X-AppEngine-Country.
Fixes golang/go#65081
Change-Id: Iba078d38bc39fe4c532cb6a78c082559f344b6e2
Reviewed-on: https://go-review.googlesource.com/c/playground/+/556315
Run-TryBot: Robert Findley <rfindley@google.com>
Commit-Queue: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/edit.go b/edit.go
index 9cb49c9..4e00d1e 100644
--- a/edit.go
+++ b/edit.go
@@ -20,7 +20,6 @@
type editData struct {
Snippet *snippet
- Share bool
Analytics bool
GoVersion string
Gotip bool
@@ -48,11 +47,6 @@
snip := &snippet{Body: []byte(s.examples.hello())}
if strings.HasPrefix(r.URL.Path, "/p/") {
- if !allowShare(r) {
- w.WriteHeader(http.StatusUnavailableForLegalReasons)
- w.Write([]byte(`<h1>Unavailable For Legal Reasons</h1><p>Viewing and/or sharing code snippets is not available in your country for legal reasons. This message might also appear if your country is misdetected. If you believe this is an error, please <a href="https://golang.org/issue">file an issue</a>.</p>`))
- return
- }
id := r.URL.Path[3:]
serveText := false
if strings.HasSuffix(id, ".go") {
@@ -88,7 +82,6 @@
w.Header().Set("Content-Type", "text/html; charset=utf-8")
data := &editData{
Snippet: snip,
- Share: allowShare(r),
GoVersion: runtime.Version(),
Gotip: s.gotip,
Examples: s.examples.examples,
diff --git a/edit.html b/edit.html
index 1045005..422d1f4 100644
--- a/edit.html
+++ b/edit.html
@@ -25,10 +25,8 @@
'runEl': '#run, #embedRun',
'fmtEl': '#fmt',
'fmtImportEl': '#imports',
- {{if $.Share}}
'shareEl': '#share',
'shareURLEl': '#shareURL',
- {{end}}
'enableHistory': true,
'enableShortcuts': true,
'enableVet': true,
@@ -36,9 +34,7 @@
});
playgroundEmbed({
'codeEl': '#code',
- {{if $.Share}}
'shareEl': '#share',
- {{end}}
'embedEl': '#embed',
'embedLabelEl': '#embedLabel',
'embedHTMLEl': '#shareURL'
@@ -112,14 +108,12 @@
Imports
</label>
</div>
- {{if $.Share}}
<input type="button" value="Share" id="share">
<input type="text" id="shareURL">
<label id="embedLabel">
<input type="checkbox" id="embed">
embed
</label>
- {{end}}
<select class="js-playgroundToysEl">
{{range .Examples}}
<option value="{{.Path}}">{{.Title}}</option>
diff --git a/share.go b/share.go
index ef7a6d6..528f86d 100644
--- a/share.go
+++ b/share.go
@@ -11,7 +11,6 @@
"fmt"
"io"
"net/http"
- "strings"
)
const (
@@ -53,11 +52,6 @@
http.Error(w, "Requires POST", http.StatusMethodNotAllowed)
return
}
- if !allowShare(r) {
- http.Error(w, "Either this isn't available in your country due to legal reasons, or our IP geolocation is wrong.",
- http.StatusUnavailableForLegalReasons)
- return
- }
var body bytes.Buffer
_, err := io.Copy(&body, io.LimitReader(r.Body, maxSnippetSize+1))
@@ -82,37 +76,3 @@
fmt.Fprint(w, id)
}
-
-// golang/go#65081: the IP prefixes below have been observed in proxied traffic
-// from go.dev to play.golang.org, and as of 2024-01-16 are incorrectly
-// identified as CN by X-AppEngine-Country. Using geoIP tooling, these were all
-// verified as having temporarily been categorized as CN in early January, but
-// are currently US.
-//
-// While this is being investigated, hard-code a temporary allow list for these
-// IPs to get the playground working again.
-//
-// Per https://www.gstatic.com/ipranges/goog.json, these are Google IPs.
-var temporaryAllowListIPPrefixes = []string{
- "2600:1900:2001:2",
- "2600:1900:2001:3",
- "2600:1900:2000:1b",
- "2600:1900:2000:1d",
- "2600:1900:2000:38",
- "2600:1900:2000:37",
- "2600:1900:2000:9",
-}
-
-func allowShare(r *http.Request) bool {
- if r.Header.Get("X-AppEngine-Country") != "CN" {
- return true
- }
- for _, forward := range strings.Split(r.Header.Get("X-Forwarded-For"), ",") {
- for _, prefix := range temporaryAllowListIPPrefixes {
- if strings.HasPrefix(strings.TrimSpace(forward), prefix) {
- return true
- }
- }
- }
- return false
-}