element-hq / element-hq/synapse

`/createRoom`: "ValueError: A string literal cannot contain NUL (0x00) characters." when \u0000 is sent in "room_alias_name"

Open
#13,510 0 comments 0 reactions 0 assignees View on GitHub
A-Create-Room A-Validation O-Uncommon S-Tolerable T-Defect
Dominant language
Python
Stars
4.6k
Forks
600
Avg merge
5d 22h
Merged PRs (30d)
51

Description

This issue has been migrated from [#13510](https://github.com/matrix-org/synapse/issues/13510).

---

### Description

`/_matrix/client/v3/createRoom` is crashing with an internal server error when it contains NUL characters.

The request (minimal working example) was made with this content:

```
{"name":"a","room_alias_name":"\u0000","visibility":"public","is_direct":false,"topic":"null_in_room"}
```

This does not seem to actually break anything apart from the crash error and `{"errcode":"M_UNKNOWN","error":"Internal server error"}` as the response.

### Steps to reproduce

- Send a request to `/_matrix/client/v3/createRoom` with `{"name":"a","room_alias_name":"\u0000","visibility":"public","is_direct":false,"topic":"null_in_room"}` as the content
- Watch logs to see it crash

### Homeserver

localhost

### Synapse Version

{"server_version":"1.64.0","python_version":"3.9.13"}

### Installation Method

Docker (matrixdotorg/synapse)

### Platform

Kubernetes with official docker image and redis and postgres

### Relevant log output

```shell
2022-08-11 20:56:19,456 - synapse.http.server - 183 - ERROR - POST-2334- Failed handle request via 'RoomCreateRestServlet':
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/synapse/http/server.py", line 366, in _async_render_wrapper
callback_return = await self._async_render(request)
File "/usr/local/lib/python3.9/site-packages/synapse/http/server.py", line 572, in _async_render
callback_return = await raw_callback_return
File "/usr/local/lib/python3.9/site-packages/synapse/rest/client/room.py", line 91, in on_POST
info, _ = await self._room_creation_handler.create_room(
File "/usr/local/lib/python3.9/site-packages/synapse/handlers/room.py", line 785, in create_room
mapping = await self.store.get_association_from_room_alias(room_alias)
File "/usr/local/lib/python3.9/site-packages/synapse/storage/databases/main/directory.py", line 45, in get_association_from_room_alias
room_id = await self.db_pool.simple_select_one_onecol(
File "/usr/local/lib/python3.9/site-packages/synapse/storage/database.py", line 1614, in simple_select_one_onecol
return await self.runInteraction(
File "/usr/local/lib/python3.9/site-packages/synapse/storage/database.py", line 882, in runInteraction
return await delay_cancellation(_runInteraction())
File "/usr/local/lib/python3.9/site-packages/twisted/internet/defer.py", line 1656, in _inlineCallbacks
result = current_context.run(
File "/usr/local/lib/python3.9/site-packages/twisted/python/failure.py", line 514, in throwExceptionIntoGenerator
return g.throw(self.type, self.value, self.tb)
File "/usr/local/lib/python3.9/site-packages/synapse/storage/database.py", line 849, in _runInteraction
result = await self.runWithConnection(
File "/usr/local/lib/python3.9/site-packages/synapse/storage/database.py", line 977, in runWithConnection
return await make_deferred_yieldable(
File "/usr/local/lib/python3.9/site-packages/twisted/python/threadpool.py", line 244, in inContext
result = inContext.theWork() # type: ignore[attr-defined]
File "/usr/local/lib/python3.9/site-packages/twisted/python/threadpool.py", line 260, in
inContext.theWork = lambda: context.call( # type: ignore[attr-defined]
File "/usr/local/lib/python3.9/site-packages/twisted/python/context.py", line 117, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "/usr/local/lib/python3.9/site-packages/twisted/python/context.py", line 82, in callWithContext
return func(*args, **kw)
File "/usr/local/lib/python3.9/site-packages/twisted/enterprise/adbapi.py", line 282, in _runWithConnection
result = func(conn, *args, **kw)
File "/usr/local/lib/python3.9/site-packages/synapse/storage/database.py", line 970, in inner_func
return func(db_conn, *args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/synapse/storage/database.py", line 711, in new_transaction
r = func(cursor, *args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/synapse/storage/database.py", line 1657, in simple_select_one_onecol_txn
ret = cls.simple_select_onecol_txn(
File "/usr/local/lib/python3.9/site-packages/synapse/storage/database.py", line 1680, in simple_select_onecol_txn
txn.execute(sql, list(keyvalues.values()))
File "/usr/local/lib/python3.9/site-packages/synapse/storage/database.py", line 389, in execute
self._do_execute(self.txn.execute, sql, *args)
File "/usr/local/lib/python3.9/site-packages/synapse/storage/database.py", line 432, in _do_execute
return func(sql, *args, **kwargs)
ValueError: A string literal cannot contain NUL (0x00) characters.
```

### Anything else that would be useful to know?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.