Skip to content

Fix CVE-2022-23305: use PreparedStatement in JDBCAppender when possible - #26

Closed
vlsi wants to merge 2 commits into
qos-ch:branch_1.2.18from
vlsi:jdbc_cve
Closed

vlsi wants to merge 2 commits into
qos-ch:branch_1.2.18from
vlsi:jdbc_cve

Conversation

@vlsi

@vlsi vlsi commented Jan 19, 2022

Copy link
Copy Markdown
Contributor

By default, the appender would treat '....%..' as string literals,
and it would use PreparedStatement.setString(..) for that.

Old behavior can be restored via org.apache.log4j.jdbc.JDBCAppender.secure_jdbc_replacement=false.


UPD: as JDBCAppender has been removed, the diff was looking as if I added the class from scratch. So I've split the PR in two commits: "revert JDBCAppender removal" and then "fix CVE". I believe it makes it easier to see what has changed to fix the CVE.

@vlsi
vlsi force-pushed the jdbc_cve branch 5 times, most recently from 8754302 to 790735f Compare January 19, 2022 18:49
Comment thread src/main/java/org/apache/log4j/jdbc/JDBCAppender.java Outdated
Comment thread src/main/java/org/apache/log4j/jdbc/JDBCAppender.java
@vlsi
vlsi force-pushed the jdbc_cve branch 7 times, most recently from e845f28 to 362d349 Compare January 20, 2022 10:38
This reverts commit 527f537.

Signed-off-by: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
By default the appender would treat '....%..' as string literals,
and it would use PreparedStatement.setString(..) for that.

Old behavior can be restored via org.apache.log4j.jdbc.JDBCAppender.securejdbc_replacement=false.

Signed-off-by: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
import java.util.regex.Pattern;

class JdbcPatternParser {
private final static Pattern STRING_LITERAL_PATTERN = Pattern.compile("'((?>[^']|'')+)'");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The atomic group is needed here to prevent StackOverflowError like in https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6337993

@ceki
ceki deleted the branch qos-ch:branch_1.2.18 February 7, 2022 17:14
@ceki ceki closed this Feb 7, 2022
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.

2 participants