Skip to content

new_get_auth() fails to authenticate against Xauthority entries with an empty display number under Wayland/XWayland #294

Description

@qwanzaden

So, I am a human/programmer. But this bug/report was found/written by ChatGPT. What ChatGPT did fixed my issue so my current understanding is it is legitimate. But, its somewhat over my head. You have my sincere apology for wasting your time if this is actually bogus.

Environment

  • Ubuntu 26.04 LTS
  • Wayland session with XWayland
  • Python 3.14.x
  • python-xlib 0.33
  • DISPLAY=:0
  • Xauthority file provided by Mutter/XWayland via $XAUTHORITY

Description

python-xlib is unable to connect to the local XWayland display because new_get_auth() does not find the authentication entry in the Xauthority file.

The Xauthority file contains entries whose display-number field is empty:

family=256   addr=<hostname>   num=b''
family=65535 addr=<hostname>   num=b''

However, unix_connect.new_get_auth() ultimately calls Xauthority.get_best_auth() with display number 0, which is converted to b'0'. Consequently, the entries with num=b'' are not matched and new_get_auth() returns empty authentication credentials.

The result is:

Xlib.error.DisplayConnectionError:
Can't connect to display ":0":
b'Authorization required, but no authorization protocol specified'

Reproduction

With the normal environment:

echo $XDG_SESSION_TYPE
# wayland

echo $DISPLAY
# :0

echo $XAUTHORITY
# /run/user/1000/.mutter-Xwaylandauth.<...>

This fails:

python3 -c "from Xlib import display; d=display.Display(); print(d.get_display_name())"

with an authorization error.

The Xauthority file can be parsed successfully with Xlib.xauth, but its entries have an empty display-number field.

Interestingly, other X clients work correctly. For example:

xeyes

works, and:

python3 -c "import tkinter; r=tkinter.Tk(); print('X connection works'); r.destroy()"

also works.

The Unix X socket itself is accessible:

/tmp/.X11-unix/X0

Additional observation

The old xauth-based authentication path is able to locate the cookie:

old_get_auth(...)

returns the correct MIT-MAGIC-COOKIE-1 cookie, but the implementation in that path converts the hexadecimal cookie to a Python str rather than raw bytes. Using bytes.fromhex() instead allows the Xlib connection to succeed:

auth_name = parts[1].encode()
auth_data = bytes.fromhex(parts[2])
return auth_name, auth_data

With that modification, this succeeds:

from Xlib import display
d = display.Display()
print(d.get_display_name())

and prints:

:0

Relevance to 0.32

The 0.32 changelog says:

Fix for auth entry having no display number

This appears closely related to the problem described above, but the problem is still reproducible with python-xlib 0.33 on this system.

I am therefore wondering whether this is an unhandled variant of the no-display-number case, or whether the 0.32 fix does not apply to Xauthority files generated by Mutter/XWayland.

The actual Xauthority cookie is omitted from this report.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions