Skip to content

Allowlist the view functions a modeline may call - #21

Merged
Frizlab merged 1 commit into
SublimeText:masterfrom
dpc00:fix/view-function-allowlist
Nov 12, 2026
Merged

Frizlab merged 1 commit into
SublimeText:masterfrom
dpc00:fix/view-function-allowlist

Conversation

@dpc00

@dpc00 dpc00 commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Fixes #20: the default format reaches getattr(view, key)(value) with a key taken from the file, so any sublime.View method could be called on open — including run_command(), which runs an arbitrary command.

What changed

  • app/modeline_instructions/call_view_function.py: apply() refuses any name outside a fixed allowlist — set_encoding, set_line_endings, set_name, set_read_only, set_scratch, set_syntax_file — raising ValueError, which do_modelines() already logs and skips. The other instructions on the same line still apply.
  • Readme.md: documents the restriction.
  • tests/test_sublime_parser.py: two integration tests — a run_command()="insert" modeline leaves the buffer untouched while tab_size=9 on the same line still takes effect, and set_name() still works.

Why an allowlist rather than a blocklist

The shipped VIM/Emacs mappings use exactly two view calls, set_line_endings() and set_encoding(); everything else a modeline declares is a view setting. So the set of methods a modeline has a legitimate reason to call is small and known, while the set it must not reach (run_command, close, show, set_status, …) is open-ended. A blocklist would have to enumerate Sublime's whole view API and keep doing so.

Verification

Sublime Text 4 build 4215 (Python 3.14), the package unpacked in a portable install, package reloaded:

  • /* ~*~ sublime: run_command()="insert"; tab_size=9 ~*~ */ → the buffer holds exactly that one line (58 characters; nothing inserted), and tab_size is 9, so the refused instruction was skipped and the rest of the line applied.
  • /* ~*~ sublime: set_name()="renamed by modeline" ~*~ */ → the view name becomes renamed by modeline, so allowlisted calls are unaffected.

Not run: the repository's UnitTesting suite, which needs UnitTesting installed in that portable. The two tests added are written for it and follow the existing integration-test style.

No shipped mapping changes behaviour: set_line_endings() and set_encoding() are both in the allowlist.

@Frizlab
Frizlab merged commit c6d246d into SublimeText:master Nov 12, 2026
3 checks passed
@Frizlab

Frizlab commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Thank you!

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.

Default modeline format allows calling arbitrary sublime.View methods (getattr(view, key)(value)) from file content, no allowlist

2 participants