Skip to content

Conversation

@meatsnails
Copy link
Collaborator

@meatsnails meatsnails commented Dec 30, 2025

Pull Request

Description

If your PR is related to an issue, please include the issue number below:

Related Issue: Closes #1125 #786

Type of Change:

  • Bug fix (non-breaking change which fixes an issue)

Guidelines

  • My code follows the style guidelines of this project (formatted with Ruff)

  • I have performed a self-review of my own code

  • I have commented my code, particularly in hard-to-understand areas

  • I have made corresponding changes to the documentation if needed

  • My changes generate no new warnings

  • I have tested this change

  • Any dependent changes have been merged and published in downstream modules

  • I have added all appropriate labels to this PR

  • I have followed all of these guidelines.

How Has This Been Tested? (if applicable)

tested by sending various messages with the problems described in the issues (see screenshots)

Screenshots (if applicable)

image image

Summary by Sourcery

Tighten detection of destructive rm commands in the harmfulcommands plugin to better catch edge cases and avoid false positives.

Bug Fixes:

  • Ensure rm is only matched as a standalone command rather than as part of longer words.
  • Extend detection of dangerous targets to cover relative paths like ./ and .. in addition to root, home, and critical system paths.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 30, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts the harmful command detector’s rm-pattern regex to more precisely match the rm command and expand coverage to additional dangerous path patterns (including relative paths like ./ and ..).

File-Level Changes

Change Details Files
Tighten rm command detection and extend dangerous-path matching in the harmful commands regex.
  • Require word-boundary matching for the rm token so only the actual rm command is matched, not substrings within other words or commands.
  • Expand the root/home indicator portion of the regex to also treat ./ and .. style relative paths as dangerous alongside existing /, ~, ∕, and wildcard patterns.
  • Preserve and integrate with existing dangerous directory and flag matching for rm invocations, ensuring overall behavior is more robust for privilege-escalated rm commands.
src/tux/plugins/atl/harmfulcommands.py

Assessment against linked issues

Issue Objective Addressed Explanation
#1125 Detect and warn on harmful rm commands even when using dot-based path variants such as sudo rm -rf ./* instead of sudo rm -rf /*.

Possibly linked issues

  • #(unknown): The PR tightens rm regex and path matching, directly improving the harmful command handling requested in the issue.
  • #: PR refines the rm harmfulcommands regex to fix the false positives described in the issue.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions
Copy link
Contributor

github-actions bot commented Dec 30, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@coderabbitai
Copy link

coderabbitai bot commented Dec 30, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Updated the DANGEROUS_RM_COMMANDS regex to match rm as a whole word, recognize dot-relative paths (./, ../), and corrected a typo in the critical path list (rooinroot) in src/tux/plugins/atl/harmfulcommands.py.

Changes

Cohort / File(s) Summary
Harmful Commands Detection
src/tux/plugins/atl/harmfulcommands.py
Modified exported constant DANGEROUS_RM_COMMANDS: changed r"rm\s+"r"\brm\b\s+" to require whole-word rm; expanded path-indicator alternatives to include dot-relative patterns `.(?:/

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(harmfulcommands): Corrected some edge cases' accurately describes the main change—improving rm command detection regex to handle edge cases.
Description check ✅ Passed The description is related to the changeset, including issue references, change type, testing approach, and a clear summary of the improvements made.
Linked Issues check ✅ Passed The PR successfully addresses issue #1125 by adding support for relative paths (./ and ..) in the dangerous rm command detection, which was the primary coding requirement.
Out of Scope Changes check ✅ Passed All changes are scoped to improving the DANGEROUS_RM_COMMANDS regex pattern to detect more variants of harmful rm commands as specified in the linked issues.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/harmfulcommands

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0fe6ce8 and 75a2962.

📒 Files selected for processing (1)
  • src/tux/plugins/atl/harmfulcommands.py
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Use strict type hints with Type | None instead of Optional[Type]
Use NumPy docstrings for documenting functions and classes
Prefer absolute imports; relative imports allowed only within the same module
Organize imports in order: stdlib → third-party → local
Use 88 character line length
Use snake_case for functions and variables, PascalCase for classes, UPPER_CASE for constants
Always add imports to the top of the file unless absolutely necessary
Use async/await for I/O operations
Use custom exceptions for business logic with context logging and meaningful user messages
Use Pydantic for data validation
Keep files to a maximum of 1600 lines
Use one class or function per file when possible
Use descriptive filenames
Add appropriate logging to services and error handlers

Files:

  • src/tux/plugins/atl/harmfulcommands.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Run All Tests (3.13.8)
  • GitHub Check: Sourcery review
🔇 Additional comments (2)
src/tux/plugins/atl/harmfulcommands.py (2)

25-25: Word boundary for rm prevents false positives and addresses substring matching.

The change to \brm\b\s+ correctly ensures rm is matched as a standalone command, avoiding false positives from words like "armor" or "firmware".

Regarding the past comment about rm-rf (no space): The current pattern requires whitespace after rm, which means rm-rf won't match. This is acceptable because rm-rf is not valid shell syntax—the proper form is rm -rf with a space. Catching only valid syntax is a reasonable design choice.


31-31: Good catch on the typo fix: rooinroot.

This correction ensures that commands targeting the /root directory are properly detected as dangerous.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `src/tux/plugins/atl/harmfulcommands.py:25` </location>
<code_context>
     r"(?:sudo\s+|doas\s+|run0\s+)?"
     # rm command
-    r"rm\s+"
+    r"\brm\b\s+"
     # rm options
     r"(?:-[frR]+|--force|--recursive|--no-preserve-root|\s+)*"
</code_context>

<issue_to_address>
**question:** Consider whether this should also catch `rm` immediately followed by flags (no space), e.g. `rm-rf /`.

The stricter `\brm\b\s+` pattern avoids substring matches but now only matches when `rm` is followed by whitespace. If you also need to catch forms like `rm-rf /` or `rm--no-preserve-root /`, you could instead allow optional whitespace or `-` after `rm`. If those forms are out of scope, the current pattern is fine.
</issue_to_address>

### Comment 2
<location> `src/tux/plugins/atl/harmfulcommands.py:29` </location>
<code_context>
     r"(?:-[frR]+|--force|--recursive|--no-preserve-root|\s+)*"
     # Root/home indicators
-    r"(?:[/\∕~]\s*|\*|"  # noqa: RUF001
+    r"(?:[/\∕~]\s*|\.(?:/|\.)\s*|\*|"  # noqa: RUF001
     # Critical system paths
     r"/(?:bin|boot|etc|lib|proc|rooin|sys|tmp|usr|var(?:/log)?|network\.|system))"
</code_context>

<issue_to_address>
**issue (bug_risk):** Pattern for `./` and `..` misses `../` (dot-dot-slash) and may under-detect dangerous `rm -rf ../`.

`\.(?:/|\.)\s*` matches `./`, `./ `, `..`, and `.. `, but not `../` or `../ `, since the `/` after `..` doesn’t match `\s*`. As a result, `rm -rf ../` won’t be caught. Consider something like `\.(?:\.(?:/)?|/)\s*` so both `./`/`./ ` and `../`/`../ ` are treated as hazardous targets.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

r"(?:-[frR]+|--force|--recursive|--no-preserve-root|\s+)*"
# Root/home indicators
r"(?:[/\∕~]\s*|\*|" # noqa: RUF001
r"(?:[/\∕~]\s*|\.(?:/|\.)\s*|\*|" # noqa: RUF001
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Pattern for ./ and .. misses ../ (dot-dot-slash) and may under-detect dangerous rm -rf ../.

\.(?:/|\.)\s* matches ./, ./ , .., and .. , but not ../ or ../ , since the / after .. doesn’t match \s*. As a result, rm -rf ../ won’t be caught. Consider something like \.(?:\.(?:/)?|/)\s* so both .//./ and ..//../ are treated as hazardous targets.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 30, 2025

📚 Documentation Preview

Type URL Version Message
Production https://tux.atl.dev - -
Preview https://38d50861-tux-docs.allthingslinux.workers.dev 38d50861-9213-446c-8167-2416026ae2dd Preview: tux@d5263f89e14d7f1139c2b5279524f97f2c307854 on 1128/merge by meatsnails (run 231)

@sentry
Copy link

sentry bot commented Dec 30, 2025

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
421 1 420 69
View the full list of 1 ❄️ flaky test(s)
tests/database/test_database_migrations.py::TestSchemaErrorHandlingThroughService::test_operations_on_disconnected_service

Flake rate in main: 100.00% (Passed 0 times, Failed 2 times)

Stack Traces | 0.009s run time
.venv/lib/python3.13.../sqlalchemy/engine/base.py:143: in __init__
    self._dbapi_connection = engine.raw_connection()
                             ^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/engine/base.py:3309: in raw_connection
    return self.pool.connect()
           ^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/pool/base.py:447: in connect
    return _ConnectionFairy._checkout(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/pool/base.py:1264: in _checkout
    fairy = _ConnectionRecord.checkout(pool)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/pool/base.py:711: in checkout
    rec = pool._do_get()
          ^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/pool/impl.py:177: in _do_get
    with util.safe_reraise():
         ^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/util/langhelpers.py:224: in __exit__
    raise exc_value.with_traceback(exc_tb)
.venv/lib/python3.13.../sqlalchemy/pool/impl.py:175: in _do_get
    return self._create_connection()
           ^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/pool/base.py:388: in _create_connection
    return _ConnectionRecord(self)
           ^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/pool/base.py:673: in __init__
    self.__connect()
.venv/lib/python3.13.../sqlalchemy/pool/base.py:899: in __connect
    with util.safe_reraise():
         ^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/util/langhelpers.py:224: in __exit__
    raise exc_value.with_traceback(exc_tb)
.venv/lib/python3.13.../sqlalchemy/pool/base.py:895: in __connect
    self.dbapi_connection = connection = pool._invoke_creator(self)
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/engine/create.py:661: in connect
    return dialect.connect(*cargs, **cparams)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/engine/default.py:630: in connect
    return self.loaded_dbapi.connect(*cargs, **cparams)  # type: ignore[no-any-return]  # NOQA: E501
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../dialects/postgresql/psycopg.py:812: in connect
    await_only(creator_fn(*arg, **kw))
.venv/lib/python3.13.../sqlalchemy/util/_concurrency_py3k.py:132: in await_only
    return current.parent.switch(awaitable)  # type: ignore[no-any-return,attr-defined] # noqa: E501
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/util/_concurrency_py3k.py:196: in greenlet_spawn
    value = await result
            ^^^^^^^^^^^^
.venv/lib/python3.13....../site-packages/psycopg/connection_async.py:145: in connect
    raise type(last_ex)("\n".join(lines)).with_traceback(None)
E   psycopg.OperationalError: connection failed: connection to server at "127.0.0.1", port 5432 failed: Connection refused
E   	Is the server running on that host and accepting TCP/IP connections?
E   Multiple connection attempts failed. All failures were:
E   - host: 'localhost', port: 5432, hostaddr: '::1': connection failed: connection to server at "::1", port 5432 failed: Connection refused
E   	Is the server running on that host and accepting TCP/IP connections?
E   - host: 'localhost', port: 5432, hostaddr: '127.0.0.1': connection failed: connection to server at "127.0.0.1", port 5432 failed: Connection refused
E   	Is the server running on that host and accepting TCP/IP connections?

The above exception was the direct cause of the following exception:
tests/database/test_database_migrations.py:310: in test_operations_on_disconnected_service
    await guild_controller.create_guild(guild_id=TEST_GUILD_ID)
.../database/controllers/guild.py:67: in create_guild
    return await self.create(id=guild_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.../controllers/base/base_controller.py:141: in create
    return await self._crud.create(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.../controllers/base/crud.py:43: in create
    await session.commit()
.venv/lib/python3.13.../ext/asyncio/session.py:1000: in commit
    await greenlet_spawn(self.sync_session.commit)
.venv/lib/python3.13.../sqlalchemy/util/_concurrency_py3k.py:201: in greenlet_spawn
    result = context.throw(*sys.exc_info())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/orm/session.py:2030: in commit
    trans.commit(_to_root=True)
<string>:2: in commit
    ???
.venv/lib/python3.13.../sqlalchemy/orm/state_changes.py:137: in _go
    ret_value = fn(self, *arg, **kw)
                ^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/orm/session.py:1311: in commit
    self._prepare_impl()
<string>:2: in _prepare_impl
    ???
.venv/lib/python3.13.../sqlalchemy/orm/state_changes.py:137: in _go
    ret_value = fn(self, *arg, **kw)
                ^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/orm/session.py:1286: in _prepare_impl
    self.session.flush()
.venv/lib/python3.13.../sqlalchemy/orm/session.py:4331: in flush
    self._flush(objects)
.venv/lib/python3.13.../sqlalchemy/orm/session.py:4466: in _flush
    with util.safe_reraise():
         ^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/util/langhelpers.py:224: in __exit__
    raise exc_value.with_traceback(exc_tb)
.venv/lib/python3.13.../sqlalchemy/orm/session.py:4427: in _flush
    flush_context.execute()
.venv/lib/python3.13.../sqlalchemy/orm/unitofwork.py:466: in execute
    rec.execute(self)
.venv/lib/python3.13.../sqlalchemy/orm/unitofwork.py:642: in execute
    util.preloaded.orm_persistence.save_obj(
.venv/lib/python3.13.../sqlalchemy/orm/persistence.py:68: in save_obj
    ) in _organize_states_for_save(base_mapper, states, uowtransaction):
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/orm/persistence.py:223: in _organize_states_for_save
    for state, dict_, mapper, connection in _connections_for_states(
.venv/lib/python3.13.../sqlalchemy/orm/persistence.py:1759: in _connections_for_states
    connection = uowtransaction.transaction.connection(base_mapper)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
<string>:2: in connection
    ???
.venv/lib/python3.13.../sqlalchemy/orm/state_changes.py:137: in _go
    ret_value = fn(self, *arg, **kw)
                ^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/orm/session.py:1037: in connection
    return self._connection_for_bind(bind, execution_options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
<string>:2: in _connection_for_bind
    ???
.venv/lib/python3.13.../sqlalchemy/orm/state_changes.py:137: in _go
    ret_value = fn(self, *arg, **kw)
                ^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/orm/session.py:1173: in _connection_for_bind
    conn = self._parent._connection_for_bind(
<string>:2: in _connection_for_bind
    ???
.venv/lib/python3.13.../sqlalchemy/orm/state_changes.py:137: in _go
    ret_value = fn(self, *arg, **kw)
                ^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/orm/session.py:1187: in _connection_for_bind
    conn = bind.connect()
           ^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/engine/base.py:3285: in connect
    return self._connection_cls(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/engine/base.py:145: in __init__
    Connection._handle_dbapi_exception_noconnection(
.venv/lib/python3.13.../sqlalchemy/engine/base.py:2448: in _handle_dbapi_exception_noconnection
    raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
.venv/lib/python3.13.../sqlalchemy/engine/base.py:143: in __init__
    self._dbapi_connection = engine.raw_connection()
                             ^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/engine/base.py:3309: in raw_connection
    return self.pool.connect()
           ^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/pool/base.py:447: in connect
    return _ConnectionFairy._checkout(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/pool/base.py:1264: in _checkout
    fairy = _ConnectionRecord.checkout(pool)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/pool/base.py:711: in checkout
    rec = pool._do_get()
          ^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/pool/impl.py:177: in _do_get
    with util.safe_reraise():
         ^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/util/langhelpers.py:224: in __exit__
    raise exc_value.with_traceback(exc_tb)
.venv/lib/python3.13.../sqlalchemy/pool/impl.py:175: in _do_get
    return self._create_connection()
           ^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/pool/base.py:388: in _create_connection
    return _ConnectionRecord(self)
           ^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/pool/base.py:673: in __init__
    self.__connect()
.venv/lib/python3.13.../sqlalchemy/pool/base.py:899: in __connect
    with util.safe_reraise():
         ^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/util/langhelpers.py:224: in __exit__
    raise exc_value.with_traceback(exc_tb)
.venv/lib/python3.13.../sqlalchemy/pool/base.py:895: in __connect
    self.dbapi_connection = connection = pool._invoke_creator(self)
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/engine/create.py:661: in connect
    return dialect.connect(*cargs, **cparams)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/engine/default.py:630: in connect
    return self.loaded_dbapi.connect(*cargs, **cparams)  # type: ignore[no-any-return]  # NOQA: E501
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../dialects/postgresql/psycopg.py:812: in connect
    await_only(creator_fn(*arg, **kw))
.venv/lib/python3.13.../sqlalchemy/util/_concurrency_py3k.py:132: in await_only
    return current.parent.switch(awaitable)  # type: ignore[no-any-return,attr-defined] # noqa: E501
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13.../sqlalchemy/util/_concurrency_py3k.py:196: in greenlet_spawn
    value = await result
            ^^^^^^^^^^^^
.venv/lib/python3.13....../site-packages/psycopg/connection_async.py:145: in connect
    raise type(last_ex)("\n".join(lines)).with_traceback(None)
E   sqlalchemy.exc.OperationalError: (psycopg.OperationalError) connection failed: connection to server at "127.0.0.1", port 5432 failed: Connection refused
E   	Is the server running on that host and accepting TCP/IP connections?
E   Multiple connection attempts failed. All failures were:
E   - host: 'localhost', port: 5432, hostaddr: '::1': connection failed: connection to server at "::1", port 5432 failed: Connection refused
E   	Is the server running on that host and accepting TCP/IP connections?
E   - host: 'localhost', port: 5432, hostaddr: '127.0.0.1': connection failed: connection to server at "127.0.0.1", port 5432 failed: Connection refused
E   	Is the server running on that host and accepting TCP/IP connections?
E   (Background on this error at: https://sqlalche..../e/20/e3q8)

To view more test analytics, go to the [Prevent Tests Dashboard](https://All Things Linux.sentry.io/prevent/tests/?preventPeriod=30d&integratedOrgName=allthingslinux&repository=tux&branch=fix%2Fharmfulcommands)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/tux/plugins/atl/harmfulcommands.py (1)

31-31: Pre-existing typo: "rooin" should likely be "root".

The critical paths list includes "rooin", which appears to be a typo for "root" (the root user's home directory). This is pre-existing and not introduced by this PR, but worth correcting in a follow-up.

🔎 Proposed fix
-    r"/(?:bin|boot|etc|lib|proc|rooin|sys|tmp|usr|var(?:/log)?|network\.|system))"
+    r"/(?:bin|boot|etc|lib|proc|root|sys|tmp|usr|var(?:/log)?|network\.|system))"
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cf93d12 and abdb462.

📒 Files selected for processing (1)
  • src/tux/plugins/atl/harmfulcommands.py
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Use strict type hints with Type | None instead of Optional[Type]
Use NumPy docstrings for documenting functions and classes
Prefer absolute imports; relative imports allowed only within the same module
Organize imports in order: stdlib → third-party → local
Use 88 character line length
Use snake_case for functions and variables, PascalCase for classes, UPPER_CASE for constants
Always add imports to the top of the file unless absolutely necessary
Use async/await for I/O operations
Use custom exceptions for business logic with context logging and meaningful user messages
Use Pydantic for data validation
Keep files to a maximum of 1600 lines
Use one class or function per file when possible
Use descriptive filenames
Add appropriate logging to services and error handlers

Files:

  • src/tux/plugins/atl/harmfulcommands.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Run All Tests (3.13.8)
  • GitHub Check: Sourcery review
  • GitHub Check: Seer Code Review
🔇 Additional comments (2)
src/tux/plugins/atl/harmfulcommands.py (2)

25-25: Word boundary improvement is solid.

Adding \b around rm prevents false positives from words containing "rm" (e.g., "form", "harm", "firmware") while still correctly matching all valid rm command invocations. This improves the pattern's precision.


29-29: Relative path detection correctly addresses issue #1125.

The added pattern \.(?:/|\.)\s* successfully detects dangerous commands with relative paths like ./ and .., resolving the bypass where "sudo rm -rf ./*" was not being caught.

Minor edge case: The pattern does not match a bare . (single dot), so rm -rf . would not be detected. However, this is less critical since it attempts to remove the current directory itself, which typically fails, and is far less commonly used than ./* or ../* patterns.

Given that this addresses the primary issue identified in #1125, this is acceptable.

r"(?:-[frR]+|--force|--recursive|--no-preserve-root|\s+)*"
# Root/home indicators
r"(?:[/\∕~]\s*|\*|" # noqa: RUF001
r"(?:[/\∕~]\s*|\.(?:/|\.)\s*|\*|" # noqa: RUF001

This comment was marked as outdated.

@kzndotsh kzndotsh merged commit 343c3be into main Dec 30, 2025
27 checks passed
@kzndotsh kzndotsh deleted the fix/harmfulcommands branch December 30, 2025 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warning bypass

3 participants