Skip to content

Commit 1b80832

Browse files
sgolemon-corpevergreen
authored andcommitted
SERVER-20558 Use unambiguous name in JS scope identifier
1 parent eb47871 commit 1b80832

File tree

6 files changed

+15
-26
lines changed

6 files changed

+15
-26
lines changed

src/mongo/db/auth/authorization_session.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,6 @@ class AuthorizationSession {
166166
// Gets an iterator over the roles of all authenticated users stored in this manager.
167167
virtual RoleNameIterator getAuthenticatedRoleNames() = 0;
168168

169-
// Returns a std::string representing all logged-in users on the current session.
170-
// WARNING: this std::string will contain NUL bytes so don't call c_str()!
171-
virtual std::string getAuthenticatedUserNamesToken() = 0;
172-
173169
// Removes any authenticated principals whose authorization credentials came from the given
174170
// database, and revokes any privileges that were granted via that principal. This function
175171
// modifies state. Synchronizes with the Client lock.

src/mongo/db/auth/authorization_session_impl.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,6 @@ RoleNameIterator AuthorizationSessionImpl::getAuthenticatedRoleNames() {
184184
return makeRoleNameIterator(_authenticatedRoleNames.begin(), _authenticatedRoleNames.end());
185185
}
186186

187-
std::string AuthorizationSessionImpl::getAuthenticatedUserNamesToken() {
188-
std::string ret;
189-
for (UserNameIterator nameIter = getAuthenticatedUserNames(); nameIter.more();
190-
nameIter.next()) {
191-
ret += '\0'; // Using a NUL byte which isn't valid in usernames to separate them.
192-
ret += nameIter->getFullName();
193-
}
194-
195-
return ret;
196-
}
197-
198187
void AuthorizationSessionImpl::grantInternalAuthorization(Client* client) {
199188
stdx::lock_guard<Client> lk(*client);
200189
_authenticatedUsers.add(internalSecurity.user);

src/mongo/db/auth/authorization_session_impl.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ class AuthorizationSessionImpl : public AuthorizationSession {
9191

9292
RoleNameIterator getAuthenticatedRoleNames() override;
9393

94-
std::string getAuthenticatedUserNamesToken() override;
95-
9694
void logoutDatabase(OperationContext* opCtx, StringData dbname) override;
9795

9896
void grantInternalAuthorization(Client* client) override;

src/mongo/db/commands/mr.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,8 +948,6 @@ State::~State() {
948948
*/
949949
void State::init() {
950950
// setup js
951-
const string userToken =
952-
AuthorizationSession::get(Client::getCurrent())->getAuthenticatedUserNamesToken();
953951
_scope.reset(getGlobalScriptEngine()->newScopeForCurrentThread());
954952
_scope->requireOwnedObjects();
955953
_scope->registerOperation(_opCtx);

src/mongo/db/matcher/expression_where.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@ using std::string;
5050
using std::stringstream;
5151
using std::unique_ptr;
5252

53+
namespace {
54+
std::string getAuthenticatedUserNamesToken(Client* client) {
55+
StringBuilder sb;
56+
57+
auto as = AuthorizationSession::get(client);
58+
for (auto nameIter = as->getAuthenticatedUserNames(); nameIter.more(); nameIter.next()) {
59+
// Using a NUL byte which isn't valid in usernames to separate them.
60+
sb << '\0' << nameIter->getUnambiguousName();
61+
}
62+
63+
return sb.str();
64+
}
65+
} // namespace
66+
5367
WhereMatchExpression::WhereMatchExpression(OperationContext* opCtx,
5468
WhereParams params,
5569
StringData dbName)
@@ -61,9 +75,7 @@ WhereMatchExpression::WhereMatchExpression(OperationContext* opCtx,
6175

6276
uassert(ErrorCodes::BadValue, "ns for $where cannot be empty", dbName.size() != 0);
6377

64-
const string userToken =
65-
AuthorizationSession::get(Client::getCurrent())->getAuthenticatedUserNamesToken();
66-
78+
const auto userToken = getAuthenticatedUserNamesToken(opCtx->getClient());
6779
_scope = getGlobalScriptEngine()->getPooledScope(_opCtx, _dbName, "where" + userToken);
6880
const auto guard = makeGuard([&] { _scope->unregisterOperation(); });
6981

src/mongo/embedded/embedded_auth_session.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,6 @@ class AuthorizationSession : public mongo::AuthorizationSession {
9393
UASSERT_NOT_IMPLEMENTED;
9494
}
9595

96-
std::string getAuthenticatedUserNamesToken() override {
97-
UASSERT_NOT_IMPLEMENTED;
98-
}
99-
10096
void grantInternalAuthorization(Client* client) override {
10197
// Always okay to do something, on embedded.
10298
}

0 commit comments

Comments
 (0)