guard

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package guard provides SQL injection prevention utilities for Quark ORM. It validates identifiers, operators, and raw queries against known-safe patterns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasPlaceholders

func HasPlaceholders(query string) bool

HasPlaceholders checks if a query string contains parameter placeholders.

Types

type Quoter

type Quoter interface {
	Quote(identifier string) string
}

Quoter is a minimal interface for quoting SQL identifiers. It avoids a circular import with the dialect package.

type SQLGuard

type SQLGuard struct {
	// contains filtered or unexported fields
}

SQLGuard provides security validations for SQL queries. It prevents SQL injection by validating identifiers and enforcing safe practices.

func New

func New() *SQLGuard

New creates a new SQLGuard with default settings.

func (*SQLGuard) QuoteIdentifier

func (g *SQLGuard) QuoteIdentifier(q Quoter, name string) (string, error)

QuoteIdentifier validates and quotes an identifier using the provided Quoter.

func (*SQLGuard) ValidateIdentifier

func (g *SQLGuard) ValidateIdentifier(name string) error

ValidateIdentifier checks if a table or column identifier is safe to use.

func (*SQLGuard) ValidateIdentifiers

func (g *SQLGuard) ValidateIdentifiers(names ...string) error

ValidateIdentifiers checks multiple identifiers at once.

func (*SQLGuard) ValidateOperator

func (g *SQLGuard) ValidateOperator(op string) error

ValidateOperator checks if an operator is in the allowed whitelist.

func (*SQLGuard) ValidateRawQuery

func (g *SQLGuard) ValidateRawQuery(query string, requirePlaceholders bool) error

ValidateRawQuery performs basic validation on a raw SQL query.

Jump to

Keyboard shortcuts

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