Repository navigation
Allowlist the view functions a modeline may call - #21
Merged
Merged
Conversation
Collaborator
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #20: the default format reaches
getattr(view, key)(value)with a key taken from the file, so anysublime.Viewmethod could be called on open — includingrun_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— raisingValueError, whichdo_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 — arun_command()="insert"modeline leaves the buffer untouched whiletab_size=9on the same line still takes effect, andset_name()still works.Why an allowlist rather than a blocklist
The shipped VIM/Emacs mappings use exactly two view calls,
set_line_endings()andset_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), andtab_sizeis 9, so the refused instruction was skipped and the rest of the line applied./* ~*~ sublime: set_name()="renamed by modeline" ~*~ */→ the view name becomesrenamed by modeline, so allowlisted calls are unaffected.Not run: the repository's
UnitTestingsuite, which needsUnitTestinginstalled 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()andset_encoding()are both in the allowlist.