Skip to content

Make clause security check pluggable#1442

Merged
qqxhb merged 1 commit intomasterfrom
fix/issue-982-clause-checker
Feb 28, 2026
Merged

Make clause security check pluggable#1442
qqxhb merged 1 commit intomasterfrom
fix/issue-982-clause-checker

Conversation

@qqxhb
Copy link
Member

@qqxhb qqxhb commented Feb 28, 2026

Summary

  • add ClauseChecker hook with ErrClauseNotHandled fallback behavior
  • centralize clause validation with optional custom checker
  • add tests for custom checker behavior

Tests

  • go test ./...

@propel-code-bot
Copy link

This PR introduces a configurable clause security checker integrated into DO clause validation, with a new option to plug in custom handling that can delegate back to the default checker when needed.

Affected Areas

do_options.go
sec_check.go
do.go
do_clause_checker_test.go

This summary was automatically generated by @propel-code-bot

// Clauses specify Clauses
func (d *DO) Clauses(conds ...clause.Expression) Dao {
if err := checkConds(conds); err != nil {
if err := checkCondsWithChecker(conds, d.ClauseChecker); err != nil {

Choose a reason for hiding this comment

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

Important

[Logic] Calling d.ClauseChecker will panic if DOConfig was never initialized (e.g., Table(...) returns a *DO without calling UseDB). That makes Clauses() unsafe on those instances. Guard against a nil DOConfig and pass a nil checker to fall back to CheckClause.

Suggested change
if err := checkCondsWithChecker(conds, d.ClauseChecker); err != nil {
var checker ClauseChecker
if d.DOConfig != nil {
checker = d.ClauseChecker
}
if err := checkCondsWithChecker(conds, checker); err != nil {
Context for Agents
Calling `d.ClauseChecker` will panic if `DOConfig` was never initialized (e.g., `Table(...)` returns a `*DO` without calling `UseDB`). That makes `Clauses()` unsafe on those instances. Guard against a nil `DOConfig` and pass a nil checker to fall back to `CheckClause`.

```suggestion
	var checker ClauseChecker
	if d.DOConfig != nil {
		checker = d.ClauseChecker
	}
	if err := checkCondsWithChecker(conds, checker); err != nil {
```

File: do.go
Line: 175

@qqxhb qqxhb merged commit 0fee043 into master Feb 28, 2026
15 checks passed
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.

1 participant