Back to exam

312-96 Cheatsheet

Certified Application Security Engineer (CASE) - Java

Download free PDF

Secure design and threat modeling

Lifecycle and security assessment

  • **Secure SDLC** integrates security requirements, design review, secure coding, testing and deployment checks. Begin threat modeling during design and revisit it when the architecture changes.
  • **SAST** examines source code or compiled artifacts without exercising the running application. Manual secure code review traces untrusted data to sensitive operations and checks authorization and error paths.
  • **DAST** tests a running application through its exposed interfaces. Combine it with code review: runtime behavior and implementation analysis reveal different classes of defects.

Threat classification and risk

  • **STRIDE** classifies threats: Spoofing, Tampering, Repudiation, Information disclosure, Denial of service and Elevation of privilege. Map each category to relevant components and controls.
  • **DREAD** is a risk-rating model: Damage potential, Reproducibility, Exploitability, Affected users and Discoverability. Use consistent scoring criteria when prioritizing findings.
  • **Risk = likelihood × impact** is a useful qualitative model. Probability of exploitation and damage potential are distinct inputs; a vulnerability name alone does not express business risk.
  • **Attack surface evaluation** decomposes the application and reviews entry points, exposed services, data flows and privileges from an attacker's perspective. Reduce unnecessary exposure.

Trust boundaries and abuse cases

  • **Data flow diagrams (DFDs)** show external entities, processes, data stores and flows. A **trust boundary** marks a change in trust or privilege where data and caller identity need renewed checks.
  • **Use cases** describe intended behavior; **abuse or misuse cases** describe hostile behavior. Derive security requirements and security use cases that prevent or detect the abuse.
  • **Threatens** connects hostile behavior to a legitimate use case; **mitigates** connects a protective behavior to the threat. UML **include** expresses reused behavior; **extend** adds conditional behavior.

Input, injection and file security

Validate at the trust boundary

  • **Allowlist validation** defines permitted types, lengths, ranges and formats. **Denylist validation** rejects known bad patterns but is easily incomplete. Validate on the server even when the browser also validates.
  • **request.getParameter("CatId")** retrieves a client-controlled string and can return null. Check presence, length and format, parse into the required type, then enforce permitted values and business rules.
  • **Pattern** and **Matcher.matches()** can enforce a whole-string format. Explicitly require nonempty input when needed: the **plus quantifier** requires characters, while the **star quantifier** permits zero. Keep patterns bounded to avoid excessive processing.
  • **Struts validation** must run before business logic. In Struts 1, **validate="true"** on an action mapping enables form validation; validator rules and form integration must also be configured.

Separate data from executable syntax

  • **SQL injection** occurs when untrusted data becomes SQL syntax. Use **PreparedStatement** placeholders and typed bindings; allowlist identifiers such as sort columns that cannot be bound as values.
  • **XSS** occurs when untrusted content becomes executable browser content. Apply output encoding for the destination context: HTML text, attributes, JavaScript and URLs require different handling.
  • **ESAPI.encoder().encodeForHTML(value)** targets HTML text output. JSP expressions and **out.write()** do not inherently make untrusted values safe. Sanitize with a suitable library when intentionally allowing HTML.
  • **Command injection** turns input into operating-system commands. Prefer direct APIs over shell execution; constrain the executable and arguments, and apply least privilege to the application process.

Parameters, paths and access control

  • **Parameter tampering** changes URL parameters, posted values, cookies or hidden fields. Recalculate prices and privileges from trusted server data and authorize access to each requested object.
  • **Directory traversal** escapes an intended directory through attacker-controlled paths. Prefer opaque document IDs mapped to approved files; never concatenate a request filename onto the web root.
  • When paths are required, resolve against a fixed base, normalize and verify containment. Account for **symbolic links**, canonical paths and filesystem permissions; reject escapes before opening the file.
  • **Unvalidated redirects** can send users to an attacker-controlled destination. Map approved destination IDs on the server or strictly allowlist targets; hiding URLs does not enforce access control.

Authentication, sessions and browser state

Authentication and availability

  • **Authentication** establishes identity; **authorization** decides allowed actions. Check authorization on every protected endpoint and object, independently of links visible in the UI.
  • Java web authentication mechanisms include **BASIC**, **FORM**, **DIGEST** and **CLIENT-CERT**. BASIC encodes credentials rather than encrypting them; use TLS. Client-certificate authentication relies on certificate validation.
  • **Account lockout** limits guessing but can let attackers deny access to victims. Combine measured throttling, progressive delays, monitoring and secure recovery; avoid revealing whether an account exists.

Where application state lives

  • **HttpSession** keeps attributes on the server, commonly indexed by a **JSESSIONID** cookie. **session.setAttribute("user", value)** stores a session attribute; the cookie does not contain the entire session object.
  • **Cookies** are stored by the browser and sent on matching requests. Treat their contents as untrusted unless integrity is verified; restrict scope and avoid storing sensitive values unnecessarily.
  • **Hidden fields** carry state through submitted forms and must be propagated through a sequence of dynamically generated forms. Users can read and change them; they are unsuitable as trusted prices, roles or authentication state.
  • **URL rewriting** can propagate a session identifier when cookies are unavailable. Identifiers in URLs may leak through logs, history and referrers; prefer cookie-based session tracking.

Protect the session lifecycle

  • **Session fixation** reuses an attacker-known identifier after login; **session hijacking** uses a stolen valid identifier. Rotate the identifier on authentication and privilege changes, and enforce idle and absolute timeouts.
  • Spring Security **migrateSession** creates a new session and copies existing attributes. **changeSessionId** rotates the identifier in place; **newSession** starts a clean session while preserving Spring security attributes. Concurrent-login limits are a separate control.
  • **session.invalidate()** invalidates the server-side session and unbinds attributes. At logout also expire the session cookie with matching scope and clear the authentication context.
  • **CSRF** makes an authenticated browser send an unwanted request using ambient credentials. Use unpredictable server-validated CSRF tokens for state changes, suitable SameSite cookies and origin checks; keep GET requests free of state-changing actions.

Errors, logging and cryptography

Exceptions and resource cleanup

  • **Try-with-resources** closes **AutoCloseable** resources on normal and exceptional exit. Prefer it for streams and database resources; resources close in reverse declaration order.
  • **finally** supports cleanup when explicit resource management is necessary. Avoid return, break, continue or throw there: abrupt completion can replace a pending result or conceal the original exception.
  • Catch specific exceptions where recovery or a safe response is possible. Do not swallow **SecurityException**, bypass a denied operation or use **NullPointerException** as ordinary input-validation logic.
  • Spring **@ControllerAdvice** centralizes handlers annotated with **@ExceptionHandler**. **@ResponseStatus** maps a handler or exception type to an HTTP status; return a consistent, sanitized error body.

Safe diagnostics and logging

  • **printStackTrace()** writes diagnostics to a stream and is unsuitable as a user-facing error response. **getMessage()** retrieves an exception message, but that message may still contain sensitive data.
  • Return generic errors and a correlation ID to clients. Keep detailed exceptions in protected server logs; exclude passwords, session tokens, cryptographic keys and unnecessary personal data.
  • **logger.isDebugEnabled()** checks whether DEBUG logging is active in common logging APIs. Guard expensive diagnostic computation and use parameterized logging without exposing secrets.
  • Prevent **log injection** by handling untrusted line breaks and delimiters. Handle logging failures deliberately so they do not cause uncontrolled application failures; do not silently bypass required security audit controls.

Encryption, hashes and signatures

  • **Symmetric encryption** uses a shared secret key. Prefer **AES** in an authenticated mode such as GCM, with unique nonces and protected keys; **DES** and **Triple DES** are unsuitable for new protection.
  • **Asymmetric cryptography** uses a public/private key pair. Encryption to a recipient uses the public key; a **digital signature** is created with the signer's private key and verified with the public key.
  • **Hashing** produces a one-way digest rather than reversible encryption. **MD5** and **SHA-1** are weak for collision resistance; they are not symmetric encryption algorithms.
  • **Password storage** needs a salted, deliberately slow password-hashing function. General-purpose hashes and reversible encryption are poor substitutes; keep keys and other secrets outside application source code.

Transport and Tomcat hardening

TLS and cookie controls

  • **TLS** protects data in transit. A Tomcat **Connector** is configured in **server.xml**; enabling **SSLEnabled="true"** also requires appropriate certificate and TLS configuration.
  • In **web.xml**, a security constraint with **user-data-constraint / transport-guarantee = CONFIDENTIAL** requires protected transport for matching resources. Cover all sensitive routes and handle proxy TLS termination correctly.
  • **Secure** restricts a cookie to secure transport. Configure session cookies with **session-config / cookie-config / secure = true** or use **Cookie.setSecure(true)** for application-created cookies.
  • **HttpOnly** restricts script access to a cookie: use **Cookie.setHttpOnly(true)**. It reduces session-token theft through scripts but does not prevent XSS or all authenticated actions; **SameSite** supplies a separate cross-site sending restriction.

Reduce exposure and resource abuse

  • Set the Tomcat **DefaultServlet** initialization parameter **listings=false** to disable directory indexes when welcome files are absent. Directory listing controls do not replace authorization on the files themselves.
  • Set **Server port="-1"** in **server.xml** to disable the shutdown listener. Use an appropriate service manager for shutdown and restrict operating-system control of the process; privileged administrators still retain control.
  • Minimize server names, version banners and detailed error pages. Tomcat's Connector **server** attribute controls the Server header; verify headers from the application, container and front-end proxy.
  • **maxPostSize** limits body data parsed into request parameters in applicable cases. Use multipart **maxFileSize** and **maxRequestSize** for upload limits, plus storage quotas and request timeouts; configure each layer for the resource it controls.