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
Questions
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
- a
- b
- c
- a AND b
- a AND b AND c
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
- a
- b
- c
- a AND b
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); } ...
- 3600 is beyond the limit
- It is not recommended as it is using Persistent Cookies
- It leads to Cookie Poisoning Attack
- Option 1 AND Option 2
- Option 2 AND Option 3
- Option 1 AND Option 2 AND Option 3
Choose the correct answer: ... Statement stmt = conn.createStatement (); ResultSet rs = stmt.executeQuery (); stmt.close (); conn.close(); ...
- Code is vulnerable as Resource is not released in the “finally” block
- Code is vulnerable as Resource is not released at all
- Code has no vulnerability
- Option 1 AND Option 2
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
- a
- b
- c
- d
- Option 1 AND Option 2
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; }
- It is returning a value in finally block
- It is catching Exception
- OPTION 1 AND Option 2
- Nothing is wrong
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.
- True
- False
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.
- Vulnerable to SQL Injection
- Vulnerable to DoS
- Vulnerable to Information Disclosure
- Code is secure
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
- Security is handled at OS level by giving only read level privilege so no need to put an extra check here
- Only problem here is that fileName may not be syntactically incorrect so it should be validated before using it in the function
- This code can lead to information disclosure attack
- Java provides enough security by default for IO operations so this code is not vulnerable.
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
- a
- b
- c
- d
Which of the following API's associates a Subject with the thread of execution?
- Subject.doAs()
- AccessController.checkPermission()
- SecurityManager.checkAccess()
- None of the above
Please select which of the following statements regarding Java 2 Security is TRUE?
- The type safety mechanism in the Java language prevents the execution of malicious code
- 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
- All signed classes are implicitly trusted and granted full access
- The principal role of a TrustManager is to determine if presented authentication credentials should be trusted
- Option 1 AND Option 4
- Option 2 AND Option 4
Which of the following is a command line tool for managing the public and private keys stored in a keystore?
- securitymanager
- policytool
- jarsigner
- keystore
- None of the above
Which of the following best describes how to sign a document using a digital signature?
- Create a hash of the document and encrypt the resulting hash using the signer's private key
- Encrypt the document using the signer's private key
- Encrypt the document using the signer's private key and create a hash of the encrypted document
- Encrypt the document using the signer's public key
How many of security code review tools available in following list • OWASP WebScarab • Fortify • WebInspect • AppScan • Nikto • FindBugs
- 1
- 2
- 4
- 6
Which of the following framework provides an annotation based validation mechanism?
- Struts 1.1
- Struts 1.2
- Struts 2
- JSF
Data returned by which of the following methods should be validated before using it. 1. getParameter () 2. getQueryString () 3. getCookies () 4. getHeaders ()
- 1 AND 4
- 1 AND 2
- 1 AND 2 AND 3
- 1 AND 2 AND 3 AND 4
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”); }
- White list validation
- Blacklist validation
- Mix validation
- No validation
What type of validation done in following code String filterPattern="[<> {}\ [\]; \&]"; String inputStr = s.replaceAll (filterPattern," ");
- Blacklist validation
- Whilelist validation
- Hibrid validation
- No validation
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 AND 4
- 2 AND 4
- 1 AND 5
- 2 AND 5
- 1 AND 2 AND 4
- 1 AND 2 AND 5