mirror of
https://github.com/ben-grande/qusal.git
synced 2025-02-08 19:08:32 -05:00
fix: unstrusted input marking and sanitization
This commit is contained in:
parent
5e3c790111
commit
10b3bcdf41
@ -6,53 +6,61 @@
|
|||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
base_path="$HOME/src"
|
|
||||||
repo="$QREXEC_SERVICE_ARGUMENT"
|
|
||||||
#origin="$QREXEC_REMOTE_DOMAIN"
|
|
||||||
|
|
||||||
die(){
|
die(){
|
||||||
echo "error: $1" >&2
|
echo "error: ${1}" >&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
fail_invalid_name(){
|
|
||||||
if ! (echo "$repo" | grep -q "^[A-Za-z0-9][A-Za-z0-9_.-]\+$"); then
|
|
||||||
die "Invalid repository. Allowed chars: letters, numbers, hyphen, underscore and dot. It cannot begin with hyphen, underscore or dot."
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
if ! command -v git >/dev/null; then
|
if ! command -v git >/dev/null; then
|
||||||
die "Command not found: git"
|
die "Command not found: git"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fail_invalid_name
|
untrusted_repo="${QREXEC_SERVICE_ARGUMENT}"
|
||||||
case "$repo" in
|
|
||||||
|
if test -z "${untrusted_repo}"; then
|
||||||
|
die "Repository name is empty"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! (echo "${untrusted_repo}" | grep -q "^[A-Za-z0-9][A-Za-z0-9_.-]\+$")
|
||||||
|
then
|
||||||
|
die "Forbidden characters in repository name. Allowed chars: letters, numbers, hyphen, underscore and dot. It cannot begin with hyphen, underscore or dot"
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Length arbitrarily set.
|
||||||
|
if test "${#untrusted_repo}" -gt 128; then
|
||||||
|
die "Repository name is too long: ${#untrusted_repo}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
base_path="$HOME/src"
|
||||||
|
repo="${untrusted_repo}"
|
||||||
|
|
||||||
|
case "${repo}" in
|
||||||
*".git") ;;
|
*".git") ;;
|
||||||
*) repo="$repo.git";;
|
*) repo="${repo}.git";;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
path="$base_path/$repo"
|
path="${base_path}/${repo}"
|
||||||
action="${0##*.Git}"
|
action="${0##*.Git}"
|
||||||
|
|
||||||
case "$action" in
|
case "${action}" in
|
||||||
Fetch) service=git-upload-pack;;
|
Fetch) service=git-upload-pack;;
|
||||||
Push) service=git-receive-pack;;
|
Push) service=git-receive-pack;;
|
||||||
Init) service="git init --bare";;
|
Init) service="git init --bare";;
|
||||||
*) die "Invalid RPC name: ${0##*/}";;
|
*) die "Invalid RPC name: ${0##*/}";;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if test "$action" != "Init"; then
|
if test "${action}" != "Init"; then
|
||||||
test -d "$path" || die "Directory doesn't exist: $repo"
|
test -d "${path}" || die "Directory doesn't exist: ${repo}"
|
||||||
git -C "$path" rev-parse >/dev/null 2>&1 || die "Not a git repository: $repo"
|
git -C "${path}" rev-parse >/dev/null 2>&1 || die "Not a git repository: ${repo}"
|
||||||
is_bare="$(git -C "$path" rev-parse --is-bare-repository)"
|
is_bare="$(git -C "${path}" rev-parse --is-bare-repository)"
|
||||||
test "${is_bare}" = "true" || die "Not a bare repository: $repo"
|
test "${is_bare}" = "true" || die "Not a bare repository: ${repo}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! test -d "$base_path"; then
|
if ! test -d "${base_path}"; then
|
||||||
# shellcheck disable=SC2174
|
# shellcheck disable=SC2174
|
||||||
mkdir -m 0700 -p "$base_path" >/dev/null 2>&1 ||
|
mkdir -m 0700 -p "${base_path}" >/dev/null 2>&1 ||
|
||||||
die "Cannot create directory: $base_path"
|
die "Cannot create directory: ${base_path}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
exec $service -- "$path"
|
exec ${service} -- "${path}"
|
||||||
|
@ -6,9 +6,25 @@
|
|||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
#origin="$QREXEC_REMOTE_DOMAIN"
|
untrusted_agent="$QREXEC_SERVICE_ARGUMENT"
|
||||||
agent="$QREXEC_SERVICE_ARGUMENT"
|
|
||||||
|
if test -z "${untrusted_agent}"; then
|
||||||
|
echo "Agent name is empty" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! (echo "${untrusted_agent}" | grep -q "^[A-Za-z0-9][A-Za-z0-9_.-]\+$")
|
||||||
|
then
|
||||||
|
die "Forbidden characters in agent name. Allowed chars: letters, numbers, hyphen, underscore and dot. It cannot begin with hyphen, underscore or dot"
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Length arbitrarily set.
|
||||||
|
if test "${#untrusted_agent}" -gt 128; then
|
||||||
|
die "Repository name is too long: ${#untrusted_agent}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
agent="${untrusted_agent}"
|
||||||
socket="/tmp/qubes-ssh-agent/${agent}.sock"
|
socket="/tmp/qubes-ssh-agent/${agent}.sock"
|
||||||
|
|
||||||
qvm-ssh-agent add "${agent}" >/dev/null
|
qvm-ssh-agent add "${agent}" >/dev/null
|
||||||
exec socat STDIO UNIX-CLIENT:"$socket"
|
exec socat STDIO UNIX-CLIENT:"${socket}"
|
||||||
|
@ -4,4 +4,6 @@
|
|||||||
#
|
#
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
exec socat STDIO TCP:localhost:22000
|
exec socat STDIO TCP:localhost:22000
|
||||||
|
Loading…
x
Reference in New Issue
Block a user