So first, I realize that this question is slightly out of the ordinary for this site. I will explain the backstory to avoid the XY problem.
Over on Programming Puzzles and Code Golf, lots of users (especially me) like to answer programming challenges using vim, and since vim is great at manipulating strings, it does pretty well as a "Programming language" of sorts. However, testing these answers is a little bit of a pain. I've written 100+ keystroke answers in vim before, and actually typing this out to test it is a pain. Also, sometimes users who aren't as familiar with vim will make mistakes like pressing <C-a> instead of ctrl+a, or not starting vim with
vim -u NONE -i NONE which can cause issues with mappings and registers.
So to remedy this, I'm working on a "vim interpreter" that you can run in your browser. You can enter in a sequence of keystrokes, such as
iHello<esc>Yp, and the browser will display the text
But this creates a security hole. A malicious user could enter something like
to get a listing of files and directories on the server, and then something like
:e /foo/somefile.txt dG:wq<cr>
To wipe out files. To get around this, initially I tried sourcing the following script before running the interpreter:
au BufReadPre * :q! au BufWritePre * :q!
and calling neovim with
to disable shell access.
However, then I found out the user could still enter
:noautocmd e /foo/somefile.txt
So I added this to the script:
cmap noautocmd q!<cr> cmap noa q!<cr>
But, a user can still get around this with
g<bs> to get around 'noa' being remapped as you type it)
So I added
cmap cu q!<cr> cmap cunmap q!<cr>
This works as far as I know, but it feels like I'm just polishing poop and adding duct tape. So my two questions are
Is my current method secure, or are there ways to get around what I have right now?
Is there a better way to accomplish this? If this is a linux-based solution (the server is running ubuntu), rather than a vim-based solution, that's okay I guess, but since I don't own the server it will be running on, I'd rather have it be a vim-based solution, since I'm more in control of that and it's less work on the server-owner's part.