Added restrict_file_access to becommands' execute() args.
authorW. Trevor King <wking@drexel.edu>
Sat, 21 Nov 2009 20:18:02 +0000 (15:18 -0500)
committerW. Trevor King <wking@drexel.edu>
Sat, 21 Nov 2009 20:18:02 +0000 (15:18 -0500)
+ associated adjustments in other files.

See cmdutil.restrict_file_access.__doc__ for an explanation of the
security hole this closes.

26 files changed:
README.dev
becommands/assign.py
becommands/close.py
becommands/comment.py
becommands/commit.py
becommands/depend.py
becommands/diff.py
becommands/email_bugs.py
becommands/help.py
becommands/html.py
becommands/import_xml.py
becommands/init.py
becommands/list.py
becommands/merge.py
becommands/new.py
becommands/open.py
becommands/remove.py
becommands/set.py
becommands/severity.py
becommands/show.py
becommands/status.py
becommands/subscribe.py
becommands/tag.py
becommands/target.py
interfaces/email/interactive/be-handle-mail
libbe/cmdutil.py

index ddc3a884707c178070697378ec9a7bd1e64625a3..fb4f4714795f21e11e11ef6db6b66e89a9bb2866 100644 (file)
@@ -10,11 +10,19 @@ To fit into the current framework, your extension module should
 provide the following elements:
   __desc__
     A short string describing the purpose of your plugin
-  execute(args)
+  execute(args, manipulate_encodings=True, restrict_file_access=False)
     The entry function for your plugin.  args is everything from
     sys.argv after the name of your plugin (e.g. for the command
     `be open abc', args=['abc']).
 
+    manipulate_encodings should be passed through to any calls to
+    bugdir.BugDir().  See the BugDir documentation for details.
+    
+    If restrict_file_access==True, you should call
+      cmdutil.restrict_file_access(bugdir, path)
+    before attempting to read or write a file.  See the
+    restrict_file_access documentation for details.
+
     Note: be supports command-completion.  To avoid raising errors you
     need to deal with possible '--complete' options and arguments.
     See the 'Command completion' section below for more information.
index 31aa6076e834aeeb4f4876a515d6e524665cbd12..2c78f69a1b09d0b10847d09f06d8ad447ecb359c 100644 (file)
@@ -21,7 +21,7 @@
 from libbe import cmdutil, bugdir
 __desc__ = __doc__
 
-def execute(args, manipulate_encodings=True):
+def execute(args, manipulate_encodings=True, restrict_file_access=False):
     """
     >>> import os
     >>> bd = bugdir.SimpleBugDir()
index d65c4e0e9892b2ba870f7c98b52806ba3beb2838..a14cea8015679b814b5f2a1a91b2d4d31104b2eb 100644 (file)
@@ -21,7 +21,7 @@
 from libbe import cmdutil, bugdir
 __desc__ = __doc__
 
-def execute(args, manipulate_encodings=True):
+def execute(args, manipulate_encodings=True, restrict_file_access=False):
     """
     >>> from libbe import bugdir
     >>> import os
index a600e9fcbdc7c61272d2d735a0265cfcae3f61ec..8e899ce3955643e9c1cc7adc3d397a13b3874f00 100644 (file)
@@ -21,7 +21,7 @@ import os
 import sys
 __desc__ = __doc__
 
-def execute(args, manipulate_encodings=True):
+def execute(args, manipulate_encodings=True, restrict_file_access=False):
     """
     >>> import time
     >>> bd = bugdir.SimpleBugDir()
index b530fdc08ee8c0ec6b08687b30ac5f05fc62af69..39d1e2e9eea7c3c0a0e7c5274bc7d29b361fef68 100644 (file)
@@ -18,7 +18,7 @@ from libbe import cmdutil, bugdir, editor, vcs
 import sys
 __desc__ = __doc__
 
-def execute(args, manipulate_encodings=True):
+def execute(args, manipulate_encodings=True, restrict_file_access=False):
     """
     >>> import os
     >>> from libbe import bug
@@ -49,6 +49,8 @@ def execute(args, manipulate_encodings=True):
     elif options.body == "EDITOR":
         body = editor.editor_string("Please enter your commit message above")
     else:
+        if restrict_file_access == True:
+            cmdutil.restrict_file_access(bd, options.body)
         body = bd.vcs.get_file_contents(options.body, allow_no_vcs=True)
     try:
         revision = bd.vcs.commit(summary, body=body,
index 044aaffdded52b1db84489f9d92bdf21b5f87f0b..f50d693e9efdc9741a655ee7233eadd723ccedfb 100644 (file)
@@ -35,7 +35,7 @@ class BrokenLink (Exception):
         self.blocking_bug = blocking_bug
 
 
-def execute(args, manipulate_encodings=True):
+def execute(args, manipulate_encodings=True, restrict_file_access=False):
     """
     >>> from libbe import utility
     >>> bd = bugdir.SimpleBugDir()
index e71da9b9ae13fa264d0289597708c5afeb8453b3..64779348065cc8f8a44ec239d6476777082b9abc 100644 (file)
@@ -21,7 +21,7 @@ from libbe import cmdutil, bugdir, diff
 import os
 __desc__ = __doc__
 
-def execute(args, manipulate_encodings=True):
+def execute(args, manipulate_encodings=True, restrict_file_access=False):
     """
     >>> import os
     >>> bd = bugdir.SimpleBugDir()
index 27f0b911ead94d16b1a434848a7e549aea5b1c83..d0366df762e8e970f8e6da52285e19e80164702c 100644 (file)
@@ -33,7 +33,7 @@ __desc__ = __doc__
 
 sendmail='/usr/sbin/sendmail -t'
 
-def execute(args, manipulate_encodings=True):
+def execute(args, manipulate_encodings=True, restrict_file_access=False):
     """
     >>> import os
     >>> from libbe import bug
index c12c56a2109032b465848ec7afb1458828a88829..99ab8c4a7151445931b39921c30162cdb57cbec5 100644 (file)
@@ -20,7 +20,7 @@
 from libbe import cmdutil, utility
 __desc__ = __doc__
 
-def execute(args, manipulate_encodings=False):
+def execute(args, manipulate_encodings=True, restrict_file_access=False):
     """
     Print help of specified command (the manipulate_encodings argument
     is ignored).
index b0640da10054103692ed5ccbf82abde504148fe6..622a5312c3ff64a85dccdf7419701234a0df61b8 100644 (file)
@@ -21,7 +21,7 @@ import xml.sax.saxutils, htmlentitydefs
 
 __desc__ = __doc__
 
-def execute(args, manipulate_encodings=True):
+def execute(args, manipulate_encodings=True, restrict_file_access=False):
     """
     >>> import os
     >>> bd = bugdir.SimpleBugDir()
index 928ca467f362d1118c4580625d49348b6d517590..a74d329b1ab325a2e20d7a0725ccdbb4ed0117c2 100644 (file)
@@ -24,7 +24,7 @@ except ImportError: # look for non-core module
     from elementtree import ElementTree
 __desc__ = __doc__
 
-def execute(args, manipulate_encodings=True):
+def execute(args, manipulate_encodings=True, restrict_file_access=False):
     """
     >>> import time
     >>> import StringIO
@@ -69,6 +69,8 @@ def execute(args, manipulate_encodings=True):
     if filename == '-':
         xml = sys.stdin.read()
     else:
+        if restrict_file_access == True:
+            cmdutil.restrict_file_access(bd, options.body)
         xml = bd.vcs.get_file_contents(filename, allow_no_vcs=True)
     str_xml = xml.encode('unicode_escape').replace(r'\n', '\n')
     # unicode read + encode to string so we know the encoding,
index 39fb00613c8e0e67710f0e4bc2ab0ad79170826c..7d6d4753428784078aa12fa71de241d9cd0cd2b0 100644 (file)
@@ -20,7 +20,7 @@ import os.path
 from libbe import cmdutil, bugdir
 __desc__ = __doc__
 
-def execute(args, manipulate_encodings=True):
+def execute(args, manipulate_encodings=True, restrict_file_access=False):
     """
     >>> from libbe import utility, vcs
     >>> import os
index 14e387bc1c51669fac67cd1abba5fc5e826a3240..47117890280910b02e9eb1d3285fac09dc5cab7a 100644 (file)
@@ -26,7 +26,7 @@ __desc__ = __doc__
 AVAILABLE_CMPS = [fn[4:] for fn in dir(bug) if fn[:4] == 'cmp_']
 AVAILABLE_CMPS.remove("attr") # a cmp_* template.
 
-def execute(args, manipulate_encodings=True):
+def execute(args, manipulate_encodings=True, restrict_file_access=False):
     """
     >>> import os
     >>> bd = bugdir.SimpleBugDir()
index 766af56c51fcd6db4ca653c1ba24148d1d325222..31c781f0df579370c3e7a302cba13a99c6aa9c0c 100644 (file)
@@ -19,7 +19,7 @@ from libbe import cmdutil, bugdir
 import os, copy
 __desc__ = __doc__
 
-def execute(args, manipulate_encodings=True):
+def execute(args, manipulate_encodings=True, restrict_file_access=False):
     """
     >>> from libbe import utility
     >>> bd = bugdir.SimpleBugDir()
index 30a7d28ee848fda1eb5097bc584ee83e4b3221b7..92d61e40c3cf225eebace77652dedd08a8f7e6e2 100644 (file)
@@ -20,7 +20,7 @@ from libbe import cmdutil, bugdir
 import sys
 __desc__ = __doc__
 
-def execute(args, manipulate_encodings=True):
+def execute(args, manipulate_encodings=True, restrict_file_access=False):
     """
     >>> import os, time
     >>> from libbe import bug
index 1b4c23e173c66f1738aeb9337e7fb1a7fb4bfe31..c2c15e2918ef5646b1e1988babaa406348895283 100644 (file)
@@ -21,7 +21,7 @@
 from libbe import cmdutil, bugdir
 __desc__ = __doc__
 
-def execute(args, manipulate_encodings=True):
+def execute(args, manipulate_encodings=True, restrict_file_access=False):
     """
     >>> import os
     >>> bd = bugdir.SimpleBugDir()
index d265e5cc3b0327198577606dbfffaa3f2ea16275..e4f006534f1af8627de27f6bbdd471274461c1d0 100644 (file)
@@ -18,7 +18,7 @@
 from libbe import cmdutil, bugdir
 __desc__ = __doc__
 
-def execute(args, manipulate_encodings=True):
+def execute(args, manipulate_encodings=True, restrict_file_access=False):
     """
     >>> from libbe import mapfile
     >>> import os
index e5cab8d89f70859ecc1ed4b31b7a9163d0f6bb87..c8c5a2cab339570ec4fed38aef0c8cc3cac2bd9c 100644 (file)
@@ -32,7 +32,7 @@ def _value_string(bd, setting):
             val = None
     return str(val)
 
-def execute(args, manipulate_encodings=True):
+def execute(args, manipulate_encodings=True, restrict_file_access=False):
     """
     >>> import os
     >>> bd = bugdir.SimpleBugDir()
index f42f740bee2e39b9e2b032be79f07678785c833a..524976beb08a94af47eed2898a7575e07bdfbf58 100644 (file)
@@ -21,7 +21,7 @@
 from libbe import cmdutil, bugdir, bug
 __desc__ = __doc__
 
-def execute(args, manipulate_encodings=True):
+def execute(args, manipulate_encodings=True, restrict_file_access=False):
     """
     >>> import os
     >>> bd = bugdir.SimpleBugDir()
index 11890a812232b857fcd7f1ae213f59b402a4b613..557c63a230ab62f072c2099d41e8fcb39dbbf313 100644 (file)
@@ -22,7 +22,7 @@ import sys
 from libbe import cmdutil, bugdir, comment, version, _version
 __desc__ = __doc__
 
-def execute(args, manipulate_encodings=True):
+def execute(args, manipulate_encodings=True, restrict_file_access=False):
     """
     >>> import os
     >>> bd = bugdir.SimpleBugDir()
index bf66c2649f61b30c1d9765f08acc1a349633fc9d..fd31c97a8fa0fe0c058204857d261e68d82ceda2 100644 (file)
@@ -18,7 +18,7 @@
 from libbe import cmdutil, bugdir, bug
 __desc__ = __doc__
 
-def execute(args, manipulate_encodings=True):
+def execute(args, manipulate_encodings=True, restrict_file_access=False):
     """
     >>> import os
     >>> bd = bugdir.SimpleBugDir()
index 0a23057afe6a326621825425a2bc738691edef4d..051341b50d0712a1c4d971d8730602cf684ada1f 100644 (file)
@@ -55,7 +55,7 @@ class InvalidType (ValueError):
         self.type_root = type_root
 
 
-def execute(args, manipulate_encodings=True):
+def execute(args, manipulate_encodings=True, restrict_file_access=False):
     """
     >>> bd = bugdir.SimpleBugDir()
     >>> bd.set_sync_with_disk(True)
index e6debb41c84b32183b16aeeed5447ae0d4763d02..e22cb70b2c5eba2a0817c3a7ee62708f1e3335bb 100644 (file)
@@ -19,7 +19,7 @@ from libbe import cmdutil, bugdir
 import os, copy
 __desc__ = __doc__
 
-def execute(args, manipulate_encodings=True):
+def execute(args, manipulate_encodings=True, restrict_file_access=False):
     """
     >>> from libbe import utility
     >>> bd = bugdir.SimpleBugDir()
index 672eb06f4a05f6ecd69534fab431b0b19d4cbb72..efb247942d0bb805fa9a8949ac01b143b99cea27 100644 (file)
@@ -22,7 +22,7 @@
 from libbe import cmdutil, bugdir
 __desc__ = __doc__
 
-def execute(args, manipulate_encodings=True):
+def execute(args, manipulate_encodings=True, restrict_file_access=False):
     """
     >>> import os
     >>> bd = bugdir.SimpleBugDir()
index bd37f55a634f79aaf4a213bf4b5adf58a5c31f27..e0e34900b175ee932c312ee10d2e9e5d54dca00d 100755 (executable)
@@ -242,7 +242,8 @@ class Command (object):
         os.chdir(BE_DIR)
         try:
             self.ret = libbe.cmdutil.execute(self.command, self.args,
-                                             manipulate_encodings=False)
+                                             manipulate_encodings=False,
+                                             restrict_file_access=True)
         except libbe.cmdutil.GetHelp:
             print libbe.cmdutil.help(command)
         except libbe.cmdutil.GetCompletions:
index 96430ebdab7c7b94c4d3c4e2188526e247505c48..e37750deb51162e6a1c75ee034fc1d036b5c518b 100644 (file)
@@ -76,11 +76,12 @@ def get_command(command_name):
     return cmd
 
 
-def execute(cmd, args, manipulate_encodings=True):
+def execute(cmd, args, manipulate_encodings=True, restrict_file_access=False):
     enc = encoding.get_encoding()
     cmd = get_command(cmd)
     ret = cmd.execute([a.decode(enc) for a in args],
-                      manipulate_encodings=manipulate_encodings)
+                      manipulate_encodings=manipulate_encodings,
+                      restrict_file_access=restrict_file_access)
     if ret == None:
         ret = 0
     return ret
@@ -213,6 +214,22 @@ def underlined(instring):
     
     return "%s\n%s" % (instring, "="*len(instring))
 
+def restrict_file_access(bugdir, path):
+    """
+    Check that the file at path is inside bugdir.root.  This is
+    important if you allow other users to execute becommands with your
+    username (e.g. if you're running be-handle-mail through your
+    ~/.procmailrc).  If this check wasn't made, a user could e.g.
+    run
+      be commit -b ~/.ssh/id_rsa "Hack to expose ssh key"
+    which would expose your ssh key to anyone who could read the VCS
+    log.
+    """
+    in_root = bugdir.vcs.path_in_root(path, bugdir.root)
+    if in_root == False:
+        raise UserError('file access restricted!\n  %s not in %s'
+                        % (path, bugdir.root))
+
 def parse_id(id):
     """
     Return (bug_id, comment_id) tuple.