You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "zhangshenghang (via GitHub)" <gi...@apache.org> on 2026/01/12 12:19:16 UTC

[PR] [Fix][Connector-v2][SQLServer] Handle database names with special characters in SQL queries and add related tests [seatunnel]

zhangshenghang opened a new pull request, #10327:
URL: https://github.com/apache/seatunnel/pull/10327

   …
   <!--
   
   Thank you for contributing to SeaTunnel! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   ## Contribution Checklist
     - Make sure that the pull request corresponds to a [GITHUB issue](https://github.com/apache/seatunnel/issues).
     - Name the pull request in the form "[Feature] [component] Title of the pull request", where *Feature* can be replaced by `Hotfix`, `Bug`, etc.
     - Minor fixes should be named following this pattern: `[hotfix] [docs] Fix typo in README.md doc`.
   -->
   
   ### Purpose of this pull request
   
   <!-- Describe the purpose of this pull request. For example: This pull request adds checkstyle plugin.-->
   
   
   ### Does this PR introduce _any_ user-facing change?
   
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released SeaTunnel versions or within the unreleased branches such as dev.
   If no, write 'No'.
   If you are adding/modifying connector documents, please follow our new specifications: https://github.com/apache/seatunnel/issues/4544.
   -->
   
   
   ### How was this patch tested?
   
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If you are adding E2E test cases, maybe refer to https://github.com/apache/seatunnel/blob/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-cdc-mysql-e2e/src/test/resources/mysqlcdc_to_mysql.conf, here is a good example.
   -->
   
   
   ### Check list
   
   * [ ] If any new Jar binary package adding in your PR, please add License Notice according
     [New License Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/contribution/new-license.md)
   * [ ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/seatunnel/tree/dev/docs
   * [ ] If necessary, please update `incompatible-changes.md` to describe the incompatibility caused by this PR.
   * [ ] If you are contributing the connector code, please check that the following files are updated:
     1. Update [plugin-mapping.properties](https://github.com/apache/seatunnel/blob/dev/plugin-mapping.properties) and add new connector information in it
     2. Update the pom file of [seatunnel-dist](https://github.com/apache/seatunnel/blob/dev/seatunnel-dist/pom.xml)
     3. Add ci label in [label-scope-conf](https://github.com/apache/seatunnel/blob/dev/.github/workflows/labeler/label-scope-conf.yml)
     4. Add e2e testcase in [seatunnel-e2e](https://github.com/apache/seatunnel/tree/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/)
     5. Update connector [plugin_config](https://github.com/apache/seatunnel/blob/dev/config/plugin_config)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix][Connector-v2][SQLServer] Handle database names with special characters in SQL queries and add related tests [seatunnel]

Posted by "aiai-bot (via GitHub)" <gi...@apache.org>.
aiai-bot commented on PR #10327:
URL: https://github.com/apache/seatunnel/pull/10327#issuecomment-3753370418

   <!-- code-pr-reviewer -->
   ## ⚠️ Request Changes
   
   **2 CRITICAL SQL injection vulnerabilities** and **1 MAJOR consistency issue** must be addressed before merging.
   
   ---
   
   ### 🔴 CRITICAL: SQL Injection Vulnerabilities
   
   **1. `getDatabaseWithConditionSql()` and `getTableWithConditionSql()` - Single quote injection**
   - **File**: `SqlServerCatalog.java:73-84`
   - **Evidence**:
     ```java
     // Line 74
     return String.format(getListDatabaseSql() + "  where name = '%s'", databaseName);
     // Lines 81-83
     "  and  TABLE_SCHEMA = '%s' and TABLE_NAME = '%s'", schemaName, tableName
     ```
   - **Fix**: Escape single quotes: `name.replace("'", "''")`
   
   **2. `getSelectColumnsSql()` - Single quote injection**
   - **File**: `SqlServerCatalog.java:98-106`
   - **Fix**: Apply `.replace("'", "''")` to both `schemaName` and `tableName`
   
   ---
   
   ### 🟠 MAJOR: Inconsistent Quoting
   
   **3. `getDropTableSql()` missing bracket quotes**
   - **File**: `SqlServerCatalog.java:141-143`
   - **Fix**:
     ```java
     return String.format("DROP TABLE %s", tablePath.getFullNameWithQuoted("[", "]"));
     ```
   
   ---
   
   ### Suggested Tests
   
   ```bash
   mvn test -Dtest=PreviewActionTest#testSqlServerPreviewAction
   mvn test -Dtest=SqlServerCDCIT#testDatabaseNameWithSpecialCharacters
   mvn test -Dtest=SqlServerCDCIT
   ```
   
   ---
   
   Please address the CRITICAL and MAJOR issues before merging.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix][Connector-v2][SQLServer] Handle database names with special characters in SQL queries and add related tests [seatunnel]

Posted by "zhangshenghang (via GitHub)" <gi...@apache.org>.
zhangshenghang commented on PR #10327:
URL: https://github.com/apache/seatunnel/pull/10327#issuecomment-3753933452

   <!-- code-pr-reviewer -->
   This PR attempts to add bracket quoting for special characters, but **multiple SQL injection vulnerabilities and functional defects remain**. The following BLOCKER issues must be fixed before merging:
   
   ## SQL Injection (Must Fix)
   
   ### `getDatabaseWithConditionSql()` - SQL Injection
   **Location:** `SqlServerCatalog.java:73-75`
   
   Directly interpolates `databaseName` into SQL WHERE clause using single quotes:
   ```java
   String.format(getListDatabaseSql() + "  where name = '%s'", databaseName)
   ```
   
   **Fix:** Use square brackets:
   ```java
   String.format(getListDatabaseSql() + "  where name = [%s]", databaseName)
   ```
   
   ---
   
   ### `getTableWithConditionSql()` - SQL Injection
   **Location:** `SqlServerCatalog.java:78-84`
   
   Interpolates schema and table names without escaping:
   ```java
   "TABLE_SCHEMA = '%s' and TABLE_NAME = '%s'"
   ```
   
   **Fix:** Escape single quotes or use square brackets for identifier quoting.
   
   ---
   
   ### `getSelectColumnsSql()` - SQL Injection
   **Location:** `SqlServerCatalog.java:99-106`
   
   Concatenates table name with single quotes:
   ```java
   "AND tbl.name = '" + tablePath.getTableName() + "'"
   ```
   
   **Fix:** Use square brackets:
   ```java
   "AND tbl.name = [" + tablePath.getTableName() + "]"
   ```
   
   ---
   
   ## Functional Defect (Must Fix)
   
   ### `getDropTableSql()` - Inconsistent Identifier Quoting
   **Location:** `SqlServerCatalog.java:141-143`
   
   Uses `tablePath.getFullName()` without quoting, while `getExistDataSql()` and `getTruncateTableSql()` correctly use `getFullNameWithQuoted("[", "]")` in the same file.
   
   **Fix:** Change to:
   ```java
   return String.format("DROP TABLE %s", tablePath.getFullNameWithQuoted("[", "]"));
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix][Connector-v2][SQLServer] Handle database names with special characters in SQL queries and add related tests [seatunnel]

Posted by "aiai-bot (via GitHub)" <gi...@apache.org>.
aiai-bot commented on PR #10327:
URL: https://github.com/apache/seatunnel/pull/10327#issuecomment-3753765499

   <!-- code-pr-reviewer -->
   ## 🔴 Blocking Issues Found
   
   ### **1. CRITICAL - SQL Injection in `getDatabaseWithConditionSql()`**
   
   `SqlServerCatalog.java:73-75`
   
   ```java
   return String.format(getListDatabaseSql() + "  where name = '%s'", databaseName);
   ```
   
   **Impact**: Database names containing single quotes (e.g., `O'Reilly`) will cause SQL syntax errors. This is called by `AbstractJdbcCatalog.databaseExists()`, making it exploitable in production.
   
   **Fix**: Use bracket quoting (consistent with `getListTableSql()`):
   ```java
   return String.format(getListDatabaseSql() + "  where name = [%s]", databaseName);
   ```
   
   ---
   
   ### **2. MAJOR - SQL Injection in `getTableWithConditionSql()`**
   
   `SqlServerCatalog.java:78-84`
   
   ```java
   + "  and  TABLE_SCHEMA = '%s' and TABLE_NAME = '%s'"
   ```
   
   While `databaseName` is escaped via `getListTableSql()`, `schemaName` and `tableName` are concatenated with single quotes. Schema or table names with single quotes (e.g., `dbo'`, `my'table`) will break queries.
   
   **Fix**: Escape with brackets:
   ```java
   + "  and  TABLE_SCHEMA = [%s] and TABLE_NAME = [%s]"
   ```
   
   ---
   
   ### **3. MAJOR - Inconsistency: `getDropTableSql()` Missing Brackets**
   
   `SqlServerCatalog.java:141-143`
   
   Uses `tablePath.getFullName()` (no quotes), while `getExistDataSql()`:174 and `getTruncateTableSql()`:179 use `getFullNameWithQuoted("[", "]")`. Tables with special characters can be created/truncated but NOT dropped.
   
   **Fix**:
   ```java
   return String.format("DROP TABLE %s", tablePath.getFullNameWithQuoted("[", "]"));
   ```
   
   Also update test expectation at `PreviewActionTest.java:366`.
   
   ---
   
   ### **4. MAJOR - Test Expects Wrong Behavior**
   
   `PreviewActionTest.java:363-367`
   
   DROP_TABLE expects `"DROP TABLE testddatabase.testtable"` (no brackets), but CREATE_DATABASE expects `"CREATE DATABASE [testddatabase]"` (with brackets). This test doesn't validate special character handling and will block the correct fix.
   
   **Fix**: Update expectation:
   ```java
   assertPreviewResult(catalog, Catalog.ActionType.DROP_TABLE, 
       "DROP TABLE [testddatabase].[testtable]", Optional.empty());
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix][Connector-v2][SQLServer] Handle database names with special characters in SQL queries and add related tests [seatunnel]

Posted by "zhangshenghang (via GitHub)" <gi...@apache.org>.
zhangshenghang commented on PR #10327:
URL: https://github.com/apache/seatunnel/pull/10327#issuecomment-3754095938

   <!-- code-pr-reviewer -->
   This PR moves in the right direction by adding square-bracket quoting for SQL Server database names, but there are **2 CRITICAL security issues** and **2 MAJOR correctness issues** that should be addressed before merge.
   
   ## CRITICAL - Must Fix
   
   ### 1. SQL Injection in `getDatabaseWithConditionSql()` - SqlServerCatalog.java:73-75
   
   The method uses single-quoted string concatenation instead of square brackets:
   ```java
   return String.format(getListDatabaseSql() + "  where name = '%s'", databaseName);
   ```
   
   **Problem**: When `databaseName` contains special characters (e.g., `test-db-name` or `test'db`), this causes SQL syntax errors or SQL injection. This directly contradicts the PR's goal of supporting special characters.
   
   **Impact**: Affects `databaseExists()` checks in `AbstractJdbcCatalog:352`. All operations depending on this check (dropDatabaseInternal, createTable, dropTable) may fail. Attackers could bypass existence checks using malicious names like `test' OR '1'='1`.
   
   **Fix**: Use `where name = [%s]` to match other methods in the same class (getListTableSql:93-95, getCreateDatabaseSql:147, getDropDatabaseSql:152).
   
   ---
   
   ### 2. SQL Injection in `getTableWithConditionSql()` - SqlServerCatalog.java:78-84
   
   The method directly concatenates schemaName and tableName without escaping:
   ```java
   TABLE_SCHEMA = '%s' and TABLE_NAME = '%s'
   ```
   
   **Problem**: Uses single quotes instead of square brackets. Inconsistent with the databaseName quoting strategy fixed in this PR.
   
   **Impact**: Affects `tableExists()` checks in `AbstractJdbcCatalog:422`. All operations depending on this check (getTable, createTable, dropTable, open) are vulnerable to SQL injection. Schema names with special characters (e.g., `my-schema`) cause runtime errors.
   
   **Fix**: Change to `TABLE_SCHEMA = '[%s]'and TABLE_NAME = '[%s]'` for consistency.
   
   ---
   
   ## MAJOR - Strongly Recommended
   
   ### 3. Missing Square Brackets in `getDropTableSql()` - SqlServerCatalog.java:141-143
   
   Uses `tablePath.getFullName()` without quoting, while other methods (`getExistDataSql:174`, `getTruncateTableSql:179`) use `getFullNameWithQuoted("[", "]")`.
   
   **Impact**: Tables/schemas with special characters cannot be dropped. Inconsistent quoting strategy within the same class creates confusion and maintenance burden.
   
   **Fix**: Change to `tablePath.getFullNameWithQuoted("[", "]")` and update `PreviewActionTest` assertions.
   
   ---
   
   ### 4. Asymmetric Fix - Schema/Table Special Characters Not Supported
   
   The PR only adds square brackets for databaseName, but schemaName and tableName remain unquoted in `getTableWithConditionSql`. The E2E test uses a fixed `dbo` schema without special characters.
   
   **Impact**: Production environments using custom schema names (e.g., `app-v2`) will encounter runtime errors. Incomplete implementation relative to PR title.
   
   **Fix**: Apply consistent quoting strategy to all identifiers, or document current limitations.
   
   ---
   
   ## Recommendation
   
   Please address the 2 CRITICAL security issues before merging to complete the SQL injection prevention coverage. The MAJOR issues can be tracked as follow-ups but would ideally be fixed together for consistency.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix][Connector-v2][SQLServer] Handle database names with special characters in SQL queries and add related tests [seatunnel]

Posted by "aiai-bot (via GitHub)" <gi...@apache.org>.
aiai-bot commented on PR #10327:
URL: https://github.com/apache/seatunnel/pull/10327#issuecomment-3753631750

   <!-- code-pr-reviewer -->
   This PR adds support for database names with special characters in SQL Server CDC, but **critical SQL injection vulnerabilities must be addressed** before merging.
   
   ## Blocking Issues
   
   ### 1. SQL Injection in `getDatabaseWithConditionSql()` - CRITICAL
   **File**: `SqlServerCatalog.java:73-75`
   
   The method uses single quotes around the database name without escaping:
   ```java
   return String.format(getListDatabaseSql() + " where name = '%s'", databaseName);
   ```
   
   When the database name contains a single quote (e.g., `test'db` or `test' OR '1'='1`), it results in SQL injection, allowing attackers to bypass checks or execute arbitrary SQL.
   
   **Fix**: Escape single quotes: `databaseName.replace("'", "''")` or use `QUOTENAME()`.
   
   ---
   
   ### 2. Bracket Escaping Incomplete - `]` Character Not Handled - CRITICAL
   **File**: `SqlServerCatalog.java:93-95`, `SqlServerCreateTableSqlBuilder.java:156,168`
   
   Database names are wrapped with brackets `[databaseName]`, but internal `]` characters are not escaped to `]]`.
   
   A database name containing `]` (e.g., `test]db`) generates invalid SQL like `[test]db]`, causing syntax errors. Worse, names like `test]; DROP TABLE users--` enable SQL injection.
   
   **Fix**: Escape `]` to `]]` using `databaseName.replace("]", "]]")` or `QUOTENAME()`. As a short-term fix, validate and reject database names containing `]` in `SqlServerSourceConfigFactory`.
   
   ---
   
   ### 3. Schema/Table Names Not Escaped in `getTableWithConditionSql()` - MAJOR
   **File**: `SqlServerCatalog.java:78-84`
   
   Schema and table names are wrapped with single quotes without escaping:
   ```java
   TABLE_SCHEMA = '%s' and TABLE_NAME = '%s'
   ```
   
   Schema or table names containing single quotes lead to SQL injection.
   
   **Fix**: Escape single quotes for both schema and table names.
   
   ---
   
   ### 4. JDBC URL Parameters Not Encoded - MAJOR
   **File**: `SqlServerCatalog.java:162-164`
   
   `getUrlFromDatabaseName()` directly concatenates the database name into the JDBC URL parameter without URL encoding.
   
   Database names containing URL special characters (`;`, `&`, `=`) cause connection failures.
   
   **Fix**: Verify if SQL Server JDBC driver requires URL encoding for the `databaseName` parameter. If so, use `URLEncoder.encode()`.
   
   ---
   
   ## Strong Recommendations
   
   ### 5. Missing Unit Tests for SQL Generation - MEDIUM
   **File**: `SqlServerCatalog.java` (lines 92-153)
   
   No unit tests for `getListTableSql()`, `getCreateDatabaseSql()`, `getDropDatabaseSql()`, etc. to verify special character handling.
   
   **Fix**: Add `SqlServerCatalogSqlBuilderTest.java` with tests for various special characters (hyphen, space, dot, brackets, quotes, semicolon, Unicode).
   
   ### 6. Missing JDBC Sink Test - MEDIUM
   **File**: `SqlServerCreateTableSqlBuilder.java` (lines 155-173)
   
   No test verifies `CREATE TABLE` statements when database names contain special characters.
   
   **Fix**: Add `testCreateTableWithDatabaseNameWithHyphen()` verifying correct bracket wrapping in generated SQL.
   
   ### 7. Missing Catalog API Integration Tests - MEDIUM
   **File**: `AbstractJdbcCatalog.java` (lines 347-364)
   
   No tests for direct Catalog API operations (`createDatabase()`, `dropDatabase()`, `listTables()`, `tableExists()`) with special character database names.
   
   **Fix**: Add `testCatalogOperationsWithSpecialCharacters()` to `SqlServerCDCIT.java`.
   
   ### 8. Missing Documentation - MEDIUM
   
   No documentation explaining special character support and the `]` character limitation.
   
   **Fix**: Update `docs/en/connector-v2/source/SqlServer-CDC.md` with examples of valid/invalid database names.
   
   ---
   
   ## Minor Issues
   
   - Test only covers hyphens, not spaces or other special characters
   - `PreviewActionTest` updates incomplete; `TRUNCATE_TABLE`/`DROP_TABLE` methods not tested with special characters
   - Inconsistent escaping strategy (some brackets, some quotes)
   - No input validation beyond `isBlank()` check
   - No negative SQL injection tests
   - No backward compatibility check (though SQL Server bracket syntax has long-standing support)
   
   ---
   
   ## Verification Checklist
   
   - Construct database name `test']; DROP TABLE--` and confirm query throws exception
   - Verify `databaseExists()` returns correct result for `test-db-name`
   - Verify JDBC connection succeeds with `test-db-name`
   - Verify table creation and metadata queries work in special-character databases
   - Confirm backward compatibility with normal database names
   - Verify `getColumn()` method safety
   - Run full CDC Source → JDBC Sink E2E test
   - Test all Catalog API operations
   
   This PR addresses a real problem but requires security fixes before merging.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix][Connector-v2][SQLServer] Handle database names with special characters in SQL queries and add related tests [seatunnel]

Posted by "corgy-w (via GitHub)" <gi...@apache.org>.
corgy-w merged PR #10327:
URL: https://github.com/apache/seatunnel/pull/10327


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org