Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Giving document.path to dmypy limits the daemon and makes it prone to crash #101

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ Configuration
- ``array`` of ``string`` items
- **The command to run dmypy**. This is useful if you want to run dmypy in a specific virtual environment. Requires env variable ``PYLSP_MYPY_ALLOW_DANGEROUS_CODE_EXECUTION`` to be set.
- ``[]``
* - ``dmypy_project_wide``
- ``pylsp.plugins.pylsp_mypy.dmypy_project_wide``
- ``boolean``
- **Use dmypy in project**. With this option set to false (default) you're telling the daemon to only check specific file(s) given by PYLSP, rather than checking your entire project. The daemon is still watching for all file changes, but you've limited the scope of that particular check.
- false

Both ``mypy_command`` and ``dmypy_command`` could be used by a malicious repo to execute arbitrary code by looking at its source with this plugin active.
Still users want this feature. For security reasons this is disabled by default. If you really want it and accept the risks set the environment variable ``PYLSP_MYPY_ALLOW_DANGEROUS_CODE_EXECUTION`` in order to activate it.
Expand Down
5 changes: 4 additions & 1 deletion pylsp_mypy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ def get_diagnostics(
args.append("--config-file")
args.append(mypyConfigFile)

args.append(document.path)

if settings.get("strict", False):
args.append("--strict")
Expand All @@ -331,6 +330,7 @@ def get_diagnostics(
if not dmypy:
args.extend(["--incremental", "--follow-imports", settings.get("follow-imports", "silent")])
args = apply_overrides(args, overrides)
args.append(document.path)

mypy_command: List[str] = get_cmd(settings, "mypy")

Expand Down Expand Up @@ -359,6 +359,9 @@ def get_diagnostics(

dmypy_command: List[str] = get_cmd(settings, "dmypy")

if not settings.get("dmypy_project_wide", False):
args.append(document.path)

if dmypy_command:
# dmypy exists on PATH or was provided by settings
# -> use this dmypy
Expand Down