Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pr_agent/agent/pr_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from pr_agent.tools.pr_config import PRConfig
from pr_agent.tools.pr_description import PRDescription
from pr_agent.tools.pr_generate_labels import PRGenerateLabels
from pr_agent.tools.pr_help_docs import PRHelpDocs
from pr_agent.tools.pr_help_message import PRHelpMessage
from pr_agent.tools.pr_line_questions import PR_LineQuestions
from pr_agent.tools.pr_questions import PRQuestions
Expand All @@ -40,7 +39,9 @@
"similar_issue": PRSimilarIssue,
"add_docs": PRAddDocs,
"generate_labels": PRGenerateLabels,
"help_docs": PRHelpDocs,
# SECURITY: "/help_docs" is temporarily disabled while the clone-target validation
# fix is reviewed (see issue #2445). Re-enable by restoring `"help_docs": PRHelpDocs`
# and its import once the hardening PR is merged.
}

commands = list(command2class.keys())
Expand Down
25 changes: 25 additions & 0 deletions tests/unittest/test_help_docs_disabled.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pytest

import pr_agent.agent.pr_agent as pr_agent_module

Check notice

Code scanning / CodeQL

Module is imported with 'import' and 'import from' Note test

Module 'pr_agent.agent.pr_agent' is imported with both 'import' and 'import from'.
Comment thread
naorpeled marked this conversation as resolved.
Dismissed
Comment thread
naorpeled marked this conversation as resolved.
Dismissed
from pr_agent.agent.pr_agent import PRAgent, command2class


def test_help_docs_is_not_registered():
"""Security stopgap for issue #2445: the /help_docs command must be disabled
(unregistered) until the clone-target validation fix is merged."""
assert "help_docs" not in command2class
assert "help_docs" not in pr_agent_module.commands


@pytest.mark.asyncio
async def test_help_docs_command_is_not_routed(monkeypatch):
"""An incoming /help_docs command resolves to an unknown command and is rejected."""
monkeypatch.setattr(pr_agent_module, "apply_repo_settings", lambda pr_url: None)
monkeypatch.setattr(pr_agent_module.CliArgs, "validate_user_args", lambda args: (True, ""))
monkeypatch.setattr(pr_agent_module, "update_settings_from_args", lambda args: args)

handled = await PRAgent()._handle_request(
"https://github.com/owner/repo/pull/1",
"/help_docs \"what docs exist\" --pr_help_docs.repo_url=https://github.com/x/y",
)
assert handled is False
Loading