mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
gitweb: Validate repository name also in actions script
This prevents writing to an arbitrary directory if running actions script as a root user. - Included tests for invalid names Signed-off-by: Veiko Aasa <veiko17@disroot.org> [sunil@medhas.org Parametrize the test case] Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
1 parent
0b2d1265cb
commit
ba9869c030
3 files changed
+39
-5
No files matched your search
@@ -27,6 +27,7 @@ import shutil
|
||||
import subprocess
|
||||
|
||||
from plinth import action_utils
|
||||
from plinth.modules.gitweb.forms import validate_repository
|
||||
from plinth.modules.gitweb.manifest import GIT_REPO_PATH
|
||||
|
||||
|
||||
@@ -168,6 +169,8 @@ def _set_access_status(repo, status):
|
||||
|
||||
def subcommand_rename_repo(arguments):
|
||||
"""Rename a repository."""
|
||||
validate_repository(arguments.oldname)
|
||||
validate_repository(arguments.newname)
|
||||
oldpath = os.path.join(GIT_REPO_PATH, arguments.oldname + '.git')
|
||||
newpath = os.path.join(GIT_REPO_PATH, arguments.newname + '.git')
|
||||
os.rename(oldpath, newpath)
|
||||
@@ -175,21 +178,25 @@ def subcommand_rename_repo(arguments):
|
||||
|
||||
def subcommand_set_repo_description(arguments):
|
||||
"""Set description of the repository."""
|
||||
validate_repository(arguments.name)
|
||||
_set_repo_description(arguments.name, arguments.description)
|
||||
|
||||
|
||||
def subcommand_set_repo_owner(arguments):
|
||||
"""Set repository's owner name."""
|
||||
validate_repository(arguments.name)
|
||||
_set_repo_owner(arguments.name, arguments.owner)
|
||||
|
||||
|
||||
def subcommand_set_repo_access(arguments):
|
||||
"""Set repository's access status."""
|
||||
validate_repository(arguments.name)
|
||||
_set_access_status(arguments.name, arguments.access)
|
||||
|
||||
|
||||
def subcommand_repo_info(arguments):
|
||||
"""Get information about repository."""
|
||||
validate_repository(arguments.name)
|
||||
repo_path = os.path.join(GIT_REPO_PATH, arguments.name + '.git')
|
||||
if not os.path.exists(repo_path):
|
||||
raise RuntimeError('Repository not found')
|
||||
@@ -203,6 +210,7 @@ def subcommand_repo_info(arguments):
|
||||
|
||||
def subcommand_create_repo(arguments):
|
||||
"""Create a new git repository."""
|
||||
validate_repository(arguments.name)
|
||||
os.chdir(GIT_REPO_PATH)
|
||||
repo_name = arguments.name + '.git'
|
||||
subprocess.check_call(['git', 'init', '--bare', repo_name])
|
||||
@@ -216,6 +224,7 @@ def subcommand_create_repo(arguments):
|
||||
|
||||
def subcommand_delete_repo(arguments):
|
||||
"""Delete a git repository."""
|
||||
validate_repository(arguments.name)
|
||||
repo_path = os.path.join(GIT_REPO_PATH, arguments.name + '.git')
|
||||
shutil.rmtree(repo_path)
|
||||
|
||||
|
||||
Reference in new issue
Block a user