sio2project / oioioi

GNU General Public License v3.0
161 stars 72 forks source link

Code beautifier #321

Open franekwitt opened 8 months ago

franekwitt commented 8 months ago

Feature request: "Beautify Code" button in the submission view. This feature would be beneficial during the manual inspection of suspected plagiarism submissions.

I can implement it but right now I'm not really sure how to approach it. The two main approaches are:

  1. Server-side formatting. a) It may create a RCE / DDOS vulnerability if ran without a siojail.

b) Running the formatter in siojail every time somebody requests a formatted view probably has too big overhead. Maybe we could run it once (with reasonable time limit) and store the formatted code in the DB but that would double the disk space taken by submissions.

c) One way to mitigate this would be to lazily generate formatted copy after the first formatted view request and then store it in the DB. However that would mean one can submit a lot of codes during long period of time and then request their formatted versions at once leading to DOS.

I believe that if we decide to do the formatting server-side we will need to restrict it to admins/teachers (that would fix only c) and not a) and b) ).

  1. Client-side formatting. Maintaining its javascript dependencies might turn out to be tricky. One example of such a formatter is https://prismjs.com/ however it uses web assembly.
MasloMaslane commented 8 months ago

Does prismjs support beautifying? I think it’s just a syntax highlighter

MasloMaslane commented 8 months ago

I think that using prettier would be a good solution. It’s possible to run it on the client-side: https://prettier.io/docs/en/browser

MasloMaslane commented 8 months ago

Never mind, prettier doesn’t support cpp and python

MasloMaslane commented 8 months ago

There are wasm based formaters: https://github.com/wasm-fmt/clang-format and https://github.com/wasm-fmt/ruff_fmt