Skip to content

_extract_shell_command regex only matches -lc quoted style #17

@fazxes

Description

@fazxes

Context

From PR #13 code review.

Problem

In nightshift/cycle.py line 464-468, _extract_shell_command() uses a regex that only matches the -lc 'body' or -lc "body" shell wrapper pattern:

def _extract_shell_command(command: str) -> str:
    shell_match = re.search(r"-lc\s+['\"](?P<body>.+?)['\"]$", command)
    if shell_match:
        return shell_match.group("body").strip()
    return command.strip()

If an agent wraps commands differently (e.g. bash -c "cmd", sh -c 'cmd', or no wrapper at all with just the raw command), this won't extract the inner command and the forbidden command check could miss violations.

Suggested fix

Broaden the regex to also handle bash -c, sh -c, and /bin/sh -c patterns, or extract more generically. The current approach is a reasonable tradeoff (avoids false positives), but documenting the limitation with a comment would also be acceptable as a minimal fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions