Skip to content

Commit 747fbf6

Browse files
Merge pull request #50799 from nextcloud/backport/50794/stable31
[stable31] fix: Only keep allowed characters in appid, and flag the method as escaping
2 parents f0a229c + a9ad23e commit 747fbf6

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
@@ -926,8 +926,23 @@ public function isBackendRequired(string $backend): bool {
926926
return false;
927927
}
928928

929+
/**
930+
* Clean the appId from forbidden characters
931+
*
932+
* @psalm-taint-escape callable
933+
* @psalm-taint-escape cookie
934+
* @psalm-taint-escape file
935+
* @psalm-taint-escape has_quotes
936+
* @psalm-taint-escape header
937+
* @psalm-taint-escape html
938+
* @psalm-taint-escape include
939+
* @psalm-taint-escape ldap
940+
* @psalm-taint-escape shell
941+
* @psalm-taint-escape sql
942+
* @psalm-taint-escape unserialize
943+
*/
929944
public function cleanAppId(string $app): string {
930-
// FIXME should list allowed characters instead
931-
return str_replace(['<', '>', '"', "'", '\0', '/', '\\', '..'], '', $app);
945+
/* Only lowercase alphanumeric is allowed */
946+
return preg_replace('/(^[0-9_]|[^a-z0-9_]+|_$)/', '', $app);
932947
}
933948
}

lib/public/App/IAppManager.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,17 @@ public function isBackendRequired(string $backend): bool;
292292
/**
293293
* Clean the appId from forbidden characters
294294
*
295+
* @psalm-taint-escape callable
296+
* @psalm-taint-escape cookie
295297
* @psalm-taint-escape file
296-
* @psalm-taint-escape include
297-
* @psalm-taint-escape html
298298
* @psalm-taint-escape has_quotes
299+
* @psalm-taint-escape header
300+
* @psalm-taint-escape html
301+
* @psalm-taint-escape include
302+
* @psalm-taint-escape ldap
303+
* @psalm-taint-escape shell
304+
* @psalm-taint-escape sql
305+
* @psalm-taint-escape unserialize
299306
*
300307
* @since 31.0.0
301308
*/

0 commit comments

Comments
 (0)