-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Issue #12714 verify workername for Mongo usage #12715
base: jetty-12.0.x
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved.. but I do have a niggle you might want to fix
@@ -159,6 +157,8 @@ public class MongoSessionDataStore extends NoSqlSessionDataStore | |||
*/ | |||
private DBObject _version1; | |||
|
|||
private final Pattern _workerNamePattern = Pattern.compile("[0-9a-zA-Z]*"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that it will make any difference, but:
private final Pattern _workerNamePattern = Pattern.compile("[0-9a-zA-Z]*"); | |
private final static Pattern __workerNamePattern = Pattern.compile("[0-9a-zA-Z]*"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -159,6 +157,8 @@ public class MongoSessionDataStore extends NoSqlSessionDataStore | |||
*/ | |||
private DBObject _version1; | |||
|
|||
private final Pattern _workerNamePattern = Pattern.compile("[0-9a-zA-Z]*"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Underscore is a valid character, too.
Adding it would allow the name to support snake case.
return; | ||
|
||
if (!_workerNamePattern.matcher(_context.getWorkerName()).matches()) | ||
throw new IllegalStateException("Invalid worker name: " + _context.getWorkerName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works like a charm!
Only improvement might be stating what's valid, so if the issue is encountered it'd be fixable without diving into the code and looking up the Pattern
Fixes #12714
The
workerName
configured on theDefaultSessionIdManager
can be unacceptable toMongoDB
. TheDefaultSessionIdManager
prepends theworkerName
onto the generated random id to form a session id. If thisworkerName
contains punctuation or other delimiter type characters, this messes with theMongoDB
index over the session ids.This PR allows
MongoSessionDataStore
to check theworkerName
at startup and fail the startup if it isn't admissible.