Question 1: You are developing a web application and notice that when user-generated content is displayed on the page, it interprets HTML and JavaScript code. How can you prevent this behavior and enhance security?

  • Use the innerText property for rendering
  • Implement input validation and sanitization
  • Disable JavaScript in the browser
  • Use a stronger password policy
The most effective way to prevent user-generated content from executing JavaScript and potentially harmful code is to implement input validation and sanitization. By validating and sanitizing user inputs, you can strip or escape any potentially malicious code, making the content safe for display. Disabling JavaScript altogether may impact the functionality of your web application.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *