Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# CHANGELOG

## v2.2.0 (24 September 2026)

### HTTPS inspection

- The Filters menu is now HTTPS inspection (Blocked keywords, Blocked content types, Sites not inspected), with a warning on each page when inspection is off
- The Block List page is removed; its entries are moved into every policy's blocked domains on upgrade

### Policies

- Policies, devices, and category feeds start with GateSentry rather than with the DNS server, so the proxy enforces a policy's blocked categories even when the DNS server is disabled
- Category lookups take constant time regardless of feed size (about 2µs per proxy decision with a million domains)

## v2.1.0 (24 September 2026)

### Policies page
Expand Down
5 changes: 5 additions & 0 deletions application/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ func DNSServerThread(baseDir string, logger *gatesentry2logger.Log, c <-chan int
}
}()

// Policies are enforced by the proxy as well as DNS, so the policy
// service, device store, and category feeds start even when the DNS
// listener is disabled.
gatesentryDnsServer.StartPolicyEnforcement(baseDir, blocklists, settings, devices, info)

for {
select {
case msg := <-c:
Expand Down
86 changes: 86 additions & 0 deletions application/dns/server/policy_blocklist_migration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package gatesentryDnsServer

import (
"os"
"path/filepath"
"reflect"
"testing"

gatesentryPolicy "bitbucket.org/abdullah_irfan/gatesentryf/policy"
)

func writeLegacyBlockList(t *testing.T, base, body string) string {
t.Helper()
path := filepath.Join(base, legacyBlockListFile)
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(path, []byte(body), 0o600); err != nil {
t.Fatal(err)
}
return path
}

func TestMigrateLegacyBlockListAddsEntriesToEveryPolicy(t *testing.T) {
svc, cleanup := setupTestPolicyServer(t)
defer cleanup()
if err := svc.CreateGroup(gatesentryPolicy.PolicyGroup{ID: "kids", Name: "Kids", BlockedDomains: []string{"tiktok.com"}}); err != nil {
t.Fatal(err)
}
if err := svc.Reload(); err != nil {
t.Fatal(err)
}
base := t.TempDir() + string(os.PathSeparator)
path := writeLegacyBlockList(t, base, `{"keywords":[{"Content":"snapads.com","Score":0},{"Content":"https://Bad.example/path","Score":0},{"Content":"tiktok.com","Score":0}]}`)

if err := migrateLegacyBlockList(svc, base); err != nil {
t.Fatal(err)
}
snap := svc.Snapshot()
if got, want := snap.Groups[gatesentryPolicy.DefaultGroupID].BlockedDomains, []string{"snapads.com", "bad.example", "tiktok.com"}; !reflect.DeepEqual(got, want) {
t.Fatalf("default blocked domains = %v, want %v", got, want)
}
if got, want := snap.Groups["kids"].BlockedDomains, []string{"tiktok.com", "snapads.com", "bad.example"}; !reflect.DeepEqual(got, want) {
t.Fatalf("kids blocked domains = %v, want %v", got, want)
}
raw, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
if string(raw) != `{"keywords":[]}` {
t.Fatalf("legacy block list after migration = %s, want it emptied", raw)
}

// A second start finds the list empty and changes nothing.
if err := migrateLegacyBlockList(svc, base); err != nil {
t.Fatal(err)
}
if got := svc.Snapshot().Groups["kids"].BlockedDomains; len(got) != 3 {
t.Fatalf("second migration changed kids blocked domains: %v", got)
}
}

func TestMigrateLegacyBlockListSkipsTheUneditedStockList(t *testing.T) {
svc, cleanup := setupTestPolicyServer(t)
defer cleanup()
base := t.TempDir() + string(os.PathSeparator)
path := writeLegacyBlockList(t, base, `{"keywords":[{"Content":"snapads.com","Score":0}]}`)

if err := migrateLegacyBlockList(svc, base); err != nil {
t.Fatal(err)
}
if got := svc.Snapshot().Groups[gatesentryPolicy.DefaultGroupID].BlockedDomains; len(got) != 0 {
t.Fatalf("stock list was copied into the default policy: %v", got)
}
if raw, _ := os.ReadFile(path); string(raw) != `{"keywords":[]}` {
t.Fatalf("stock list was not retired: %s", raw)
}
}

func TestMigrateLegacyBlockListWithoutFileIsANoop(t *testing.T) {
svc, cleanup := setupTestPolicyServer(t)
defer cleanup()
if err := migrateLegacyBlockList(svc, t.TempDir()+string(os.PathSeparator)); err != nil {
t.Fatal(err)
}
}
71 changes: 71 additions & 0 deletions application/dns/server/policy_migration.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package gatesentryDnsServer

import (
"encoding/json"
"errors"
"fmt"
"log"
"os"
"strings"

gatesentryPolicy "bitbucket.org/abdullah_irfan/gatesentryf/policy"
Expand Down Expand Up @@ -82,3 +85,71 @@ func migrateLegacyPolicy(svc *gatesentryPolicy.Service, settings *gatesentry2sto
}
return nil
}

// legacyBlockListFile is the retired gateway-wide Block List filter.
const legacyBlockListFile = "filterfiles/blockedsites.json"

// legacyBlockListStock is the entry every installation shipped with. A list
// holding only it was never edited, so it is retired without being copied into
// every policy.
const legacyBlockListStock = "snapads.com"

// migrateLegacyBlockList moves the retired Block List into policies. The list
// applied to every proxied request, so each existing policy, the default
// included, gains its entries as blocked domains; DNS then enforces them too.
// The file is emptied afterwards, which makes the migration safe to run on
// every start.
func migrateLegacyBlockList(svc *gatesentryPolicy.Service, basePath string) error {
if svc == nil {
return nil
}
path := basePath + legacyBlockListFile
raw, err := os.ReadFile(path)
if errors.Is(err, os.ErrNotExist) {
return nil
}
if err != nil {
return fmt.Errorf("read legacy block list: %w", err)
}
var file struct {
Keywords []struct {
Content string `json:"Content"`
} `json:"keywords"`
}
if err := json.Unmarshal(raw, &file); err != nil {
return fmt.Errorf("decode legacy block list: %w", err)
}
var domains []string
for _, entry := range file.Keywords {
pattern, err := gatesentryPolicy.NormalizeDomainPattern(entry.Content)
if err != nil {
log.Printf("[DNS] Legacy block list entry %q is not a domain; not migrated", entry.Content)
continue
}
if pattern != "" {
domains = append(domains, pattern)
}
}
if len(domains) == 1 && domains[0] == legacyBlockListStock {
domains = nil
}
if len(file.Keywords) == 0 {
return nil
}
if len(domains) > 0 {
for _, group := range svc.OrderedGroups() {
group.BlockedDomains = append(group.BlockedDomains, domains...)
if err := svc.UpdateGroup(group.ID, group); err != nil {
return fmt.Errorf("add legacy block list to policy %q: %w", group.ID, err)
}
}
if err := svc.Reload(); err != nil {
return fmt.Errorf("reload policy after block list migration: %w", err)
}
log.Printf("[DNS] Moved %d legacy block list entries into every policy's blocked domains", len(domains))
}
if err := os.WriteFile(path, []byte(`{"keywords":[]}`), 0o600); err != nil {
return fmt.Errorf("empty legacy block list: %w", err)
}
return nil
}
Loading
Loading