Skip to content

Commit b003af2

Browse files
authored
Merge pull request #50794 from nextcloud/fix/fix-appmanager-cleanappid
fix: Only keep allowed characters in appid, and flag the method as escaping
2 parents c71bc06 + 6e7c97e commit b003af2

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

lib/private/App/AppManager.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,8 +939,23 @@ public function isBackendRequired(string $backend): bool {
939939
return false;
940940
}
941941

942+
/**
943+
* Clean the appId from forbidden characters
944+
*
945+
* @psalm-taint-escape callable
946+
* @psalm-taint-escape cookie
947+
* @psalm-taint-escape file
948+
* @psalm-taint-escape has_quotes
949+
* @psalm-taint-escape header
950+
* @psalm-taint-escape html
951+
* @psalm-taint-escape include
952+
* @psalm-taint-escape ldap
953+
* @psalm-taint-escape shell
954+
* @psalm-taint-escape sql
955+
* @psalm-taint-escape unserialize
956+
*/
942957
public function cleanAppId(string $app): string {
943-
// FIXME should list allowed characters instead
944-
return str_replace(['<', '>', '"', "'", '\0', '/', '\\', '..'], '', $app);
958+
/* Only lowercase alphanumeric is allowed */
959+
return preg_replace('/(^[0-9_]|[^a-z0-9_]+|_$)/', '', $app);
945960
}
946961
}

lib/public/App/IAppManager.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,17 @@ public function isBackendRequired(string $backend): bool;
309309
/**
310310
* Clean the appId from forbidden characters
311311
*
312+
* @psalm-taint-escape callable
313+
* @psalm-taint-escape cookie
312314
* @psalm-taint-escape file
313-
* @psalm-taint-escape include
314-
* @psalm-taint-escape html
315315
* @psalm-taint-escape has_quotes
316+
* @psalm-taint-escape header
317+
* @psalm-taint-escape html
318+
* @psalm-taint-escape include
319+
* @psalm-taint-escape ldap
320+
* @psalm-taint-escape shell
321+
* @psalm-taint-escape sql
322+
* @psalm-taint-escape unserialize
316323
*
317324
* @since 31.0.0
318325
*/

0 commit comments

Comments
 (0)