guard

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package guard refuses every MTProto request that is not on an exact read allowlist before it leaves the process.

The method name is the TL schema name from the gotd type (TypeName(), e.g. "messages.getHistory"). Wrapper requests (invokeWithLayer, initConnection, invokeWithoutUpdates) are checked by their inner query. The allowlist is the set of reads the CLI makes plus what gotd sends internally; a name prefix is never enough (payments.resolveStarGiftOffer is a "resolve" that moves money).

Index

Constants

View Source
const MethodSendMessage = "messages.sendMessage"

MethodSendMessage is the RPC a watcher reply is granted (see AllowOnce).

Variables

This section is empty.

Functions

func AllowOnce

func AllowOnce(ctx context.Context, method string) context.Context

AllowOnce returns a ctx under which exactly one request named method passes read-only mode. Other methods, later calls and always-denied methods stay blocked.

func Allowed

func Allowed(name string, authMode bool) bool

Allowed reports whether a method name may be called while read-only. Check also refuses allowed methods used with write-like arguments.

func AllowedMethods

func AllowedMethods(authMode bool) []string

AllowedMethods lists the read-only allowlist (sorted), for tests and docs.

func Check

func Check(req any, readOnly, authMode bool) error

Check returns a *BlockedError if req must not be sent.

func MethodName

func MethodName(req any) string

MethodName returns the TL name of a request, or "" if it has none.

func Middleware

func Middleware(readOnly func() bool, authMode bool) telegram.Middleware

Middleware is the gotd middleware; readOnly is evaluated per call.

Types

type BlockedError

type BlockedError struct {
	Method string
	Always bool
}

BlockedError is returned for a refused request.

func (*BlockedError) Error

func (e *BlockedError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL