Skip to content

Commit 685a7f9

Browse files
committed
extra security precaution
1 parent e6d4f8e commit 685a7f9

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎v3/pg_logger.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,19 @@ def _runscript(self, script_str):
710710
# (at least on my Webfaction hosting with Python 2.7)
711711
#resource.setrlimit(resource.RLIMIT_FSIZE, (0, 0)) # (redundancy for paranoia)
712712

713+
# sys.modules contains an in-memory cache of already-loaded
714+
# modules, so if you delete modules from here, they will
715+
# need to be re-loaded from the filesystem.
716+
#
717+
# Thus, as an extra precaution, remove these modules so that
718+
# they can't be re-imported without opening a new file,
719+
# which is disallowed by resource.RLIMIT_NOFILE
720+
#
721+
# Of course, this isn't a foolproof solution by any means,
722+
# and it might lead to UNEXPECTED FAILURES later in execution.
723+
del sys.modules['os']
724+
del sys.modules['sys']
725+
713726
self.run(script_str, user_globals, user_globals)
714727
# sys.exit ...
715728
except SystemExit:

0 commit comments

Comments
 (0)