Files
mesh/sync_validation.go
T
waozi 7a7983576d Close more server-side gaps from the security audit
- Credit a Monero invoice in the same transaction that claims it, so two
  settlements that see different transaction sets cannot both credit it.
- Add an optional signed manifest_sequence; a node and its mesh peers
  refuse an approved manifest older than the installed one, so a replayed
  approval cannot undo a suspension or key revocation.
- Keep revoked device key IDs revoked instead of reactivating them on
  registration.
- Take the rate-limit address from CF-Connecting-IP or the proxy's own
  X-Forwarded-For entry, never the client-chosen first entry, and key
  per-account challenge and login limits by account and address so
  strangers cannot lock an account out.
- Keep a signed sync transaction spent once its writes commit.
- Stop a paired peer widening its scope by omitting app, collection or
  space lists; cap mesh pull pages and peer response size.
- Bound metric labels by route pattern, cap request headers at 64 KiB,
  check subprotocol WebSocket tokens against deleted accounts, match app
  record prefixes case-sensitively, compare the app admin token in
  constant time, require a node key's public half to match its seed, and
  stop printing invalid secrets or raw database errors.
- Only render http and https peer links on the nodes page.
2026-10-13 02:22:05 -03:00

100 lines
3.1 KiB
Go

// Code generated by zi2go from sync_validation.zi. DO NOT EDIT.
package main
import slog "log/slog"
// #import std_go_types
// #import sync_types
func SyncValidation_Validate(database *Database, context Context, request SyncRequest) Error {
if request.AppID != "" {
var value_0 bool = Identity_ValidNamespace(request.AppID)
if !value_0 {
return StdErrorsGo_New("invalid app_id")
}
selected := AppStore_ByID(database, context, request.AppID)
if selected.Error != nil {
return selected.Error
}
if !selected.Found {
return StdErrorsGo_New("unknown app_id")
}
if selected.Value.Status != "active" {
return StdErrorsGo_New("app_id inactive")
}
var value_1 bool = request.ProtocolVersion >= int(6) && selected.Value.ManifestExpiresAt > 0
var value_2 bool = value_1
if value_2 {
var value_3 bool = StdTimeGo_Unix(StdTimeGo_Now()) > selected.Value.ManifestExpiresAt
value_2 = value_3
}
if value_2 {
return StdErrorsGo_New("app manifest expired")
}
if request.ProtocolVersion < int(6) {
legacy := AppStore_AllowsLegacyProtocol(database, context, request.AppID, request.ProtocolVersion)
if legacy.Error != nil {
return legacy.Error
}
if !legacy.Value {
return StdErrorsGo_New("legacy protocol not allowed for app_id")
}
}
}
if request.ProtocolVersion >= int(6) && request.AppID == "" {
return StdErrorsGo_New("app_id required")
}
requestApp := request.AppID
if requestApp == "" {
requestApp = "inbe"
}
{
value_4 := request.EncryptedRecords[:]
if int64(0) < 0 || int64(int64(len(value_4))) < int64(0) || int64(int64(len(value_4))) > int64(len(value_4)) {
panic("slice range out of bounds")
}
loop_view_34 := value_4[0:int64(len(value_4)):int64(len(value_4))]
loop_count_34 := int64(len(loop_view_34))
var loop_cursor_34 int64 = 0
for loop_cursor_34 < loop_count_34 {
loop_index_34 := loop_cursor_34
record := loop_view_34[loop_index_34]
var value_5 bool = EncryptedRecord_ValidForProtocol(record, request.ProtocolVersion)
if !value_5 {
return StdErrorsGo_New("invalid encrypted record")
}
if request.AppID != "" {
ownership := AppStore_OwnsCollection(database, context, request.AppID, record.Collection)
if ownership.Error != nil {
return ownership.Error
}
if !ownership.Value {
if request.ProtocolVersion >= int(6) {
return StdErrorsGo_New("encrypted record collection is not registered for app_id")
}
slog.Warn("sync request used unregistered app collection", "app_id", LogSafety_LogText(request.AppID), "collection", LogSafety_LogText(record.Collection), "mode", "compat")
}
}
owner := Scope_CollectionOwnerApp(record.Collection)
if owner != "" && owner != requestApp {
return StdErrorsGo_New("encrypted record collection belongs to another app")
}
loop_cursor_34++
}
}
return nil
}
var SyncValidation_ziranInitState uint8
func SyncValidation_ziranInit() {
if SyncValidation_ziranInitState == 2 {
return
}
if SyncValidation_ziranInitState == 1 {
panic("cyclic module startup")
}
SyncValidation_ziranInitState = 1
AppStore_ziranInit()
SyncValidation_ziranInitState = 2
}