Gitea returns a 500 when searching for %00 #90

Closed
opened 2025-11-02 03:08:19 -06:00 by GiteaMirror · 9 comments
Owner

Originally created by @Bwko on GitHub (Nov 28, 2016).

  • Gitea version (or commit ref): 27d66855eb
  • Git version: 2.10.2
  • Operating system: Arch linux
  • Database:
    • PostgreSQL 9.6.1 en_US.utf8
    • MySQL
    • SQLite
  • Log gist: 2016/11/28 23:43:28 [...itea/routers/home.go:93 RenderRepoSearch()] [E] SearchRepositoryByName: Count: pq: invalid byte sequence for encoding "UTF8": 0x00

Go to your local Gitea server, enter %00 behind ?q= (like http://localhost/explore/repos?q=%00) and Gitea returns a 500 error

Originally created by @Bwko on GitHub (Nov 28, 2016). - Gitea version (or commit ref): 27d66855eb642b22852b557cbb8ffd7781d73d4e - Git version: 2.10.2 - Operating system: Arch linux - Database: - [x] PostgreSQL 9.6.1 en_US.utf8 - [ ] MySQL - [ ] SQLite - Log gist: `2016/11/28 23:43:28 [...itea/routers/home.go:93 RenderRepoSearch()] [E] SearchRepositoryByName: Count: pq: invalid byte sequence for encoding "UTF8": 0x00` Go to your local Gitea server, enter %00 behind ?q= (like http://localhost/explore/repos?q=%00) and Gitea returns a 500 error
GiteaMirror added the type/bug label 2025-11-02 03:08:19 -06:00
Author
Owner

@lunny commented on GitHub (Nov 29, 2016):

The error returned by postgres. For Golang,

utf8.ValidString(url.QueryUnescape("%00"))

will return true. but postgres don't think so.

@lunny commented on GitHub (Nov 29, 2016): The error returned by postgres. For Golang, ``` utf8.ValidString(url.QueryUnescape("%00")) ``` will return true. but postgres don't think so.
Author
Owner

@tboerger commented on GitHub (Nov 29, 2016):

Should we add a list of strings that get stripped before sending to the db?

@tboerger commented on GitHub (Nov 29, 2016): Should we add a list of strings that get stripped before sending to the db?
Author
Owner

@lunny commented on GitHub (Nov 29, 2016):

Yes, I think maybe we have to write a regex? to limit the keyword.

@lunny commented on GitHub (Nov 29, 2016): Yes, I think maybe we have to write a regex? to limit the keyword.
Author
Owner

@thibaultmeyer commented on GitHub (Nov 29, 2016):

a regexp to avoid all non-printable chars could be useful. Of maybe is the job of the ORM to sanitize data before send it to SQL server ?

@thibaultmeyer commented on GitHub (Nov 29, 2016): a regexp to avoid all non-printable chars could be useful. Of maybe is the job of the ORM to sanitize data before send it to SQL server ?
Author
Owner

@lunny commented on GitHub (Nov 29, 2016):

Sounds reasonable. Maybe it's the database/sql drivers' work :)

@lunny commented on GitHub (Nov 29, 2016): Sounds reasonable. Maybe it's the `database/sql` drivers' work :)
Author
Owner
@bkcsoft commented on GitHub (Nov 29, 2016): It's a limitation in PostgreSQL http://stackoverflow.com/questions/28813409/are-null-bytes-allowed-in-unicode-strings-in-postgresql-via-python https://www.postgresql.org/message-id/4A271678.6010405@postnewspapers.com.au
Author
Owner

@Bwko commented on GitHub (Nov 29, 2016):

@lunny could you fix this?

@Bwko commented on GitHub (Nov 29, 2016): @lunny could you fix this?
Author
Owner

@lunny commented on GitHub (Nov 30, 2016):

Just ignoring %00 could fix this bug. But if there are other characters will result in 500?

@lunny commented on GitHub (Nov 30, 2016): Just ignoring `%00` could fix this bug. But if there are other characters will result in 500?
Author
Owner

@Bwko commented on GitHub (Nov 30, 2016):

To my knowledge %00 are the only characters that result in a 500

@Bwko commented on GitHub (Nov 30, 2016): To my knowledge `%00` are the only characters that result in a 500
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#90