Skip to content

Commit 70f440d

Browse files
committed
server, packaging, docs: list the source addresses on the about page
1 parent 1551340 commit 70f440d

8 files changed

Lines changed: 48 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ number is written.
88
- An unreachable result says why the site did not answer.
99
- Sansec Shield's block page is named instead of a bare HTTP 403.
1010
- A block the result already names no longer also names the layer in front.
11+
- The about page lists the addresses checks come from, set by `source_addresses`, so owners can let the check through.
1112

1213
## v1.0.6 (2026-10-23)
1314

‎docs/deploy.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ that loads back unchanged. A file naming an unknown key is refused.
4545
"source_url": "https://github.com/pawal/php2shell",
4646
"contact": "abuse@evilbit.de",
4747
"trusted_proxy_cidrs": ["127.0.0.1/32", "::1/128"],
48+
"source_addresses": ["5.75.244.113", "2a01:4f8:c012:1000::1"],
4849
"rate_limit": { "enabled": true, "max": 10, "window": "1h" },
4950
"target_cooldown": "5m",
5051
"max_concurrent_checks": 10,
@@ -68,6 +69,9 @@ Notes on the keys:
6869
provided by". `source_url` is the source link of the footer and the about
6970
page. `contact`, when set, is offered on the about page for opt-out
7071
requests.
72+
- `source_addresses` lists the addresses checks leave from. The about page
73+
shows them so that site owners can let the check through a firewall. Each
74+
MUST be an IP address; empty shows none.
7175
- `trusted_proxy_cidrs` lists the peers whose forwarded client address and
7276
protocol are trusted. From any other peer those headers are stripped.
7377
Without the proxy in the list, the rate limit counts the proxy instead of

‎packaging/config/config.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"listen_addr": "127.0.0.1:8080",
33
"public_url": "https://php2shell.evilbit.de",
44
"trusted_proxy_cidrs": ["127.0.0.1/32", "::1/128"],
5+
"source_addresses": ["5.75.244.113", "2a01:4f8:c012:1000::1"],
56
"log_file": "/var/lib/php2shell/checks.log"
67
}

‎server/config.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ type Config struct {
6464
// Contact is shown on the about page for opt-out requests.
6565
Contact string `json:"contact,omitempty"`
6666
TrustedProxyCIDRs []string `json:"trusted_proxy_cidrs,omitempty"`
67+
SourceAddresses []string `json:"source_addresses,omitempty"` // shown on the about page
6768
RateLimit RateLimitConfig `json:"rate_limit"`
6869
TargetCooldown Duration `json:"target_cooldown"`
6970
MaxConcurrentChecks int `json:"max_concurrent_checks"`
@@ -141,6 +142,7 @@ var durationKeys = []key[Duration]{
141142

142143
var listKeys = []key[[]string]{
143144
{"trusted-proxy-cidrs", "TRUSTED_PROXY_CIDRS", "sources whose forwarded client address is honoured", func(c *Config) *[]string { return &c.TrustedProxyCIDRs }},
145+
{"source-addresses", "SOURCE_ADDRESSES", "addresses checks are sent from, shown on the about page", func(c *Config) *[]string { return &c.SourceAddresses }},
144146
}
145147

146148
// commaList binds a comma-separated value to a slice.
@@ -385,6 +387,11 @@ func (c Config) Validate() error {
385387
faults = append(faults, fmt.Errorf("trusted_proxy_cidrs: %q is not a prefix", cidr))
386388
}
387389
}
390+
for _, address := range c.SourceAddresses {
391+
if _, err := netip.ParseAddr(address); err != nil {
392+
faults = append(faults, fmt.Errorf("source_addresses: %q is not an address", address))
393+
}
394+
}
388395
return errors.Join(faults...)
389396
}
390397

‎server/config_test.go‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"io"
55
"os"
66
"path/filepath"
7+
"strings"
78
"testing"
89
"time"
910
)
@@ -47,3 +48,15 @@ func TestConfigRefusals(t *testing.T) {
4748
t.Error("a faulty configuration validated")
4849
}
4950
}
51+
52+
func TestSourceAddressesMustBeAddresses(t *testing.T) {
53+
cfg := DefaultConfig()
54+
cfg.SourceAddresses = []string{"192.0.2.10", "example.com"}
55+
if err := cfg.Validate(); err == nil || !strings.Contains(err.Error(), "source_addresses") {
56+
t.Errorf("a host name was accepted: %v", err)
57+
}
58+
cfg.SourceAddresses = []string{"192.0.2.10", "2001:db8::10"}
59+
if err := cfg.Validate(); err != nil {
60+
t.Error(err)
61+
}
62+
}

‎server/public/about.html‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ <h2>What is recorded</h2>
2323
<p>To have a site excluded or a record removed, write to <a href="mailto:{{.Contact}}">{{.Contact}}</a>.</p>
2424
{{- end}}
2525

26-
<h2>Recognising the check in your logs</h2>
27-
<p>Requests carry a <code>User-Agent</code> beginning with <code>php2shell-check</code> and a link to this page.</p>
26+
<h2>Recognising and allowing the check</h2>
27+
<p>Requests carry a <code>User-Agent</code> beginning with <code>php2shell-check</code> and a link to this page.
28+
{{- if .Sources}} They come from {{range $i, $a := .Sources}}{{if $i}} and {{end}}<code>{{$a}}</code>{{end}}.{{end}}</p>
29+
<p>Some firewalls and hosts refuse the check, and the result then says it was blocked or got no answer. To let it through, allow {{if .Sources}}these addresses{{else}}this User-Agent{{end}} while you check, or check on the server with the commands every result lists.</p>
2830

2931
<h2>Source</h2>
3032
<p>The service is free software under the BSD 2-Clause license. The source is at <a href="{{.SourceURL}}">{{.SourceURL}}</a>.</p>

‎server/server_test.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,19 @@ func TestLocalCheckFollowsServerHeader(t *testing.T) {
358358
}
359359
}
360360
}
361+
362+
func TestAboutListsSourceAddresses(t *testing.T) {
363+
about := func(addresses []string) string {
364+
h := newTestServer(t, func(c *Config) { c.SourceAddresses = addresses }, nil).Handler()
365+
rec := httptest.NewRecorder()
366+
h.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/about", nil))
367+
return rec.Body.String()
368+
}
369+
listed := about([]string{"192.0.2.10", "2001:db8::10"})
370+
if !strings.Contains(listed, "They come from <code>192.0.2.10</code> and <code>2001:db8::10</code>.") || !strings.Contains(listed, "allow these addresses") {
371+
t.Errorf("addresses missing from the about page")
372+
}
373+
if plain := about(nil); strings.Contains(plain, "They come from") || !strings.Contains(plain, "allow this User-Agent") {
374+
t.Errorf("the about page without addresses is wrong")
375+
}
376+
}

‎server/ui.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type page struct {
2626
ProviderURL string
2727
SourceURL string
2828
Contact string
29+
Sources []string
2930
StructuredData template.JS
3031
}
3132

@@ -48,6 +49,7 @@ func (s *Server) renderDocuments() (map[string][]byte, error) {
4849
data := page{
4950
Title: doc.title, Description: doc.description, Path: doc.path, Version: s.version,
5051
Provider: s.cfg.Provider, ProviderURL: s.cfg.ProviderURL, SourceURL: s.cfg.SourceURL, Contact: s.cfg.Contact,
52+
Sources: s.cfg.SourceAddresses,
5153
}
5254
if origin := s.cfg.Origin(); origin != "" {
5355
data.Origin = origin

0 commit comments

Comments
 (0)