Skip to content

Add gosec + correctness linters to golangci-lint - #16

Merged
KARTIKrocks merged 1 commit into
mainfrom
chore/security-linters
Jul 8, 2026
Merged

KARTIKrocks merged 1 commit into
mainfrom
chore/security-linters

Conversation

@KARTIKrocks

@KARTIKrocks KARTIKrocks commented Jul 8, 2026 •

Copy link
Copy Markdown
Owner

Enable a stronger linter set befitting a security-adjacent tool: gosec (SAST), errorlint, bodyclose, nilerr, unconvert, usestdlibvars.

Annotate the deliberate patterns gosec/nilerr flag, each with a scoped //nolint and a justification rather than a blanket disable:

  • explain: EXPLAIN string concatenation (G202) — no bind params exist; the defense is validate() + the rolled-back read-only tx.
  • config.Load: reading the .sqlguard.yml path the caller pointed at (G304).
  • pg/mysql parsers: return the best-effort fallback Statement (not an error) on parse failure, by contract (nilerr).
  • scanner: skip an unparseable Go file and keep walking (nilerr).

Exclude gosec from _test.go (lax fixture perms / ignored setup errors), mirroring the existing errcheck exclusion. gosec G115 is excluded globally (noisy on deliberate range-checked int conversions).

Summary

What does this PR change, and why?

Closes #

Type of change

  • Bug fix
  • New detection rule
  • New integration / parser
  • Feature / enhancement
  • Docs only
  • Refactor / chore

Checklist

  • make ci passes (fmt-check, vet, lint, test-race) across all modules
  • Added/updated tests (and, where practical, a failure-mode check)
  • Updated docs as needed (README.md, CLAUDE.md, .sqlguard.example.yml)
  • Added an entry under ## [Unreleased] in CHANGELOG.md
  • No new third-party deps in analyzer / middleware / reporter
  • Findings stay redaction-safe (no raw literals leak into a Result)

Notes for reviewers

Anything reviewers should focus on — tricky areas, trade-offs, follow-ups.

Summary by CodeRabbit

  • Chores
    • Expanded linting and security checks to catch more correctness, error-handling, and security issues during development.
    • Refined lint rules and exclusions so tests and examples are handled more appropriately.
    • Added clearer guidance around cases where invalid SQL or unparsable files are skipped instead of stopping scans.

Enable a stronger linter set befitting a security-adjacent tool:
gosec (SAST), errorlint, bodyclose, nilerr, unconvert, usestdlibvars.

Annotate the deliberate patterns gosec/nilerr flag, each with a scoped
//nolint and a justification rather than a blanket disable:
- explain: EXPLAIN string concatenation (G202) — no bind params exist;
  the defense is validate() + the rolled-back read-only tx.
- config.Load: reading the .sqlguard.yml path the caller pointed at (G304).
- pg/mysql parsers: return the best-effort fallback Statement (not an
  error) on parse failure, by contract (nilerr).
- scanner: skip an unparseable Go file and keep walking (nilerr).

Exclude gosec from _test.go (lax fixture perms / ignored setup errors),
mirroring the existing errcheck exclusion. gosec G115 is excluded
globally (noisy on deliberate range-checked int conversions).
@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@KARTIKrocks, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 57 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 2a522d76-8cb2-40db-a186-87b94458fe1b

📥 Commits

Reviewing files that changed from the base of the PR and between b29c907 and 4c3da20.

📒 Files selected for processing (6)
  • .golangci.yml
  • cmd/sqlguard/scan.go
  • config/config.go
  • explain/explain.go
  • parsers/mysqlparser/mysqlparser.go
  • parsers/pgparser/pgparser.go

Walkthrough

This PR expands .golangci.yml with additional security and correctness linters (gosec, errorlint, bodyclose, nilerr, unconvert, usestdlibvars), tunes linter settings, and broadens test-path exclusions. It adds //nolint directives with explanatory comments to existing intentional patterns in scan, config, explain, and parser code, without changing logic.

Changes

Lint hardening and suppressions

Layer / File(s) Summary
Linter configuration updates
.golangci.yml
Enables gosec and related linters, sets gocyclo/revive/gosec options, excludes G115, and extends test-path exclusions to cover both errcheck and gosec.
Parser fallback nolint annotations
parsers/mysqlparser/mysqlparser.go, parsers/pgparser/pgparser.go
Adds //nolint:nilerr and expanded comments documenting non-fatal parse-failure fallback behavior; no logic change.
Scan skip-on-parse-error annotation
cmd/sqlguard/scan.go
Adds //nolint:nilerr and comment explaining unparseable files are skipped during AST scan.
EXPLAIN and config path gosec suppressions
explain/explain.go, config/config.go
Adds //nolint:gosec suppressions (G202, G304) with comments explaining safety guarantees from validate() and read-only transactions, and the caller-provided config path intent.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Poem

A rabbit hops through lint rules tight,
Sprinkling nolint comments left and right 🐰
Gosec, nilerr, all in a row,
Explaining why the concat's okay to go.
No logic bent, just clarity's light.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: enabling gosec and related correctness linters in golangci-lint.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/security-linters

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@KARTIKrocks

Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 59 minutes.

@KARTIKrocks
KARTIKrocks merged commit 361e007 into main Jul 8, 2026
7 checks passed
@KARTIKrocks
KARTIKrocks deleted the chore/security-linters branch July 8, 2026 16:51
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