-
-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
session: Validate the token for correctness #1562
base: main
Are you sure you want to change the base?
Conversation
3cd75da
to
ad83903
Compare
The token is used as part of an object path so it has to meet those requirements. We can't escape it since the caller presumably expects to use the token as-is so where it fails the validity simply error out. Closes: flatpak#1549
ad83903
to
2d68212
Compare
with pytest.raises(dbus.exceptions.DBusException) as excinfo: | ||
request.call("CreateSession", options=options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohh, that's nice
|
||
for (i = 0; token[i]; i++) | ||
{ | ||
if (!g_ascii_isalnum(token[i]) && token[i] != '_') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is _
a valid token? Doesn't gdbus already provide something like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is being used in object paths, https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-marshaling-object-path is the canonical specification.
gdbus probably doesn't have a function for "is this a valid object-path element?", though, just "is this a valid complete object path?" (which is g_variant_is_object_path()
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could validate that the result of g_strdup_printf ("/foo/%s", token)
is a valid object path, which I think is what we actually require. That's pretty ugly, but is it less ugly than open-coding validation? I don't know.
g_dbus_is_member_name()
is almost right, but member names are not allowed to start with digits, whereas object path elements are, so using that would be unnecessarily restrictive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
_
a valid token?
If our only functional requirement is "can we append it to /blah/blah/
and get a valid object path?" then yes it is.
return FALSE; | ||
} | ||
|
||
return TRUE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation would return true for the empty string, but "/blah/blah/" + ""
is not a syntactically valid object path (an object path must not end with /
unless it is exactly /
). So we must check for that.
(We are probably appending it to some string in the /org/freedesktop/...
namespace rather than literally /foo/
or /blah/blah/
, but it's the "shape" that matters.)
|
||
for (i = 0; token[i]; i++) | ||
{ | ||
if (!g_ascii_isalnum(token[i]) && token[i] != '_') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!g_ascii_isalnum(token[i]) && token[i] != '_') | |
if (!g_ascii_isalnum (token[i]) && token[i] != '_') |
@@ -311,6 +311,20 @@ xdp_session_authorize_callback (GDBusInterfaceSkeleton *interface, | |||
return TRUE; | |||
} | |||
|
|||
static gboolean | |||
is_valid_token(const char *token) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is_valid_token(const char *token) | |
is_valid_token (const char *token) |
@@ -335,6 +349,15 @@ xdp_session_initable_init (GInitable *initable, | |||
return FALSE; | |||
} | |||
|
|||
if (!is_valid_token(session->token)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!is_valid_token(session->token)) | |
if (!is_valid_token (session->token)) |
remotedesktop_intf = xdp.get_portal_iface(dbus_con, "RemoteDesktop") | ||
|
||
request = xdp.Request(dbus_con, remotedesktop_intf) | ||
options = {"session_handle_token": "Invalid-token&"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please can we specifically test "/foo"
and ""
here, too? Those are special cases would be easy to get wrong.
for badness in ("Invalid-token&", "/foo", ""):
options = { "session_handle_token": badness }
with pytest.raises (etc.)
...
The token is used as part of an object path so it has to meet those requirements. We can't escape it since the caller presumably expects to use the token as-is so where it fails the validity simply error out.
Closes: #1549