mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-28 08:03:36 +00:00
ikiwiki: Validate a path when deleting wiki or blog
I tested that ikiwiki functional tests pass and running the command `sudo ./actions/ikiwiki delete --name '../'` returns an error and does not delete any directory. Signed-off-by: Veiko Aasa <veiko17@disroot.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
f0000c4ba3
commit
e2e3768fe1
@ -46,6 +46,11 @@ def parse_arguments():
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def _is_safe_path(basedir, path):
|
||||
"""Return whether a path is safe."""
|
||||
return os.path.realpath(path).startswith(basedir)
|
||||
|
||||
|
||||
def subcommand_setup(_):
|
||||
"""Perform first time setup operations."""
|
||||
setup()
|
||||
@ -106,6 +111,11 @@ def subcommand_delete(arguments):
|
||||
html_folder = os.path.join(SITE_PATH, arguments.name)
|
||||
wiki_folder = os.path.join(WIKI_PATH, arguments.name)
|
||||
|
||||
if not (_is_safe_path(SITE_PATH, html_folder)
|
||||
and _is_safe_path(WIKI_PATH, wiki_folder)):
|
||||
print('Error: {0} is not a correct name.'.format(arguments.name))
|
||||
exit(1)
|
||||
|
||||
try:
|
||||
shutil.rmtree(html_folder)
|
||||
shutil.rmtree(wiki_folder)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user