fix(excel-import): escape cell values in INSERT statements - #2021
Merged
Merged
Conversation
ReadHeaderListener.buildSql concatenated raw cell values into INSERT VALUES with surrounding single quotes and no escaping, so a value containing an apostrophe (e.g. O'Brien) broke the generated SQL, and a crafted import file could inject SQL. Route values through the existing EasyStringUtils.escapeAndQuoteString, which doubles single quotes and backslashes and wraps the value in quotes — the same path used by the sibling importer via DefaultValueProcessor. Adds contract tests. Fixes OtterMind#2015 Co-Authored-By: Claude <noreply@anthropic.com>
3 tasks
openai0229
approved these changes
Jul 24, 2026
openai0229
left a comment
Contributor
There was a problem hiding this comment.
Reviewed the Excel/CSV SQL generation path and the existing value-processor escaping contract. The change safely quotes apostrophes through the shared helper; the 3 focused tests pass, domain-core packages locally, the exact Java change previously passed Java CodeQL, and the latest required checks are green. No blocking issues found.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issue
Closes #2015
Summary
ReadHeaderListener.buildSqlconcatenated raw cell values into INSERTVALUES (...)with surrounding single quotes and no escaping:A cell value containing an apostrophe (e.g.
O'Brien) became'O'Brien'and broke the generated SQL; in a shared/web deployment a crafted import
file could inject SQL into the batch executed against the target
connection.
The fix routes values through the existing
EasyStringUtils.escapeAndQuoteString(...), which doubles single quotes(
'->'') and backslashes (\\->\\\\) and wraps the value inquotes — the same path the sibling importer uses via
DefaultValueProcessor.getSqlValueString->escapeAndQuoteString.Affected surfaces
Verification
mvn -B -f chat2db-community-server/pom.xml -pl chat2db-community-tools -am -Dmaven.test.skip=false -DskipTests=false -Dtest=ai.chat2db.community.tools.util.EasyStringUtilsTest -Dsurefire.failIfNoSpecifiedTests=false -Dmaven.test.failure.ignore=false test->Tests run: 3, Failures: 0, Errors: 0; reactor BUILD SUCCESS.mvn -B -q -f chat2db-community-server/pom.xml -pl chat2db-community-domain/chat2db-community-domain-core -am -Dmaven.test.skip=true compile-> BUILD SUCCESS (import resolves;chat2db-community-toolsis already a dependency ofdomain-coreandEasyStringUtilsis already used bySQLImporterin the same module).escapeAndQuoteString("O'Brien")returns'O''Brien'(covered by the new test).Risk and compatibility
'') is standard ANSI SQL string escaping and is accepted by the supported databases; the same util is already used by the default value processor across plugins.'value'); only previously-broken/injectable inputs now import correctly.Reviewer map
ReadHeaderListener.java:161—"'" + v + "'"->EasyStringUtils.escapeAndQuoteString(v.toString())); new importai.chat2db.community.tools.util.EasyStringUtils. New testEasyStringUtilsTest.Contributor declaration
AI assistance: The fix, test, verification, and PR description were produced with Claude Code assistance.