Textgen: Add permissions check for TabbyAPI keys There's no formal permissions checking in ST's UI, so add a temporary check in the server endpoint before requesting a download. Signed-off-by: kingbri <bdashore3@proton.me>
| @@ -526,7 +526,10 @@ async function downloadTabbyModel() { | ||
| 526 | 526 | body: JSON.stringify(params), |
| 527 | 527 | }); |
| 528 | 528 | |
| 529 | 529 | if (!response.okstatus === 403) { |
| 530 | + toastr.error("The provided key has invalid permissions. Please use an admin key for downloading."); | |
| 531 | + return; | |
| 532 | + } else if (!response.ok) { | |
| 530 | 533 | throw new Error(response.statusText); |
| 531 | 534 | } |
| 532 | 535 | |
| @@ -602,6 +602,23 @@ tabby.post('/download', jsonParser, async function (request, response) { | ||
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | setAdditionalHeaders(request, args, baseUrl); |
| 605 | + | |
| 606 | + // Check key permissions | |
| 607 | + const permissionResponse = await fetch(`${baseUrl}/v1/auth/permission`, { | |
| 608 | + headers: args.headers | |
| 609 | + }); | |
| 610 | + | |
| 611 | + if (permissionResponse.ok) { | |
| 612 | + const permissionJson = await permissionResponse.json(); | |
| 613 | + | |
| 614 | + if (permissionJson['permission'] !== 'admin') { | |
| 615 | + return response.status(403).send({ error: true }); | |
| 616 | + } | |
| 617 | + } else { | |
| 618 | + console.log('API Permission error:', permissionResponse.status, permissionResponse.statusText); | |
| 619 | + return response.status(permissionResponse.status).send({ error: true }); | |
| 620 | + } | |
| 621 | + | |
| 605 | 622 | const fetchResponse = await fetch(`${baseUrl}/v1/download`, args); |
| 606 | 623 | |
| 607 | 624 | if (!fetchResponse.ok) { |