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.
Loading...
Related Quiz
- How to declare a constant array in JavaScript?
- The initial version of JavaScript was created in just _________ days.
- You're developing a game and you're using a two-dimensional array to represent a grid of game cells. How could you access the third cell in the second row of a grid defined as const grid = [[1,2,3], [4,5,6], [7,8,9]]?
- What is a potential downside of using async/await syntax?
- What is a prototype in JavaScript?