Restrict tags format
This commit is contained in:
1 parent
83de65f913
commit
6c60ce6457
2 files changed
+17
-3
No files matched your search
@@ -483,7 +483,14 @@ router.post("/devices/:id/tags", async (ctx, next) => {
|
|||||||
return void (ctx.status = 403);
|
return void (ctx.status = 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
await db.updateDeviceTags(ctx.params.id, ctx.request.body);
|
await db.updateDeviceTags(ctx.params.id, ctx.request.body);
|
||||||
|
} catch (error) {
|
||||||
|
log.message += " failed";
|
||||||
|
logger.accessWarn(log);
|
||||||
|
ctx.body = error.message;
|
||||||
|
return void (ctx.status = 400);
|
||||||
|
}
|
||||||
|
|
||||||
logger.accessInfo(log);
|
logger.accessInfo(log);
|
||||||
|
|
||||||
|
|||||||
+10
-3
@@ -211,9 +211,16 @@ export function updateDeviceTags(deviceId, tags): Promise<void> {
|
|||||||
const add = [];
|
const add = [];
|
||||||
const pull = [];
|
const pull = [];
|
||||||
|
|
||||||
for (const [tag, onOff] of Object.entries(tags)) {
|
const regex = /^[0-9a-zA-Z_]+$/;
|
||||||
if (onOff) add.push(tag);
|
for (let [tag, onOff] of Object.entries(tags)) {
|
||||||
else pull.push(tag);
|
tag = tag.trim();
|
||||||
|
if (onOff) {
|
||||||
|
if (!tag.match(regex))
|
||||||
|
return void reject(new Error(`Invalid tag '${tag}'`));
|
||||||
|
add.push(tag);
|
||||||
|
} else {
|
||||||
|
pull.push(tag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
getClient()
|
getClient()
|
||||||
.then(client => {
|
.then(client => {
|
||||||
|
|||||||
Reference in new issue
Block a user