Skip to content

Commit cd8d367

Browse files
authored
Merge pull request #4768 from coralproject/hotfix/tokenTest-error-handling
[Hotfix] Add error handling around `tokenTest` endpoint
2 parents 6bcc459 + fec70ab commit cd8d367

File tree

5 files changed

+38
-34
lines changed

5 files changed

+38
-34
lines changed

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coralproject/talk",
3-
"version": "9.9.2",
3+
"version": "9.9.3",
44
"author": "The Coral Project",
55
"homepage": "https://coralproject.net/",
66
"sideEffects": [

common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "common",
3-
"version": "9.9.2",
3+
"version": "9.9.3",
44
"description": "",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "common",
3-
"version": "9.9.2",
3+
"version": "9.9.3",
44
"description": "",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coralproject/talk",
3-
"version": "9.9.2",
3+
"version": "9.9.3",
44
"author": "The Coral Project",
55
"homepage": "https://coralproject.net/",
66
"sideEffects": [

server/src/core/server/app/handlers/api/auth/tokenTest/index.ts

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -272,37 +272,41 @@ export const submitHandler = ({
272272
});
273273

274274
return async (req, res, next) => {
275-
await ipLimiter.test(req, req.ip);
276-
277-
const result = submitSchema.validate(req.body);
278-
if (result.error) {
279-
res.send(renderIndex([result.error.message]));
280-
return;
281-
}
282-
283-
const body = result.value as SubmitBody;
284-
if (!body) {
285-
res.send(renderIndex());
286-
return;
275+
try {
276+
await ipLimiter.test(req, req.ip);
277+
278+
const result = submitSchema.validate(req.body);
279+
if (result.error) {
280+
res.send(renderIndex([result.error.message]));
281+
return;
282+
}
283+
284+
const body = result.value as SubmitBody;
285+
if (!body) {
286+
res.send(renderIndex());
287+
return;
288+
}
289+
290+
const cleanToken = body.token.trim();
291+
const decodedToken = jwt.decode(cleanToken);
292+
if (!decodedToken) {
293+
res.send(renderIndex(["Token is invalid."]));
294+
return;
295+
}
296+
297+
const analysis = analyseTokenPayload(decodedToken);
298+
299+
res.send(
300+
renderIndex(
301+
[],
302+
cleanToken,
303+
JSON.stringify(decodedToken, null, 2).trim(),
304+
analysis
305+
)
306+
);
307+
} catch (err) {
308+
return next(err);
287309
}
288-
289-
const cleanToken = body.token.trim();
290-
const decodedToken = jwt.decode(cleanToken);
291-
if (!decodedToken) {
292-
res.send(renderIndex(["Token is invalid."]));
293-
return;
294-
}
295-
296-
const analysis = analyseTokenPayload(decodedToken);
297-
298-
res.send(
299-
renderIndex(
300-
[],
301-
cleanToken,
302-
JSON.stringify(decodedToken, null, 2).trim(),
303-
analysis
304-
)
305-
);
306310
};
307311
};
308312

0 commit comments

Comments
 (0)