Skip to content

Commit fcbbd83

Browse files
committed
Several changes:
- Fix issue #7028: make sure to update the offset for subsequent query fields + test cases - wt_config.xml.in: extBaseURL has no use in Wt 4 anymore - Restore accidental conversions to StandardColor back (in docs) - WFileDropWidget: remove UpdateLock taking in JWt - explicit bool operators for safe bool conversion in: - observing_ptr - WApplication::UpdateLock
1 parent c472fc3 commit fcbbd83

21 files changed

+185
-64
lines changed

src/Wt/Auth/AuthModel.C

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,17 @@ User AuthModel::processAuthToken()
236236
AuthTokenResult result = baseAuth()->processAuthToken(*token, users());
237237

238238
switch(result.state()) {
239-
case AuthTokenState::Valid:
240-
/*
241-
* Only extend the validity from what we had currently.
242-
*/
243-
app->setCookie(baseAuth()->authTokenCookieName(), result.newToken(),
244-
result.newTokenValidity(), "", "", app->environment().urlScheme() == "https");
239+
case AuthTokenState::Valid: {
240+
if (!result.newToken().empty()) {
241+
/*
242+
* Only extend the validity from what we had currently.
243+
*/
244+
app->setCookie(baseAuth()->authTokenCookieName(), result.newToken(),
245+
result.newTokenValidity(), "", "", app->environment().urlScheme() == "https");
246+
}
245247

246248
return result.user();
249+
}
247250
case AuthTokenState::Invalid:
248251
app->setCookie(baseAuth()->authTokenCookieName(),std::string(), 0, "", "", app->environment().urlScheme() == "https");
249252

src/Wt/Auth/AuthService.C

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ AuthService::AuthService()
128128
emailVerification_(false),
129129
emailTokenValidity_(3 * 24 * 60), // three days
130130
authTokens_(false),
131+
authTokenUpdateEnabled_(true),
131132
authTokenValidity_(14 * 24 * 60) // two weeks
132133
{
133134
redirectInternalPath_ = "/auth/mail/";
@@ -254,26 +255,31 @@ AuthTokenResult AuthService::processAuthToken(const std::string& token,
254255
User user = users.findWithAuthToken(hash);
255256

256257
if (user.isValid()) {
257-
std::string newToken = WRandom::generateId(tokenLength_);
258-
std::string newHash = tokenHashFunction()->compute(newToken, std::string());
259-
int validity = user.updateAuthToken(hash, newHash);
260-
261-
if (validity < 0) {
262-
/*
263-
* Old API, this is bad since we always extend the lifetime of the
264-
* token.
265-
*/
266-
user.removeAuthToken(hash);
267-
newToken = createAuthToken(user);
268-
validity = authTokenValidity_ * 60;
269-
}
258+
if (authTokenUpdateEnabled_) {
259+
std::string newToken = WRandom::generateId(tokenLength_);
260+
std::string newHash = tokenHashFunction()->compute(newToken, std::string());
261+
int validity = user.updateAuthToken(hash, newHash);
262+
263+
if (validity < 0) {
264+
/*
265+
* Old API, this is bad since we always extend the lifetime of the
266+
* token.
267+
*/
268+
user.removeAuthToken(hash);
269+
newToken = createAuthToken(user);
270+
validity = authTokenValidity_ * 60;
271+
}
270272

271-
if (t.get()) t->commit();
273+
if (t.get())
274+
t->commit();
272275

273-
return AuthTokenResult(AuthTokenState::Valid,
274-
user, newToken, validity);
276+
return AuthTokenResult(AuthTokenState::Valid, user, newToken, validity);
277+
} else {
278+
return AuthTokenResult(AuthTokenState::Valid, user);
279+
}
275280
} else {
276-
if (t.get()) t->commit();
281+
if (t.get())
282+
t->commit();
277283

278284
return AuthTokenResult(AuthTokenState::Invalid);
279285
}

src/Wt/Auth/AuthService.h

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ class WT_API AuthTokenResult
192192

193193
/*! \brief Returns a new token for this user.
194194
*
195-
* An authentication token can be used only once, and needs to be
196-
* replaced by a new token.
195+
* Returns the empty string if there is no new token. See
196+
* AuthService::authTokenUpdateEnabled().
197197
*
198198
* The returned token is valid only if the state() == AuthTokenState::Valid.
199199
*/
@@ -203,6 +203,8 @@ class WT_API AuthTokenResult
203203
*
204204
* This returns the token validity in seconds.
205205
*
206+
* Returns -1 if there is no new token, or result() != Valid.
207+
*
206208
* \sa newToken()
207209
*/
208210
int newTokenValidity() const;
@@ -331,6 +333,32 @@ class WT_API AuthService
331333
*/
332334
bool authTokensEnabled() const { return authTokens_; }
333335

336+
/*! \brief Set whether processAuthToken() updates the auth token
337+
*
338+
* If this option is enabled, processAuthToken() will replace the auth token
339+
* with a new token. This is a bit more secure, because an auth token can
340+
* only be used once. This is enabled by default.
341+
*
342+
* However, this means that if a user concurrently opens multiple sessions within
343+
* the same browsers (e.g. multiple tabs being restored at the same time)
344+
* or refreshes before they receive the new cookie, the user will be logged out,
345+
* unless the AbstractUserDatabase implementation takes this into account
346+
* (e.g. keeps the old token valid for a little bit longer)
347+
*
348+
* The default Dbo UserDatabase does not handle concurrent token updates well,
349+
* so disable this option if you want to prevent that issue.
350+
*
351+
* \sa processAuthToken()
352+
* \sa authTokenUpdateEnabled()
353+
*/
354+
void setAuthTokenUpdateEnabled(bool enabled) { authTokenUpdateEnabled_ = enabled; }
355+
356+
/*! \brief Returns whether the auth token is updated
357+
*
358+
* \sa setAuthTokenUpdateEnabled()
359+
*/
360+
bool authTokenUpdateEnabled() const { return authTokenUpdateEnabled_; }
361+
334362
/*! \brief Returns the authentication token cookie name.
335363
*
336364
* This is the default cookie name used for storing the authentication
@@ -380,8 +408,11 @@ class WT_API AuthService
380408
/*! \brief Processes an authentication token.
381409
*
382410
* This verifies an authentication token, and considers whether it matches
383-
* with a token hash value stored in database. If it matches, the token
384-
* is removed and a new token is created for the identified user.
411+
* with a token hash value stored in database. If it matches and auth token
412+
* update is enabled, the token is updated with a new hash.
413+
*
414+
* \sa setAuthTokenUpdateEnabled()
415+
* \sa AbstractUserDatabase::updateAuthToken()
385416
*/
386417
virtual AuthTokenResult processAuthToken(const std::string& token,
387418
AbstractUserDatabase& users) const;
@@ -585,6 +616,7 @@ class WT_API AuthService
585616
std::string redirectInternalPath_;
586617

587618
bool authTokens_;
619+
bool authTokenUpdateEnabled_;
588620
int authTokenValidity_; // minutes
589621
std::string authTokenCookieName_;
590622
std::string authTokenCookieDomain_;

src/Wt/Chart/WAbstractGridData.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,7 @@ void WAbstractGridData::paintGLIndex(unsigned index, double marginX, double marg
17311731

17321732
// Encoding the index as a color value.
17331733
//
1734-
// Since StandardColor::White is the clear color of the index texture,
1734+
// Since white is the clear color of the index texture,
17351735
// this allows for 16777215 meshes. That should be enough,
17361736
// or is even a tad excessive.
17371737
float r = ((index >> 16) & 0xff) / 255.0f;

src/Wt/Chart/WAbstractGridData.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class WT_API WAbstractGridData : public WAbstractDataSeries3D {
120120
/*! \brief Sets the WPen that is used for drawing the mesh.
121121
*
122122
* Used when drawing the mesh on a surface or the lines around bars. The
123-
* default is a default constructed WPen (StandardColor::Black and one pixel wide).
123+
* default is a default constructed WPen (black and one pixel wide).
124124
*
125125
* Note: only the width and color of this WPen are used.
126126
*

src/Wt/Core/observing_ptr.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class observing_ptr
116116
* Returns if the pointer does not point to \c null and the pointed
117117
* object isn't deleted.
118118
*/
119-
operator bool() const noexcept;
119+
explicit operator bool() const noexcept;
120120

121121
/*! \brief Returns whether the observed object has been deleted.
122122
*

src/Wt/Dbo/Query.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ std::string createQueryCountSql(const std::string& query,
194194
void substituteFields(const SelectFieldList& list,
195195
const std::vector<FieldInfo>& fs,
196196
std::string& sql,
197-
int offset)
197+
int& offset)
198198
{
199199
for (unsigned i = 0, j = 0; j < list.size(); ++j) {
200200
if (fs[i].isFirstDboField()) {

src/Wt/Dbo/Query_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ extern void WTDBO_API
5252
substituteFields(const SelectFieldList& list,
5353
const std::vector<FieldInfo>& fs,
5454
std::string& sql,
55-
int offset);
55+
int& offset);
5656

5757
extern void WTDBO_API
5858
parseSql(const std::string& sql, SelectFieldLists& fieldLists);

src/Wt/Render/LayoutBox.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct InlineBox : public LayoutBox
2727

2828
int utf8Pos, utf8Count;
2929

30-
// minimum width of StandardColor::White space contained in this linebox.
30+
// minimum width of whitespace contained in this linebox.
3131
double whitespaceWidth;
3232
int whitespaceCount;
3333

src/Wt/Render/Line.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void Line::finish(AlignmentFlag textAlign,
166166
Range rangeX(minX, maxX);
167167
Block::adjustAvailableWidth(y_, page_, floats, rangeX);
168168

169-
/* Compute total width and total StandardColor::White space width */
169+
/* Compute total width and total whitespace width */
170170
double whitespace = 0;
171171
double content = 0;
172172

0 commit comments

Comments
 (0)