CS5220 Advanced Topics in Web Programming Secure REST API

Slides:



Advertisements
Similar presentations
Spring 2000CS 4611 Security Outline Encryption Algorithms Authentication Protocols Message Integrity Protocols Key Distribution Firewalls.
Advertisements

SSL CS772 Fall Secure Socket layer Design Goals: SSLv2) SSL should work well with the main web protocols such as HTTP. Confidentiality is the top.
Securing web applications using Java EE Dr Jim Briggs 1.
>> PHP: Access Control & Security. Authentication: Source Authentication Source Hard-coded File-Based The username and password is available inside the.
It’s always better live. MSDN Events Security Best Practices Part 2 of 2 Reducing Vulnerabilities using Visual Studio 2008.
WEB2P security Java web application security Dr Jim Briggs.
Online Security Tuesday April 8, 2003 Maxence Crossley.
Secure Hashing and DSS Sultan Almuhammadi ICS 454 Principles of Cryptography.
Copyright © Clifford Neuman - UNIVERSITY OF SOUTHERN CALIFORNIA - INFORMATION SCIENCES INSTITUTE CSci530: Computer Security Systems Authentication.
Web Application Vulnerabilities Checklist. EC-Council Parameter Checklist  URL request  URL encoding  Query string  Header  Cookie  Form field 
Cryptography 101 Frank Hecker
CSCI 6962: Server-side Design and Programming
.Net Security and Performance -has security slowed down the application By Krishnan Ganesh Madras.
Remotely authenticating against the Service Framework.
Chapter 5 Java Servlets. Objectives Explain the nature of a servlet and its operation Use the appropriate servlet methods in a web application Code the.
Web Database Programming Week 7 Session Management & Authentication.
Ins and Outs of Authenticating Users Requests to IIS 6.0 and ASP.NET Chris Adams Program Manager IIS Product Unit Microsoft Corporation.
CS 4244: Internet Programming Security 1.0. Introduction Client identification and cookies Basic Authentication Digest Authentication Secure HTTP.
PHP Secure Communications Web Technologies Computing Science Thompson Rivers University.
Access control 2/18/2009. TOMCAT Security Model Declarative Security:  the expression of application security external to the application, and it allows.
©SoftMoore ConsultingSlide 1 Filters. Filters can be used in a web application to intercept, examine, and possibly transform requests or responses associated.
© Copyright 2009 SSLPost 01. © Copyright 2009 SSLPost 02 a recipient is sent an encrypted that contains data specific to that recipient the data.
Dos and Don’ts of Client Authentication on the Web Kevin Fu, Emil Sit, Kendra Smith, Nick Feamster Presented: Jesus F. Morales.
 Encryption provides confidentiality  Information is unreadable to anyone without knowledge of the key  Hashing provides integrity  Verify the integrity.
CS520 Web Programming Declarative Security (I) Chengyu Sun California State University, Los Angeles.
SSL: Secure Socket Layer By: Mike Weissert. Overview Definition History & Background SSL Assurances SSL Session Problems Attacks & Defenses.
CS520 Web Programming Spring – Web MVC Chengyu Sun California State University, Los Angeles.
7/10/20161 Computer Security Protection in general purpose Operating Systems.
CS520 Web Programming Spring – Web MVC Chengyu Sun California State University, Los Angeles.
Srinivas Balivada USC CSCE548 07/22/2016.  Cookies are generally set server-side using the ‘Set-Cookie’ HTTP header and sent to the client  In PHP to.
Building Secure Microservices
CS3220 Web and Internet Programming Database Access with JDBC
Chapter 5 Network Security Protocols in Practice Part I
Web Applications Security Cryptography 1
CS520 Web Programming Declarative Security (II)
Web Application Vulnerabilities, Detection Mechanisms, and Defenses
Security Outline Encryption Algorithms Authentication Protocols
GrubTruck (iOS Food Truck App)
Secure Sockets Layer (SSL)
Information Security message M one-way hash fingerprint f = H(M)
Cryptographic Hash Function
Node.js Express Web Services
What is REST API ? A REST (Representational State Transfer) Server simply provides access to resources and the REST client accesses and presents the.
IBM Certified WAS 8.5 Administrator
Information Security message M one-way hash fingerprint f = H(M)
Using SSL – Secure Socket Layer
Cryptographic Hash Functions Part I
BY: SHIVI AGRAWAL ( ) CSE-(6)C
ICS 454 Principles of Cryptography
Web Systems Development (CSC-215)
CS5220 Advanced Topics in Web Programming Spring – Web MVC
CS320 Web and Internet Programming Cookies and Session Tracking
Information Security message M one-way hash fingerprint f = H(M)
Kiran Subramanyam Password Cracking 1.
CS3220 Web and Internet Programming Cookies and Session Tracking
The Secure Sockets Layer (SSL) Protocol
ICS 454 Principles of Cryptography
CS5220 Advanced Topics in Web Programming Spring – Web MVC
Outline Using cryptography in networks IPSec SSL and TLS.
Cryptographic Hash Functions Part I
Token-based Authentication
CS3220 Web and Internet Programming Introduction to Java Servlets
Chengyu Sun California State University, Los Angeles
Chengyu Sun California State University, Los Angeles
Exercise: Hashing, Password security, And File Integrity
CS3220 Web and Internet Programming Cookies and Session Tracking
Chengyu Sun California State University, Los Angeles
Computer Security Protection in general purpose Operating Systems
CS3220 Web and Internet Programming Database Access with JDBC
CS3220 Web and Internet Programming Database Access with JDBC
Presentation transcript:

CS5220 Advanced Topics in Web Programming Secure REST API Chengyu Sun California State University, Los Angeles

Web Application Security Client Server request who are you? Authentication username/password (Access Control) Authorization you’re not authorized to access Connection Security

HTTP Secure (HTTPS) HTTP over SSL/TLS Configure SSL in Tomcat - http://tomcat.apache.org/tomcat-8.5-doc/ssl-howto.html

Basic Security Implementation Database Server Client /login ?? users /api/user/1 ?? ?? How to store passwords properly?? What happens if authentication is successful?? How does the server authenticate/authorize subsequent requests??

Storing Passwords … Hash stored passwords Why?? How?? Encryption vs Hashing?? How to check against hashed passwords?? Common attack on hashed passwords Brute force and some variations Dictionary

… Storing Passwords Common defenses Long and random passwords Make cryptographic hash functions slower Salt

Cryptographic Hash Function… String of arbitrary length  n bits digest Properties Given a hash value, it’s virtually impossible to find a message that hashes to this value Given a message, it’s virtually impossible to find another message that hashes to the same value It’s virtually impossible to find two messages that hash to the same value A.K.A. One-way hashing, message digest, digital fingerprint

…Cryptographic Hash Function Common usage Store passwords, software checksum … Popular algorithms Good for password hashing: Argon2, PBKDF2, scrypt, bcrypt Not good for password hashing: MD5 (broken), SHA and variants

bcrypt hash Example abcd $2a$10$aol3r6 … kH/mkyO zB06fcQQOQa … U5.r3rSZI6 128 bit salt encoded in 22 characters 184 bit hash encoded in 31 characters Cost parameter Algorithm version

bcrypt Libraries BcryptPasswordEncoder in org.springframework.security:spring-security-crypto jBcrypt – org.mindrot:jbcrypt

Session-Based Security Database Server Client /login ?? users /api/user/1 ?? What happens if authentication is successful?? What does the server authenticate/authorize subsequent requests?? Why is it not suitable for RESTful web service??

Security without Session What’s wrong with sending username and password in every request? How about using a access key / token instead? Issues need to be considered: access control, performance, expiration, revocation

JSON Web Token (JWT) JWT = JSON object + Signature Example The JSON object contains the identity and authorization of a user, a.k.a. claims The actual content of JSON is up to the application The signature is the hash of the JSON object and a secret key (that only the server knows) Example JSON: { “username”: “john”, “role”: “admin” } Signature: HS256( JSON, “some secrete” )

How JWT Works … Login on the server Receives username and password Loads user information from database Creates a JWT Sends the JWT to client

… How JWT Works In subsequent requests Client includes JWT in each request Header E.g. Authorization: Bearer <token> Request parameter Cookie Server verifies the signature in JWT (How??) If signature is valid, server grants access based on JWT (no need to access database again)

More About JWT https://jwt.io/ Header, payload, and signature Predefined claims in payload sub: subject exp: expiration time iat: Issued at JWT does not provide a way to revoke tokens

Implementation Strategy … Create and verify token using Java JWT Extract token from request header, parameter, or cookie (easily done with Spring controller methods) HttpServletRequest @RequestHeader @RequestParam @CookieValue

… Implementation Strategy Use Servlet Filter, or Spring Handler Interceptor, or @ControllerAdvice Verify token, and create a User object from the token if the signature is valid Pass the User object to controller methods as a request attribute or @ModelAttribute

Servlet Filter Intercept, examine, and/or modify request and response Servlet/JSP

Servlet Filter Example web.xml <filter> and <filter-mapping> Modify request Modify response

Spring Handler Interceptor Serve the same purpose as servlet filter Configured as Spring beans, i.e. support dependency injection Handler Interceptor request response Controller

Implement a Handler Interceptor Implement HandlerInterceptor or inherits from HandlerInterceptorAdapter preHandle() – called before the controller method is invoked postHandle() – called after the controller method is invoked (but before view is generated) afterCompletion() – called after the request processing is completed (i.e. after view is generated)

URL Mapping for Handler Interceptor <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/api/**" /> <bean class=“some.Interceptor"></bean> </mvc:interceptor> </mvc:interceptors>

Use Model Methods in @ControllerAdvice Model Methods can create @ModelAttribute that are used by subsequent controller methods @ControllerAdvice public class SomeAdvice { @ModelAttribute(“currentUser”) public User getUserFromJwt( … ) { … } @ModelAttribute public void addMultipleAttributes( ModelMap models ) {…} }