Overview
This guide covers best practices for developing secure, performant, and maintainable QueryBox plugins.Security
Never Log Credentials
Avoid logging connection parameters or credentials:Sanitize Query Parameters
When constructing queries from user input, use parameterized queries:Validate Connection Parameters
Reject obviously invalid inputs early:Use TLS by Default
Enable encrypted connections when possible:Avoid Hardcoded Secrets
Never embed API keys or credentials in plugin code:Limit Resource Access
Restrict file system access when usingFILE_PATH fields:
Error Handling
Return Errors in Response, Not as Go Errors
Frompkg/plugin/plugin.go:137-220, the CLI protocol expects all results on stdout:
Provide Helpful Error Messages
Include actionable information:Close Resources Properly
Always usedefer to close connections:
Performance
Respect Context Deadlines
Fromdocs/features/02-plugin-system.md:14-21, commands have timeouts:
| Command | Timeout |
|---|---|
info | 2s |
exec | 30s |
authforms | 30s |
connection-tree | 30s |
test-connection | 15s |
Limit Result Set Size
Prevent memory exhaustion from large queries:Reuse Connection Pools
For plugins that maintain state (not recommended for the current stateless model), reuse connections:Avoid Expensive Operations in Info
Theinfo command has a 2-second timeout and is called frequently:
Code Quality
Use the Unimplemented Server Stub
Embed the generated stub for forward compatibility:Implement All Core Methods
Fromdocs/features/02-plugin-system.md:14-21, required and optional methods:
Required:
Info- Plugin metadataExec- Query executionAuthForms- Connection form definitions
ConnectionTree- Database browsingTestConnection- Connection validation
TestConnection to improve UX:
Handle Empty Results Gracefully
Always return empty collections, nevernil:
Support Explain Query Capability
For SQL plugins, implement theexplain-query capability: