Skip to content

[ZEPPELIN-6186] fix searching user using JdbcRealm #4926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

sh1nj1
Copy link
Contributor

@sh1nj1 sh1nj1 commented Apr 29, 2025

What is this PR for?

This PR fixes a broken feature where getUserList fails when using JdbcRealm for Shiro authentication.

The previous PR addressing SQL injection introduced an error that prevents getUserList from working correctly with JdbcRealm. As a result, users are unable to set notebook permissions.

Ref: #4676

What type of PR is it?

Bug Fix

Todos

What is the Jira issue?

How should this be tested?

Added new unit test should be passed

  • ./mvnw clean package -pl zeppelin-server -am

Verify in UI

  • Go to notebook permission settings
  • Type username and see if username listed

Screenshots (if appropriate)

Questions:

  • Does the license files need to update? No
  • Is there breaking changes for older versions? No
  • Does this needs documentation? No

@sh1nj1 sh1nj1 force-pushed the fix/user-list-in-jdbc branch from 77287ab to 706653a Compare April 30, 2025 00:07
@sh1nj1 sh1nj1 changed the title [ZEPPELIN-3725] fix search user error using JdbcRealm [ZEPPELIN-3725] fix searching user using JdbcRealm Apr 30, 2025

userquery = "SELECT ? FROM ?";
userquery = String.format("SELECT %s FROM %s WHERE %s LIKE ?", username, tablename, username);
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better to use PreparedStatement instead of making a query using String.format.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the last PR's issue for this, you can use parameter replacement in where clause, not the table name or projections. That's why I make this PR.
SELECT ? FROM ? makes query syntax error because it create invalid query by the PreparedStatement because you can not use '?' in select clause or from clause.

Copy link
Member

Choose a reason for hiding this comment

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

Can you please explain more about it? If PreparedStatement disallows it, it shouldn't be passed as a query. The test case doesn't cover it as well.

Copy link
Member

@jongyoul jongyoul Apr 30, 2025

Choose a reason for hiding this comment

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

I think we could set SELECT ? FROM ? WHERE ? LIKE ?, and pass it as ps.setString(4, "%" + username + "%").

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://stackoverflow.com/a/2917509/1395707 this explains it better than me.

I use PreparedStatement only set WHERE username LIKE ? but remove from select clause and from clause.
If I use old implementation, it creates an error in test case that I added here.

Copy link
Contributor Author

@sh1nj1 sh1nj1 Apr 30, 2025

Choose a reason for hiding this comment

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

SELECT ? FROM ? WHERE ? LIKE ?

that's the point, previous PR use this form rather than String.format but it misuse PreparedStatement, so that it creates error.

So I changed and I added some validation for username and tablename for the possible SQL Injection that previous PR tried to implement.

Copy link
Member

Choose a reason for hiding this comment

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

Ah .. I got the point. You meant we shouldn't use an identifier as a literal in the preparedStatement.

@jongyoul
Copy link
Member

Thank you for your contribution! I left one comment. Please check it.

jongyoul
jongyoul previously approved these changes Apr 30, 2025
Copy link
Member

@jongyoul jongyoul left a comment

Choose a reason for hiding this comment

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

LGTM. By the way, we can refator the whole logic to parse a tablename and username, and get them from separate variables and pass them directly. Can you consider refactoring the logic as well?

@jongyoul
Copy link
Member

@sh1nj1 Can you please create a new ticket so that I can give you credit as the assignee for this issue?

@sh1nj1 sh1nj1 changed the title [ZEPPELIN-3725] fix searching user using JdbcRealm [ZEPPELIN-6186] fix searching user using JdbcRealm Apr 30, 2025
@sh1nj1
Copy link
Contributor Author

sh1nj1 commented Apr 30, 2025

@jongyoul updated the ticket ID

Can you consider refactoring the logic as well?

I can do in a separate PR

Copy link
Contributor

@Reamer Reamer left a comment

Choose a reason for hiding this comment

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

Looks good to me too. Only the indentation looks strange. Maybe it's a GitHub display issue. Can you please make sure you don't use tabs for the indentation.

@sh1nj1
Copy link
Contributor Author

sh1nj1 commented Apr 30, 2025

@Reamer fixed indentation

Copy link
Contributor

@Reamer Reamer left a comment

Choose a reason for hiding this comment

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

The indentation looks much better. I have two minor points to mention.

rs = ps.executeQuery();
while (rs.next()) {
int count = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the count?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is it naming issue, no need issue or anything else?
BTW, I removed the variable.

Copy link
Contributor

@Reamer Reamer left a comment

Choose a reason for hiding this comment

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

LGTM
If no further comments are received, I will merge the whole thing next Monday.

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.

3 participants