Skip to content

Commit 80cc1d3

Browse files
committed
fix: closes #13176, check if uid is number when creating tokens
1 parent 5e71d59 commit 80cc1d3

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/api/utils.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ utils.tokens.get = async (tokens) => {
5252
};
5353

5454
utils.tokens.generate = async ({ uid, description }) => {
55+
if (!srcUtils.isNumber(uid)) {
56+
throw new Error('[[error:invalid-uid]]');
57+
}
5558
if (parseInt(uid, 10) !== 0) {
5659
const uidExists = await user.exists(uid);
5760
if (!uidExists) {
@@ -66,7 +69,7 @@ utils.tokens.generate = async ({ uid, description }) => {
6669
};
6770

6871
utils.tokens.add = async ({ token, uid, description = '', timestamp = Date.now() }) => {
69-
if (!token || uid === undefined) {
72+
if (!token || uid === undefined || !srcUtils.isNumber(uid)) {
7073
throw new Error('[[error:invalid-data]]');
7174
}
7275

@@ -80,6 +83,9 @@ utils.tokens.add = async ({ token, uid, description = '', timestamp = Date.now()
8083
};
8184

8285
utils.tokens.update = async (token, { uid, description }) => {
86+
if (!srcUtils.isNumber(uid)) {
87+
throw new Error('[[error:invalid-uid]]');
88+
}
8389
await Promise.all([
8490
db.setObject(`token:${token}`, { uid, description }),
8591
db.sortedSetAdd(`tokens:uid`, uid, token),
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<form role="form">
22
<div class="mb-3">
33
<label class="form-label" for="uid">[[admin/settings/api:uid]]</label>
4-
<input type="text" inputmode="numeric" pattern="\d+" name="uid" class="form-control" placeholder="0" value="{./uid}" />
4+
<input id="uid" type="number" inputmode="numeric" pattern="\d+" name="uid" class="form-control" placeholder="0" value="{./uid}" />
55
<p class="form-text">
66
[[admin/settings/api:uid-help-text]]
77
</p>
88
</div>
99
<div class="mb-3">
1010
<label class="form-label" for="description">[[admin/settings/api:description]]</label>
11-
<input type="text" name="description" class="form-control" placeholder="Description" value="{./description}" />
11+
<input id="description" type="text" name="description" class="form-control" placeholder="Description" value="{./description}" />
1212
</div>
1313
</form>

0 commit comments

Comments
 (0)