fix: unstrusted input marking and sanitization

This commit is contained in:
Ben Grande 2023-11-21 14:57:47 +00:00
parent 6314658c23
commit 5e53ed259f
No known key found for this signature in database
GPG key ID: 00C64E14F51F9E56
3 changed files with 54 additions and 28 deletions

View file

@ -6,9 +6,25 @@
set -eu
#origin="$QREXEC_REMOTE_DOMAIN"
agent="$QREXEC_SERVICE_ARGUMENT"
untrusted_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"
qvm-ssh-agent add "${agent}" >/dev/null
exec socat STDIO UNIX-CLIENT:"$socket"
exec socat STDIO UNIX-CLIENT:"${socket}"