Skip to content

Commit 2779a1a

Browse files
committed
fix(ai-apis): reject text inputs that are longer than 64K chars
Signed-off-by: Julien Veyssier <[email protected]>
1 parent e1a98c0 commit 2779a1a

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

core/Controller/TextProcessingApiController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ public function taskTypes(): DataResponse {
104104
#[NoAdminRequired]
105105
#[UserRateLimit(limit: 20, period: 120)]
106106
public function schedule(string $input, string $type, string $appId, string $identifier = ''): DataResponse {
107+
if (strlen($input) > 64_000) {
108+
return new DataResponse(['message' => $this->l->t('Input text is too long')], Http::STATUS_BAD_REQUEST);
109+
}
107110
try {
108111
$task = new Task($type, $input, $appId, $this->userId, $identifier);
109112
} catch (InvalidArgumentException) {

core/Controller/TranslationApiController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ public function languages(): DataResponse {
6767
* @AnonRateThrottle(limit=10, period=120)
6868
*/
6969
public function translate(string $text, ?string $fromLanguage, string $toLanguage): DataResponse {
70+
if (strlen($text) > 64_000) {
71+
return new DataResponse(['message' => $this->l->t('Input text is too long')], Http::STATUS_BAD_REQUEST);
72+
}
7073
try {
7174
$translation = $this->translationManager->translate($text, $fromLanguage, $toLanguage);
7275

0 commit comments

Comments
 (0)