Skip to content
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

Forum returns 5xx when search term includes "(" or ")" #312

Open
adokitkat opened this issue Feb 16, 2022 · 5 comments
Open

Forum returns 5xx when search term includes "(" or ")" #312

adokitkat opened this issue Feb 16, 2022 · 5 comments

Comments

@adokitkat
Copy link

I just noticed last night, if your forum search term includes "(" or ")", the forum will crash, and you will get a Cloudflare bad gateway error. It quickly restarts but this is clearly not supposed to happen.

Source

I have tested it and it really crashes.

@adokitkat
Copy link
Author

This answers the malformed MATCH expression:

https://stackoverflow.com/questions/11708736/sqlite-match-operator

@dom96
Copy link
Contributor

dom96 commented Feb 20, 2022

Wow, this is really interesting. I was wondering how the forum was crashing here, turns out it doesn't. I'm not quite sure why CloudFlare returns a 502 after the search with a "(" but it seems to be browser-local. You can test this yourself by doing the search with "(" in Firefox, waiting as long as you want, opening the forum in Chrome (it will load), then clicking the home button in Firefox (and you'll see the 502 from CloudFlare). I guess maybe CloudFlare is doing some stupid caching here based on the session.

But the forum certainly doesn't crash so the bug ain't that critical :)

@cyraxjoe
Copy link

Definitely there is something going on, testing from curl, I get the error with traceback (unless that is the actual expected behavior).

curl -G  -d q='example (' https://forum.nim-lang.org/search.json
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Jester route exception</title></head><body><h1>An error has occured in one of your routes.</h1><p><b>Detail: </b>/home/dom/nimforum2/src/forum.nim(817) forum<br/>
/home/dom/.nimble/pkgs/jester-#405be2e/jester.nim(493) serve<br/>
/home/dom/.nimble/pkgs/httpbeast-0.4.0/httpbeast.nim(540) run<br/>
/home/dom/.nimble/pkgs/httpbeast-0.4.0/httpbeast.nim(371) eventLoop<br/>
/home/dom/.nimble/pkgs/httpbeast-0.4.0/httpbeast.nim(283) processEvents<br/>
/home/dom/.nimble/pkgs/jester-#405be2e/jester.nim(496) :anonymous<br/>
/home/dom/.nimble/pkgs/jester-#405be2e/jester.nim(398) handleRequest<br/>
/home/dom/Nim/lib/pure/asyncmacro.nim(232) dispatch<br/>
/home/dom/Nim/lib/pure/asyncmacro.nim(28) dispatchNimAsyncContinue<br/>
/home/dom/.nimble/pkgs/jester-#405be2e/jester.nim(297) dispatchIter<br/>
/home/dom/Nim/lib/pure/asyncmacro.nim(232) match<br/>
/home/dom/Nim/lib/pure/asyncmacro.nim(28) matchNimAsyncContinue<br/>
/home/dom/Nim/lib/impure/db_sqlite.nim(337) matchIter<br/>
/home/dom/Nim/lib/impure/db_sqlite.nim(198) dbError<br/>
[[reraised from:<br/>
/home/dom/nimforum2/src/forum.nim(817) forum<br/>
/home/dom/.nimble/pkgs/jester-#405be2e/jester.nim(493) serve<br/>
/home/dom/.nimble/pkgs/httpbeast-0.4.0/httpbeast.nim(540) run<br/>
/home/dom/.nimble/pkgs/httpbeast-0.4.0/httpbeast.nim(371) eventLoop<br/>
/home/dom/.nimble/pkgs/httpbeast-0.4.0/httpbeast.nim(283) processEvents<br/>
/home/dom/.nimble/pkgs/jester-#405be2e/jester.nim(496) :anonymous<br/>
/home/dom/.nimble/pkgs/jester-#405be2e/jester.nim(398) handleRequest<br/>
/home/dom/Nim/lib/pure/asyncmacro.nim(232) dispatch<br/>
/home/dom/Nim/lib/pure/asyncmacro.nim(31) dispatchNimAsyncContinue<br/>
/home/dom/Nim/lib/pure/asyncmacro.nim(131) dispatchIter<br/>
/home/dom/Nim/lib/pure/asyncfutures.nim(389) read<br/>
]]<br/>
[[reraised from:<br/>
/home/dom/nimforum2/src/forum.nim(817) forum<br/>
/home/dom/.nimble/pkgs/jester-#405be2e/jester.nim(493) serve<br/>
/home/dom/.nimble/pkgs/httpbeast-0.4.0/httpbeast.nim(540) run<br/>
/home/dom/.nimble/pkgs/httpbeast-0.4.0/httpbeast.nim(371) eventLoop<br/>
/home/dom/.nimble/pkgs/httpbeast-0.4.0/httpbeast.nim(283) processEvents<br/>
/home/dom/.nimble/pkgs/jester-#405be2e/jester.nim(496) :anonymous<br/>
/home/dom/.nimble/pkgs/jester-#405be2e/jester.nim(398) handleRequest<br/>
/home/dom/Nim/lib/pure/asyncmacro.nim(232) handleRequestSlow<br/>
/home/dom/Nim/lib/pure/asyncmacro.nim(31) handleRequestSlowNimAsyncContinue<br/>
/home/dom/Nim/lib/pure/asyncmacro.nim(131) handleRequestSlowIter<br/>
/home/dom/Nim/lib/pure/asyncfutures.nim(389) read<br/>
]]<br/>
malformed MATCH expression: [example (]<br/>
Async traceback:<br/>
  /home/dom/nimforum2/src/forum.nim(817)                    forum<br/>
  /home/dom/.nimble/pkgs/jester-#405be2e/jester.nim(493)    serve<br/>
  /home/dom/.nimble/pkgs/httpbeast-0.4.0/httpbeast.nim(540) run<br/>
  /home/dom/.nimble/pkgs/httpbeast-0.4.0/httpbeast.nim(371) eventLoop<br/>
  /home/dom/.nimble/pkgs/httpbeast-0.4.0/httpbeast.nim(283) processEvents<br/>
  /home/dom/.nimble/pkgs/jester-#405be2e/jester.nim(496)    :anonymous<br/>
  /home/dom/.nimble/pkgs/jester-#405be2e/jester.nim(398)    handleRequest<br/>
  /home/dom/Nim/lib/pure/asyncmacro.nim(232)                dispatch<br/>
  /home/dom/Nim/lib/pure/asyncmacro.nim(28)                 dispatchNimAsyncContinue<br/>
  /home/dom/.nimble/pkgs/jester-#405be2e/jester.nim(297)    dispatchIter<br/>
  /home/dom/Nim/lib/pure/asyncmacro.nim(232)                match<br/>
  /home/dom/Nim/lib/pure/asyncmacro.nim(28)                 matchNimAsyncContinue<br/>
  /home/dom/Nim/lib/impure/db_sqlite.nim(337)               matchIter<br/>
  /home/dom/Nim/lib/impure/db_sqlite.nim(198)               dbError<br/>
  #[<br/>
    /home/dom/nimforum2/src/forum.nim(817)                    forum<br/>
    /home/dom/.nimble/pkgs/jester-#405be2e/jester.nim(493)    serve<br/>
    /home/dom/.nimble/pkgs/httpbeast-0.4.0/httpbeast.nim(540) run<br/>
    /home/dom/.nimble/pkgs/httpbeast-0.4.0/httpbeast.nim(371) eventLoop<br/>
    /home/dom/.nimble/pkgs/httpbeast-0.4.0/httpbeast.nim(283) processEvents<br/>
    /home/dom/.nimble/pkgs/jester-#405be2e/jester.nim(496)    :anonymous<br/>
    /home/dom/.nimble/pkgs/jester-#405be2e/jester.nim(398)    handleRequest<br/>
    /home/dom/Nim/lib/pure/asyncmacro.nim(232)                dispatch<br/>
    /home/dom/Nim/lib/pure/asyncmacro.nim(31)                 dispatchNimAsyncContinue<br/>
    /home/dom/Nim/lib/pure/asyncmacro.nim(131)                dispatchIter<br/>
    /home/dom/Nim/lib/pure/asyncfutures.nim(389)              read<br/>
  ]#<br/>
Exception message: malformed MATCH expression: [example (]<br/>
</p></body></html>

@cyraxjoe
Copy link

cyraxjoe commented Mar 2, 2022

Maybe something like groue/GRDB.swift#129 (comment) be good enough?

@adokitkat
Copy link
Author

adokitkat commented Mar 5, 2022

So what should we do? I've already proposed to replace parentheses and also an automatic fix for missing parentheses... We can also just catch a DbError and give no results but it's not up to me which version is chosen I guess.

@dom96 dom96 changed the title Forum crashes when search term includes "(" or ")" Forum returns 5xx when search term includes "(" or ")" Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants