Skip to content

Prevent SQL injection when passing Sort#34

Merged
klaidliadon merged 4 commits intomasterfrom
sort-sql-injection
Jan 28, 2026
Merged

Prevent SQL injection when passing Sort#34
klaidliadon merged 4 commits intomasterfrom
sort-sql-injection

Conversation

@klaidliadon
Copy link
Contributor

@klaidliadon klaidliadon commented Jan 27, 2026

package main

import (
	"fmt"

	sq "github.com/Masterminds/squirrel"
	"github.com/goware/pgkit/v2"
)

func main() {
	page := pgkit.Page{
		Sort: []pgkit.Sort{
			{Column: "ID; DROP TABLE users;", Order: pgkit.Asc},
		}
	}
	_, q := pgkit.NewPaginator[T]().PrepareQuery(sq.Select("*").From("t"), page)
	sql, _, _ := q.ToSql()

	fmt.Println(sql)
}

Produces:

SELECT * FROM t ORDER BY ID; DROP TABLE users; ASC

Copy link
Member

@VojtechVitek VojtechVitek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@klaidliadon klaidliadon merged commit 2638db4 into master Jan 28, 2026
1 check passed
@klaidliadon klaidliadon deleted the sort-sql-injection branch January 28, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants