Skip to content

Comments

MSSQL (major): add query validation#929

Merged
vtalas merged 5 commits intodevfrom
copilot/apply-changes-to-mssql-connector
Jan 21, 2026
Merged

MSSQL (major): add query validation#929
vtalas merged 5 commits intodevfrom
copilot/apply-changes-to-mssql-connector

Conversation

Copy link
Contributor

Copilot AI commented Jan 16, 2026

The last part of https://github.com/Appmixer-ai/appmixer-components/issues/2509

Mirrors MySQL connector security changes from PR #928 by restricting MSSQL queries to read-only operations (SELECT/WITH) to prevent SQL injection.

Changes

  • Query validation: Added validateQuery() function that rejects non-SELECT/WITH queries using regex pattern /^\s*(select|with)\s/i
  • Integration: Validation occurs in runQuery() before query execution
  • Version bump: 1.0.3 → 2.0.0 (breaking change)
  • Test coverage: 12 unit tests covering valid queries (SELECT, WITH, case variations) and rejection of dangerous operations (INSERT, UPDATE, DELETE, DROP, ALTER, TRUNCATE, CREATE)

Implementation

function validateQuery(query) {
    if (!/^\s*(select|with)\s/i.test(query)) {
        throw new Error('Only SELECT or WITH queries are allowed');
    }
}

async function runQuery({ context, query, stream = false }) {
    validateQuery(query);  // Blocks dangerous queries
    const conn = await createConnection(context);
    // ... rest of query execution
}

Note: Multiple statement injection attempts (e.g., SELECT *; DROP TABLE) are already blocked by MSSQL driver defaults (multipleStatements: false).

Breaking Change

Queries containing INSERT, UPDATE, DELETE, DROP, ALTER, TRUNCATE, or CREATE statements will now throw errors. Applications requiring write operations must use dedicated components (CreateItem, UpdateItem, DeleteItem) rather than raw SQL.

Original prompt

Look at changes in #928 and apply them to MSSQL connector


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 16, 2026 14:11
Co-authored-by: jirihofman <12988096+jirihofman@users.noreply.github.com>
Co-authored-by: jirihofman <12988096+jirihofman@users.noreply.github.com>
Copilot AI changed the title [WIP] Apply updates from PR #928 to MSSQL connector Apply PR #928 security enhancements to MSSQL connector Jan 16, 2026
Copilot AI requested a review from jirihofman January 16, 2026 14:20
@jirihofman jirihofman marked this pull request as ready for review January 21, 2026 10:26
Copy link
Contributor

@jirihofman jirihofman left a comment

Choose a reason for hiding this comment

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

🆗

Before

Image

After

Image

@jirihofman jirihofman requested a review from vtalas January 21, 2026 10:27
@jirihofman
Copy link
Contributor

jirihofman commented Jan 21, 2026

Also updated icons to 2025 ones. This reduced connector size from 600kB to 40kB

image

Seen here

image

@vtalas vtalas changed the title Apply PR #928 security enhancements to MSSQL connector mssql: Apply PR #928 security enhancements to MSSQL connector (major) Jan 21, 2026
@jirihofman jirihofman changed the title mssql: Apply PR #928 security enhancements to MSSQL connector (major) MSSQL (major): add query validation Jan 21, 2026
@vtalas vtalas merged commit 6f463fc into dev Jan 21, 2026
1 check passed
@vtalas vtalas deleted the copilot/apply-changes-to-mssql-connector branch January 21, 2026 11:17
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.

4 participants