How to protect Net.Core server from malicious content uploads by users?

Volk Volk 551 Reputation points
2023-10-01T15:31:24.0033333+00:00

Hi!

I have a website where on certain pages the user can (through checks in the controller method):

  1. To save (upload to server) text in text fields and to CKEditor.
  2. To save (upload to server) images (.jpg) to website through CKEditor and through system explorer.
  3. To add links to multimedia in CKEditor (YouTube, Vimeo, Twitter, Google Maps).

All image files are saved in wwwroot\Images in subfolders.

Can I somehow protect these pages from embedding malicious code, iframes, viruses, and so on?

For example, can I just somehow prevent any code from running in files in the wwwroot\Images folder?

I tried using CSP, but it's just kind of AWFUL - everything breaks and nothing works on these pages.

Who, in general, came up with this nightmare - CSP, this is some kind of mockery of common sense.

Does CKEditor protect itself from malicious content that is uploaded to the server using it?
Probably not, judging by this explanation (but this is again CSP that cannot be embedded - it creates a nuclear explosion on the pages of the site):
Content Security Policy

https://ckeditor.com/docs/ckeditor5/latest/installation/advanced/csp.html

Why do websites and interactivity in browsers are created at all, if it's all impossible to somehow protect?

So that special services, hackers and others can hack anyone at any time and take everything they need?)))

Thanks!

Developer technologies | ASP.NET | ASP.NET Core
{count} votes

2 answers

Sort by: Most helpful
  1. Volk Volk 551 Reputation points
    2023-10-03T06:17:13.84+00:00

    As far as I understand, everything is already protected (without CSP and file restrictions in wwwroot\Images), but I have to attach (additionally) a hardened converter to upload images. Yes? Please give me a link to an example with a hardened converter for upload images (in C#)? Thanks!


  2. Volk Volk 551 Reputation points
    2023-11-01T06:52:27.9833333+00:00

    Many thanks to everyone! I figured out how to install ClamAV. The code works, the virus scan works. The question is closed. :)

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.