You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "FANNG1 (via GitHub)" <gi...@apache.org> on 2026/06/26 02:48:20 UTC

[I] [Improvement] sec(catalog-jdbc): ExternalType.catalogString() is written verbatim into DDL SQL without validation [gravitino]

FANNG1 opened a new issue, #11805:
URL: https://github.com/apache/gravitino/issues/11805

   ## What would you like to be improved?
   
   In `MysqlTypeConverter`, `PostgreSqlTypeConverter`, and `DorisTypeConverter` (added in #11763), `fromGravitino(ExternalType)` returns `type.catalogString()` directly. This string is then inserted verbatim into `CREATE TABLE` / `ALTER TABLE` SQL in the corresponding `TableOperations` class (e.g. `DorisTableOperations:630`, `:744`, `MysqlTableOperations`, `PostgreSqlTableOperations`).
   
   There is no validation that `catalogString()` is a well-formed, single-token type name. An authenticated API caller who stores an `ExternalType` with a malformed or multi-statement string (e.g. `ExternalType.of("json; DROP TABLE foo")`) would have that string embedded directly into the generated DDL.
   
   **Affected files:**
   - `catalog-jdbc-mysql`: `MysqlTypeConverter.fromGravitino`
   - `catalog-jdbc-postgresql`: `PostgreSqlTypeConverter.fromGravitino`
   - `catalog-jdbc-doris`: `DorisTypeConverter.fromGravitino`
   
   ## How should we improve?
   
   Add a shared validation helper in `JdbcTypeConverter` (or override the base `fromGravitino` contract) that rejects `catalogString()` values containing SQL metacharacters (e.g. semicolons, quotes, comment markers) before they reach DDL construction.
   
   Alternatively, maintain a per-catalog allowlist of known valid external type names and reject anything not on the list.
   
   This can be done as a follow-up hardening task independent of any specific connector PR.


-- 
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@gravitino.apache.org.apache.org

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


Re: [I] [Improvement]: ExternalType.catalogString() is written verbatim into DDL SQL without validation in JDBC catalog [gravitino]

Posted by "sachinnn99 (via GitHub)" <gi...@apache.org>.
sachinnn99 commented on issue #11805:
URL: https://github.com/apache/gravitino/issues/11805#issuecomment-5640646282

   Thanks @FANNG1, this is really helpful — especially the point about comma-separated actions. I confirmed it in the builders: `MysqlTableOperations.generateAlterTableSql:410` and `DorisTableOperations.generateAlterTableSql:810` both do `"ALTER TABLE \`t\`\n" + String.join(",\n", alterSql) + ";"`, and `PostgreSqlTableOperations:604-614` appends `,\nALTER COLUMN ... SET NOT NULL` right after the type. So a top-level comma does inject an extra action into the same statement, and a `;`-only blocklist would miss it. Agreed on validating in `fromGravitino` and on not trying to prove the type is legal.
   
   Two cases where I think the character set needs to be slightly wider than `[\w .,:()<>\[\]]`:
   
   **1. `-` — the set as written would fail two existing tests.**
   
   `TestMysqlTypeConverter.java:101` and `TestPostgreSqlTypeConverter.java:124` both assert:
   
   ```java
   checkGravitinoTypeToJdbcType(USER_DEFINED_TYPE, Types.ExternalType.of(USER_DEFINED_TYPE));
   // USER_DEFINED_TYPE = "user-defined"
   ```
   
   Since `-` isn't in the set, `fromGravitino(ExternalType.of("user-defined"))` would throw and both tests would start failing.
   
   Suggestion: keep `-` in the set, but reject the two-character sequence `--` separately. `--` is what actually opens a line comment; a lone hyphen can't. `/* */` and `#` need no special case, since `/`, `*` and `#` are already outside the set.
   
   **2. `=` — needed for ClickHouse `Enum8`/`Enum16`.**
   
   `Enum8('active'=1,'inactive'=2)` is stored as an `ExternalType` today (`TestClickHouseTypeConverter.java:108-110`, `CatalogClickHouseIT.java:2934`). ClickHouse is out of scope for this PR, but since the helper lands in the shared `JdbcTypeConverter`, leaving `=` out now means the contrib follow-up would have to widen it later.
   
   My reading is that `=` is safe here: with `;` outside the set, top-level commas rejected and brackets required balanced, a bare `=` in the column-type position can't start a new action or terminate the statement — at worst it's a syntax error the database rejects, which is the outcome you described for invalid types anyway. Happy to leave it out if you'd rather keep the first PR minimal.
   
   So the set would become `[\w .,:()<>\[\]=-]` plus an explicit `--` rejection, with the rest exactly as you described: strip single-quoted literals first, `()`/`<>` balanced and never negative, commas only inside brackets.
   
   Two smaller notes:
   
   - `Types.ExternalType.of()` accepts `null` and `" "` today, and `JsonUtils.readExternalType` only checks that the `catalogString` field is present — so I'll reject null/empty/blank in the helper as well.
   - For the contrib follow-up: Hologres looks more exposed than the others. `HologresTableOperations:501` joins with `String.join("\n", alterSql)` and each clause carries its own `;`, so a semicolon in the type string could append an entirely new statement there rather than just an extra ALTER action.
   
   Planning to scope this PR to MySQL, PostgreSQL and Doris plus the shared helper, and open a follow-up for ClickHouse/OceanBase/Hologres. (FWIW StarRocks doesn't need it — its `fromGravitino` has no `ExternalType` branch and already throws.)
   


-- 
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@gravitino.apache.org

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


Re: [I] [Improvement]: ExternalType.catalogString() is written verbatim into DDL SQL without validation in JDBC catalog [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on issue #11805:
URL: https://github.com/apache/gravitino/issues/11805#issuecomment-5628306800

   Thanks @sachinnn99 for picking this up! Below is just an implementation suggestion from my side — @mchades, I'd like to hear your thoughts as well.
   
   **1. Validation shape**
   
   Neither a pure blocklist nor a strict single-token pattern seems sufficient:
   
   - Blocking only `;` and comment markers misses single-statement injection. Both MySQL `ALTER TABLE ... MODIFY COLUMN` and PostgreSQL `ALTER COLUMN ... SET DATA TYPE` accept comma-separated actions, so a type string like `int, DROP COLUMN secret` would still get through.
   - A strict identifier/parentheses/comma pattern would reject values we already produce, e.g. MySQL `enum('a','b')` (quotes, now round-tripped by `MysqlTableOperations`), `int unsigned` / `timestamp with time zone` (spaces), and Doris `struct<a:int>` (colon).
   
   What I have in mind is a lightweight shared check in `JdbcTypeConverter`:
   
   1. Strip single-quoted literals first, so values like `enum('a;b')` are allowed.
   2. Require the remainder to match a small character set such as `[\w .,:()<>\[\]]`. This rules out `;`, `--`, `/*`, `#`, `=`, newlines, and unclosed quotes.
   3. Require balanced `()` and `<>` (tracked separately and never going negative), and reject commas outside of brackets.
   
   The goal is to keep the string confined to the column's type position, not to verify it is a legal type — the database will reject invalid types anyway.
   
   **2. Rejection point**
   
   I'd validate in `fromGravitino`. What counts as a valid type is dialect-specific, so the API layer can't judge it generically, and `fromGravitino` is the choke point before any DDL is built. Throwing an `IllegalArgumentException` that includes the offending type string should be enough.
   
   **Tests and scope**
   
   - Please add round-trip tests for the legitimate types above, plus negative cases: statement separators, comments, top-level commas, and prematurely closed brackets.
   - The contrib converters for ClickHouse, OceanBase, and Hologres return `catalogString()` the same way. They could reuse the helper in this PR or in a follow-up.
   
   @mchades WDYT?
   


-- 
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@gravitino.apache.org

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


Re: [I] [Improvement]: ExternalType.catalogString() is written verbatim into DDL SQL without validation in JDBC catalog [gravitino]

Posted by "SachinForNeenjas (via GitHub)" <gi...@apache.org>.
SachinForNeenjas commented on issue #11805:
URL: https://github.com/apache/gravitino/issues/11805#issuecomment-5640627684

   Thanks @FANNG1, this is really helpful — especially the point about comma-separated actions. I confirmed it in the builders: `MysqlTableOperations.generateAlterTableSql:410` and `DorisTableOperations.generateAlterTableSql:810` both do `"ALTER TABLE \`t\`\n" + String.join(",\n", alterSql) + ";"`, and `PostgreSqlTableOperations:604-614` appends `,\nALTER COLUMN ... SET NOT NULL` right after the type. So a top-level comma does inject an extra action into the same statement, and a `;`-only blocklist would miss it. Agreed on validating in `fromGravitino` and on not trying to prove the type is legal.
   
   Two cases where I think the character set needs to be slightly wider than `[\w .,:()<>\[\]]`:
   
   **1. `-` — the set as written would fail two existing tests.**
   
   `TestMysqlTypeConverter.java:101` and `TestPostgreSqlTypeConverter.java:124` both assert:
   
   ```java
   checkGravitinoTypeToJdbcType(USER_DEFINED_TYPE, Types.ExternalType.of(USER_DEFINED_TYPE));
   // USER_DEFINED_TYPE = "user-defined"
   ```
   
   Since `-` isn't in the set, `fromGravitino(ExternalType.of("user-defined"))` would throw and both tests would start failing.
   
   Suggestion: keep `-` in the set, but reject the two-character sequence `--` separately. `--` is what actually opens a line comment; a lone hyphen can't. `/* */` and `#` need no special case, since `/`, `*` and `#` are already outside the set.
   
   **2. `=` — needed for ClickHouse `Enum8`/`Enum16`.**
   
   `Enum8('active'=1,'inactive'=2)` is stored as an `ExternalType` today (`TestClickHouseTypeConverter.java:108-110`, `CatalogClickHouseIT.java:2934`). ClickHouse is out of scope for this PR, but since the helper lands in the shared `JdbcTypeConverter`, leaving `=` out now means the contrib follow-up would have to widen it later.
   
   My reading is that `=` is safe here: with `;` outside the set, top-level commas rejected and brackets required balanced, a bare `=` in the column-type position can't start a new action or terminate the statement — at worst it's a syntax error the database rejects, which is the outcome you described for invalid types anyway. Happy to leave it out if you'd rather keep the first PR minimal.
   
   So the set would become `[\w .,:()<>\[\]=-]` plus an explicit `--` rejection, with the rest exactly as you described: strip single-quoted literals first, `()`/`<>` balanced and never negative, commas only inside brackets.
   
   Two smaller notes:
   
   - `Types.ExternalType.of()` accepts `null` and `" "` today, and `JsonUtils.readExternalType` only checks that the `catalogString` field is present — so I'll reject null/empty/blank in the helper as well.
   - For the contrib follow-up: Hologres looks more exposed than the others. `HologresTableOperations:501` joins with `String.join("\n", alterSql)` and each clause carries its own `;`, so a semicolon in the type string could append an entirely new statement there rather than just an extra ALTER action.
   
   Planning to scope this PR to MySQL, PostgreSQL and Doris plus the shared helper, and open a follow-up for ClickHouse/OceanBase/Hologres. (FWIW StarRocks doesn't need it — its `fromGravitino` has no `ExternalType` branch and already throws.)
   


-- 
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@gravitino.apache.org

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


Re: [I] [Improvement]: ExternalType.catalogString() is written verbatim into DDL SQL without validation in JDBC catalog [gravitino]

Posted by "sachinnn99 (via GitHub)" <gi...@apache.org>.
sachinnn99 commented on issue #11805:
URL: https://github.com/apache/gravitino/issues/11805#issuecomment-5622113981

   I'd like to work on this.
   
   I've confirmed the current state on `main`: all three converters return `catalogString()` unvalidated — `MysqlTypeConverter.java:163`, `PostgreSqlTypeConverter.java:160`, and `DorisTypeConverter` — and the base `JdbcTypeConverter` has no validation hook to build on.
   
   Proposed approach, following the first option in the description: add a shared validation helper in `JdbcTypeConverter` that rejects `catalogString()` values which aren't a well-formed single-token type name, and call it from `fromGravitino` in the MySQL, PostgreSQL, and Doris converters, with unit tests in each module.
   
   Two questions before I start:
   
   1. Validation shape — is a strict positive pattern (identifier characters, plus the parentheses/commas needed for parameterized names like `numeric(10,2)` and `array<int>`) preferable to blocklisting SQL metacharacters? A positive pattern fails closed, but it risks rejecting legitimate exotic type names, so I'd rather confirm the preference than guess.
   2. Rejection point — should this throw from `fromGravitino` at DDL-construction time, or would you rather it be validated earlier, when the `ExternalType` is first accepted through the API?
   
   Happy to go with the per-catalog allowlist instead if that's the direction you'd prefer.
   


-- 
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@gravitino.apache.org

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