Java Web Application Security and Input Validation

Covers essential web application security topics including XSS, SQL injection, input validation, authentication, session management, and secure coding practices in Java applications

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Following list shows entries in the web.xml deployment descriptor for Exception & Error Handling. Please identify which one is correct a. java.lang.Throwable /error.jsp b. 500 /error.jsp c. /error.jsp

  1. a
  2. b
  3. c
  4. a AND b
  5. a AND b AND c
Question 2 Multiple Choice (Single Answer)

Choose the correct answer: a. Session Timeouts can be defined in the web.xml as below: Time-in-minutes b. Session Timeouts can be defined in the server.xml as below: Time-in-minutes c. Session Timeouts cannot be defined in the deployment descriptor

  1. a
  2. b
  3. c
  4. a AND b
Question 3 Multiple Choice (Single Answer)

Choose the correct answer about the following code: public class SetCookie extends HttpServlet { public void doGet (HttpServletRequest req, HttpServletResponse res) { Cookie cookie = new Cookie ("Session Cookie”, req.getParameter(“value”)); cookie.setMaxAge (3600); response.addCookie (cookie); } ...

  1. 3600 is beyond the limit
  2. It is not recommended as it is using Persistent Cookies
  3. It leads to Cookie Poisoning Attack
  4. Option 1 AND Option 2
  5. Option 2 AND Option 3
  6. Option 1 AND Option 2 AND Option 3
Question 4 Multiple Choice (Single Answer)

Choose the correct answer: ... Statement stmt = conn.createStatement (); ResultSet rs = stmt.executeQuery (); stmt.close (); conn.close(); ...

  1. Code is vulnerable as Resource is not released in the “finally” block
  2. Code is vulnerable as Resource is not released at all
  3. Code has no vulnerability
  4. Option 1 AND Option 2
Question 5 Multiple Choice (Single Answer)

Choose the correct answer: a. HTTP PUT & DELETE method can be disabled in web.xml from the below code: Disallowed Location /* PUT DELETE b. HTTP PUT & DELETE methods are disabled by default on many web server c. HTTP PUT & DELETE methods should not be disabled d. HTTP PUT & DELETE methods cannot be disabled

  1. a
  2. b
  3. c
  4. d
  5. Option 1 AND Option 2
Question 6 Multiple Choice (Single Answer)

From security view point what is problem with code below try { //code to do IO operations return var1; } Catch(Exception e) { return var2; } finally{ return var3; }

  1. It is returning a value in finally block
  2. It is catching Exception
  3. OPTION 1 AND Option 2
  4. Nothing is wrong
Question 7 True/False

Whill this code result in DoS situation? public void dummyFunction(){ try { //open a connection to database //transaction with database closeConnection(); } catch(SQLException e){ //Exception handling block } } closeConnection() is a function which releases all database resources opened by current function.

  1. True
  2. False
Question 8 Multiple Choice (Single Answer)

Analyse following code public void dummyFunction(String var1,String var2){ try{ Connection con=getConnection(); String query=”select * from table1 where col1=”+var1 +”and col2=”+var2; Statement st=conn.createStatement(); ResultSet rs=st.executeQuery(query); …… ….. } catch(Exception e) { } } var1 and var2 are inputs from user directly passed to this functions.

  1. Vulnerable to SQL Injection
  2. Vulnerable to DoS
  3. Vulnerable to Information Disclosure
  4. Code is secure
Question 9 Multiple Choice (Single Answer)

Fnction below is used to read file from a directory on the filesystem. This code runs with read only OS level privilege on this directory. fileName is parameter from user directly passed to this function. public void dummyFunction(String fileName){ FileInputStream fis = new FileInputStream(fileName); // code to read file content only, no write modify or delete } Identify correct answer

  1. Security is handled at OS level by giving only read level privilege so no need to put an extra check here
  2. Only problem here is that fileName may not be syntactically incorrect so it should be validated before using it in the function
  3. This code can lead to information disclosure attack
  4. Java provides enough security by default for IO operations so this code is not vulnerable.
Question 10 Multiple Choice (Single Answer)

Please select which of the following statements are NOT true regarding the AccessController class? a. Can be used to mark code as being "privileged", thus affecting subsequent access determinations b. Can be to decide whether an access to a critical system resource is to be allowed or denied, based on the security policy currently in effect c. Can be used to obtain a "snapshot" of the current calling context d. Can be used to compute a cryptographically secure hash

  1. a
  2. b
  3. c
  4. d
Question 11 Multiple Choice (Single Answer)

Which of the following API's associates a Subject with the thread of execution?

  1. Subject.doAs()
  2. AccessController.checkPermission()
  3. SecurityManager.checkAccess()
  4. None of the above
Question 12 Multiple Choice (Single Answer)

Please select which of the following statements regarding Java 2 Security is TRUE?

  1. The type safety mechanism in the Java language prevents the execution of malicious code
  2. Two classes with the same fully qualified name but which are defined by different instances of a class loader are NOT of the same type
  3. All signed classes are implicitly trusted and granted full access
  4. The principal role of a TrustManager is to determine if presented authentication credentials should be trusted
  5. Option 1 AND Option 4
  6. Option 2 AND Option 4
Question 13 Multiple Choice (Single Answer)

Which of the following is a command line tool for managing the public and private keys stored in a keystore?

  1. securitymanager
  2. policytool
  3. jarsigner
  4. keystore
  5. None of the above
Question 14 Multiple Choice (Single Answer)

Which of the following best describes how to sign a document using a digital signature?

  1. Create a hash of the document and encrypt the resulting hash using the signer's private key
  2. Encrypt the document using the signer's private key
  3. Encrypt the document using the signer's private key and create a hash of the encrypted document
  4. Encrypt the document using the signer's public key
Question 15 Multiple Choice (Single Answer)

How many of security code review tools available in following list • OWASP WebScarab • Fortify • WebInspect • AppScan • Nikto • FindBugs

  1. 1
  2. 2
  3. 4
  4. 6
Question 16 Multiple Choice (Single Answer)

Which of the following framework provides an annotation based validation mechanism?

  1. Struts 1.1
  2. Struts 1.2
  3. Struts 2
  4. JSF
Question 17 Multiple Choice (Single Answer)

Data returned by which of the following methods should be validated before using it. 1. getParameter () 2. getQueryString () 3. getCookies () 4. getHeaders ()

  1. 1 AND 4
  2. 1 AND 2
  3. 1 AND 2 AND 3
  4. 1 AND 2 AND 3 AND 4
Question 18 Multiple Choice (Single Answer)

Identify code below is what type of validation. String input = request.getParameter ("input"); String characterPattern = "/ [^A-z]/"; If (! input. matches (characterPattern)) { out.println (“Invalid Input”); }

  1. White list validation
  2. Blacklist validation
  3. Mix validation
  4. No validation
Question 19 Multiple Choice (Single Answer)

What type of validation done in following code String filterPattern="[<> {}\ [\]; \&]"; String inputStr = s.replaceAll (filterPattern," ");

  1. Blacklist validation
  2. Whilelist validation
  3. Hibrid validation
  4. No validation
Question 20 Multiple Choice (Single Answer)

Which of the following are countermeasures for XSS 1. Releasing Resources after use 2. Input Validation 3. Running with least privilege 4. URL based access control 5. Output Encoding

  1. 1 AND 4
  2. 2 AND 4
  3. 1 AND 5
  4. 2 AND 5
  5. 1 AND 2 AND 4
  6. 1 AND 2 AND 5