Describe the role of Subresource Integrity (SRI) in preventing XSS attacks.
- Encrypts sensitive user information
- Enforces Same-Origin Policy
- Ensures secure transmission of data
- Validates and verifies external scripts
Subresource Integrity (SRI) is a security feature that helps prevent XSS attacks by ensuring the integrity of external scripts, validating and verifying that they haven't been tampered with.
To prevent XSS attacks, it is essential to _________ user input and _________ user output.
- decode
- encode
- sanitize
- validate
To prevent XSS attacks, it is essential to sanitize user input and encode user output. Sanitizing helps remove potentially harmful content, and encoding ensures that user data is displayed correctly and safely in the browser.
_________ is a security standard that prevents the browser from interpreting user input as script.
- CORS
- CSP
- CSRF
- HTTPS
Content Security Policy (CSP) is a security standard that prevents the browser from interpreting user input as a script. It helps mitigate the risk of XSS attacks by defining and enforcing a set of rules for how resources should be loaded on a web page.
When implementing CSP, the _________ directive is crucial in restricting resources the page can load.
- connect-src
- img-src
- script-src
- style-src
When implementing CSP, the connect-src directive is crucial in restricting resources the page can load. It controls which URLs the document is allowed to make requests to, helping prevent unwanted network requests that could pose security risks.
In an XSS attack, the _________ method of XSS involves the attacker injecting a script that is stored on the server.
- DOM-based
- Persistent
- Reflected
- Stored
In a stored XSS attack, the injected script is stored on the server and served to users, making it more dangerous.
_________ encoding is a common technique to prevent XSS by converting special characters into HTML entities.
- Base64
- HTML
- URL
- UTF-8
HTML encoding is a common technique to prevent XSS by converting special characters into HTML entities, making it difficult for attackers to inject malicious scripts.
To mitigate DOM-based XSS attacks, one should avoid using _________ directly with user input.
- document.write()
- getElementById()
- innerHTML
- setAttribute()
Mitigating DOM-based XSS involves avoiding direct use of the innerHTML property with user input, as it can be exploited to execute malicious scripts within the DOM.
In a scenario where a user's session cookies are stolen via XSS, what security measures could have prevented this?
- Cross-Site Request Forgery (CSRF) Token
- Data Encryption
- HttpOnly Cookies
- Multi-Factor Authentication (MFA)
The use of HttpOnly Cookies, which cannot be accessed by JavaScript, is a security measure that could have prevented the theft of session cookies via XSS. By restricting access, the impact of XSS attacks on session data can be mitigated.
What is the primary purpose of using WebSockets in web applications?
- Batch processing
- File storage
- Real-time communication
- Static content delivery
The primary purpose of WebSockets in web applications is to enable real-time communication between the client and server, allowing for interactive and dynamic updates without the need for constant polling.
Which Java API is used for creating WebSocket applications in Java EE?
- java.socket
- java.web
- javax.communication
- javax.websocket
The javax.websocket API is used for creating WebSocket applications in Java EE, providing classes and interfaces to work with the WebSocket protocol.