-
-
Notifications
You must be signed in to change notification settings - Fork 203
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -311,6 +311,20 @@ xdp_session_authorize_callback (GDBusInterfaceSkeleton *interface, | |||||
return TRUE; | ||||||
} | ||||||
|
||||||
static gboolean | ||||||
is_valid_token(const char *token) | ||||||
{ | ||||||
int i; | ||||||
|
||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is being used in object paths, 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could validate that the result of
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If our only functional requirement is "can we append it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return FALSE; | ||||||
} | ||||||
|
||||||
return TRUE; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This implementation would return true for the empty string, but (We are probably appending it to some string in the |
||||||
} | ||||||
|
||||||
static gboolean | ||||||
xdp_session_initable_init (GInitable *initable, | ||||||
GCancellable *cancellable, | ||||||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
{ | ||||||
g_set_error (error, | ||||||
XDG_DESKTOP_PORTAL_ERROR, | ||||||
XDG_DESKTOP_PORTAL_ERROR_INVALID_ARGUMENT, | ||||||
"Invalid token '%s'", session->token); | ||||||
return FALSE; | ||||||
} | ||||||
|
||||||
id = g_strdup_printf ("/org/freedesktop/portal/desktop/session/%s/%s", | ||||||
sender_escaped, session->token); | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,19 @@ def test_remote_desktop_create_close_session(self, portals, dbus_con): | |
session.close() | ||
xdp.wait_for(lambda: session.closed) | ||
|
||
def test_remote_desktop_create_session_invalid(self, portals, dbus_con): | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Please can we specifically test
|
||
|
||
with pytest.raises(dbus.exceptions.DBusException) as excinfo: | ||
request.call("CreateSession", options=options) | ||
Comment on lines
+55
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ohh, that's nice |
||
|
||
e = excinfo.value | ||
assert e.get_dbus_name() == "org.freedesktop.portal.Error.InvalidArgument" | ||
assert "Invalid token" in e.get_dbus_message() | ||
|
||
@pytest.mark.parametrize( | ||
"template_params", ({"remotedesktop": {"force-close": 500}},) | ||
) | ||
|
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.