Skip to content

Commit 620ba7a

Browse files
committed
command_matches_regex: use canonicalized path if user path contains ".."
We already fall back on the canonicalized path if the user-specified path is relative. This helps prevent abuse of overly broad command regular expressions in sudoers. Reported by Christos Papakonstantinou from Cantina (cantina.xyz)
1 parent edc4baa commit 620ba7a

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

plugins/sudoers/match_command.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ command_matches_regex(struct sudoers_context *ctx, const char *sudoers_cmnd,
475475
*
476476
* Neither sudoers_cmnd nor user_cmnd are relative to runchroot.
477477
*/
478-
if (cmnd[0] != '/' || regex_matches(sudoers_cmnd, cmnd) != ALLOW) {
478+
if (cmnd[0] != '/' || sudo_contains_dot_dot(cmnd) ||
479+
regex_matches(sudoers_cmnd, cmnd) != ALLOW) {
479480
/* No match, retry using the canonicalized path (if possible). */
480481
if (ctx->user.cmnd_dir == NULL)
481482
debug_return_int(DENY);

0 commit comments

Comments
 (0)