SlideShare a Scribd company logo
SECURING REACT APPS
SHIELDS UP
December 8, 2017
SHIELDS UP - SECURING REACT APPS
ABOUT US
▸ Me: Zachary Klein
▸ Based in St Louis, MO
▸ Web dev at Object Computing,
▸ Specialize in Grails & frontend
development
SHIELDS UP - SECURING REACT APPS
ABOUT US
▸ My company: Object Computing,
Inc
▸ Based in St Louis, MO
▸ Consulting and training
provider (24+ years experience)
▸ Corporate sponsor to the Grails
framework and Groovy
language
▸ https://objectcomputing.com
SHIELDS UP - SECURING REACT APPS
ABOUT US
▸ Grails: A dynamic, flexible web application framework
▸ Built on top of Spring Boot
▸ First-class support for REST APIs
▸ Profiles for building applications using React,
Angular, Webpack, and RESTful backends
▸ Powerful persistence layer with GORM - supports
Hibernate, MongoDb, Neo4J, GraphQL, and more
▸ Rich plugin ecosystem: 200+ plugins and growing
▸ Active community and commercial support available.
▸ https://grails.org
SHIELDS UP - SECURING REACT APPS
HTTP://START.GRAILS.ORG
SHIELDS UP - SECURING REACT APPS
HTTP://GUIDES.GRAILS.ORG
SHIELDS UP - SECURING REACT APPS
SHIELDS UP - SECURING REACT APPS
ABOUT US
▸ You:
▸?
SHIELDS UP - SECURING REACT APPS
OVERVIEW
▸ Security in the world of SPAs
▸ Client-side security
▸ Cross-site-scripting Prevention
▸ Role-based Routing
▸ Server-side security*
▸ Stateless Authentication
▸ Third-party authentication
SHIELDS UP - SECURING REACT APPS
WHAT ARE WE PREVENTING?
▸ Unauthorized access to data
▸ Unauthorized access to UI
▸ Unexpected input
SHIELDS UP - SECURING REACT APPS
WHAT ARE WE PREVENTING?
▸ Unauthorized access to data
▸ API authentication
▸ Local storage
▸ Unauthorized access to UI
▸ Unexpected input
SHIELDS UP - SECURING REACT APPS
WHAT ARE WE PREVENTING?
▸ Unauthorized access to data
▸ API authentication
▸ Local storage
▸ Unauthorized access to UI
▸ Role-based Routing
▸ Unexpected input
SHIELDS UP - SECURING REACT APPS
WHAT ARE WE PREVENTING?
▸ Unauthorized access to data
▸ API authentication
▸ Local storage
▸ Unauthorized access to UI
▸ Role-based Routing
▸ Unexpected input
▸ Cross-site scripting (XSS)
SHIELDS UP - SECURING REACT APPS
WHAT ARE WE PREVENTING?
▸ Unauthorized access to data
▸ API authentication
▸ Local Storage
▸ Unauthorized access to UI
▸ Role-based Routing
▸ Unexpected input
▸ Cross-site scripting (XSS)
SHIELDS UP - SECURING REACT APPS
WHAT ARE WE PREVENTING?
▸ Unauthorized access to data
▸ API authentication
▸ Local Storage
▸ Unauthorized access to UI
▸ Role-based Routing
▸ Unexpected input
▸ Cross-site scripting (XSS)
SHIELDS UP - SECURING REACT APPS
CROSS SITE SCRIPTING & REACT
▸ React is XSS-safe by default
▸ Potential loopholes - href, formaction
▸ Server-side rendered content
▸ dangerouslySetInnerHTML
SHIELDS UP - SECURING REACT APPS
CROSS SITE SCRIPTING & REACT
▸ React is XSS-safe by default
▸ Potential loopholes - href, formaction
▸ Server-side rendered content
▸ dangerouslySetInnerHTML
▸ Third-part JavaScript
SHIELDS UP - SECURING REACT APPS
LOCAL STORAGE
▸ Local storage by design is only available to the same domain
▸ If an XSS attack is successful, storage is compromised
▸ Alternative is to use cookies with secure & httpOnly flags for storage
▸ But… cookies are vulnerable to Cross-Site-Request-Forgery attacks
▸ https://stormpath.com/blog/where-to-store-your-jwts-cookies-vs-
html5-web-storage
▸ Node CSRF Token generator: https://www.npmjs.com/package/csurf
SHIELDS UP - SECURING REACT APPS
CROSS SITE SCRIPTING & REACT
DEMO
SHIELDS UP - SECURING REACT APPS
ROLE-BASED AUTHORIZATION & ROUTING
▸ Routing allows SPAs to expose “URLS” within the app
▸ Most popular JavaScript frameworks either include a
router or support third-party libraries
▸ React-Router, Ng-Router, UI-Router, Vue-Router, etc
▸ Based on the URL, query params, and other criteria,
different content will be rendered
▸ Either hash-based history or HTML 5 browser history
http://myapp.com/#/my/route http://myapp.com/my/route
SHIELDS UP - SECURING REACT APPS
ROLE-BASED AUTHORIZATION & ROUTING
▸ User authorization vs authentication
▸ Some content should only be available to certain users
▸ E.g, admin screens, payroll management…
▸ Resources need to be secured at the server
▸ UI functionality and routes may still need to be secured
SHIELDS UP - SECURING REACT APPS
ROLE-BASED AUTHORIZATION & ROUTING
▸ Simple Approach
▸ Store current user roles in state
▸ Wrap routes/components in a container component
▸ Container component accepts list of required roles &
conditionally renders component
SHIELDS UP - SECURING REACT APPS
ROLE-BASED AUTHORIZATION & ROUTING
import React from ‘react'
import { array, bool } from ‘prop-types‘
const Authorized = {roles, allowedRoles, requireAll, children} => {
const matchesRoles = required => {
roles.indexOf(required) >= 0;
}
const show = requireAll ? allowedRoles.every(matchesRoles)
: allowedRoles.some(matchesRoles);
return show ? children : null
}
Authorized.propTypes = {
roles: array,
allowedRoles: array,
requireAll: bool
};
export default Authorized;
SHIELDS UP - SECURING REACT APPS
WITH REDUX
import React from ‘react’
import {connect} from ‘react-redux‘
const Authorized = {roles, allowedRoles, requireAll, children} => {
const matchesRoles = required => {
roles.indexOf(required) >= 0;
}
const show = requireAll ? allowedRoles.every(matchesRoles)
: allowedRoles.some(matchesRoles);
return show ? children : null
}
//..
const mapStateToProps = (state) => {
return {
allowedRoles: state.user.roles
}
};
Authorized = connect(mapStateToProps, null)(RequiresRole);
export default Authorized;
SHIELDS UP - SECURING REACT APPS
ROLE-BASED AUTHORIZATION & ROUTING
<Authorized allowedRoles={[‘ROLE_ADMIN', 'ROLE_ADMIN', 'ROLE_USER']}>
<Profile user={user} />
</Authorized>
<Authorized allowedRoles={['ROLE_ADMIN', 'ROLE_MANAGER']}>
<ManageEmployees />
</Authorized>
<Authorized allowedRoles={['ROLE_ADMIN', ‘ROLE_MANAGER']} requireAll={true}>
<ManageDatabase />
</Authorized>
SHIELDS UP - SECURING REACT APPS
ROLE-BASED AUTHORIZATION & ROUTING
▸ Advanced Approach
▸ Encapsulate role evaluation in a Higher Order
Component
▸ Slightly more complex to implement
▸ More reusable code
SHIELDS UP - SECURING REACT APPS
HIGHER ORDER COMPONENTS
▸ Not a “true” component
▸ “… a function that takes a component and returns a new
component.” (React docs)
▸ Used to avoid cross-cutting concerns in components (e.g.,
accessing external data stores, such as Redux)
SHIELDS UP - SECURING REACT APPS
HIGHER ORDER COMPONENTS
// This function takes a component...
function withExternalLogic(WrappedComponent, inputFunction) {
// ...and returns another component...
return class ExternalLogic extends React.Component {
constructor(props) {
super(props);
this.state = {
//set up some state
};
}
componentDidMount() {
//perform external logic by calling `inputFunction()`
}
render() {
// ... and renders the wrapped component with the fresh data!
return <WrappedComponent data={this.state.data} {...this.props} />;
}
};
}
const MyComponentWithExtLogic = withExternalLogic(
MyComponent,
(external) => external.doSomething()
);
https://reactjs.org/docs/higher-order-components.html
SHIELDS UP - SECURING REACT APPS
HIGHER ORDER COMPONENTS
https://reactjs.org/docs/higher-order-components.html
https://hackernoon.com/role-based-authorization-in-react-c70bb7641db4
import React, {Component} from 'react';
const Authorized = (allowedRoles, user) => {
return (WrappedComponent) => {
return class WithAuthorization extends Component {
render() {
const {role} = user;
if (allowedRoles.includes(role)) {
return <WrappedComponent {...this.props} />
} else {
return <h1>No page for you!</h1>
}
}
}
}
}
export default Authorized;
SHIELDS UP - SECURING REACT APPS
HIGHER ORDER COMPONENTS
https://reactjs.org/docs/higher-order-components.html
import Authorized from "./Authorized";
render() {
const {user, loggedIn} = this.state;
const withAdminRole = Authorized(['admin'], user);
const withUserRole = Authorized(['user', 'admin'], user);
return (
<Router>
<Route path="/restricted" component={withUserRole(Restricted)}/>
<Route path="/admin" component={withAdminRole(Admin)}/>
</Router>
);
SHIELDS UP - SECURING REACT APPS
API AUTHENTICATION
▸ Once data makes it to the UI, it’s too late to secure
▸ Authorization needs to be checked at every endpoint
▸ In a microservice architecture, each service boundary
should be secured
▸ Always use HTTPS
SHIELDS UP - SECURING REACT APPS
SESSION AUTHENTICATION
▸ Session-based security relies on the server to store state
▸ Usually a session cookie is provided to the client
▸ Ensures that sensitive data is stored only on the server
▸ Server controls session lifetime, timeouts, etc
▸ Typically requires interaction with data layer to verify user
identity, session state, etc
SHIELDS UP - SECURING REACT APPS
SESSION AUTHENTICATION
via auth0.com
SHIELDS UP - SECURING REACT APPS
STATELESS AUTHENTICATION
▸ Stateless authentication typically relies on encrypting
session details in a token
▸ Token is provided to client upon successful login
▸ Token can contain its own expiration date, user details,
roles (scopes)
▸ Client includes token in API requests
▸ Server can verify client’s identity/authorization via token
SHIELDS UP - SECURING REACT APPS
STATELESS AUTHENTICATION
via auth0.com
SHIELDS UP - SECURING REACT APPS
STATELESS AUTHENTICATION
▸ Unauthorized request is made to
API
▸ Responds with 401
▸ Client POSTs to login endpoint
▸ Responds with authorization
token
▸ Token included in subsequent
request
▸ Responds with resource
SHIELDS UP - SECURING REACT APPS
JSON WEB TOKENS
▸ https://jwt.io
▸ Open, industry-standard method for representing claims
securely between two parties
▸ Typically consist of a header, payload, and signature
SHIELDS UP - SECURING REACT APPS
JSON WEB TOKENS
https://jwt.io/introduction/
SHIELDS UP - SECURING REACT APPS
STATELESS AUTH WITH JWT
DEMO
SHIELDS UP - SECURING REACT APPS
OAUTH2 & THIRD-PARTY AUTHENTICATION
▸ OAuth2 is a standard for authentication and secured
resource access w/o sharing credentials
https://developer.okta.com/blog/2017/06/21/what-the-heck-is-oauth
SHIELDS UP - SECURING REACT APPS
OAUTH2 & THIRD-PARTY AUTHENTICATION
▸ OAuth2 is a standard flow for authentication and secured
resource access w/o sharing credentials
▸ Many third party authentication providers on the market
▸ Doesn’t usually make sense to stand up your own
▸ https://hackernoon.com/authentication-as-a-service-an-
honest-review-of-auth0-315277abcba1
▸ https://hackernoon.com/dev-rant-stop-reinventing-user-
auth-1193b138772
SHIELDS UP - SECURING REACT APPS
AUTH0
▸ https://auth0.com/docs/quickstart/spa/react/01-login
▸ https://auth0.com/blog/reactjs-authentication-tutorial
SHIELDS UP - SECURING REACT APPS
OKTA
▸ https://developer.okta.com/blog/2017/03/30/react-okta-
sign-in-widget
▸ https://developer.okta.com/blog/2017/12/06/bootiful-
development-with-spring-boot-and-react
SHIELDS UP - SECURING REACT APPS
THIRD-PARTY AUTHENTICATION
DEMO
SHIELDS UP - SECURING REACT APPS
SUMMARY
▸ React is largely very safe client-side attacks
▸ Always validate user input
▸ Plan routing strategies
▸ Secure your API first
▸ Don’t re-invent the wheel - leverage existing platforms for
authentication/authorization
▸ Keep checking behind your back
SHIELDS UP - SECURING REACT APPS
LINKS
▸ http://www.jamesward.com/2013/05/13/securing-single-page-apps-and-
rest-services
▸ http://guides.grails.org/react-spring-security/guide
▸ https://hackernoon.com/authentication-as-a-service-an-honest-review-of-
auth0-315277abcba1
▸ https://hackernoon.com/dev-rant-stop-reinventing-user-auth-1193b138772
▸ https://medium.com/dailyjs/exploiting-script-injection-flaws-in-
reactjs-883fb1fe36c1
▸ https://stormpath.com/blog/where-to-store-your-jwts-cookies-vs-html5-web-
storage
THANK YOU
Twitter: @ZacharyAKlein. Github: @ZacharyKlein. Email: zak@silver-chalice.com

More Related Content

What's hot

Angular state Management-NgRx
Angular state Management-NgRxAngular state Management-NgRx
Angular state Management-NgRx
Knoldus Inc.
 
Learn react-js
Learn react-jsLearn react-js
Reactjs
Reactjs Reactjs
Reactjs
Neha Sharma
 
Spring Boot
Spring BootSpring Boot
Spring Boot
HongSeong Jeon
 
reactJS
reactJSreactJS
reactJS
Syam Santhosh
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
Josué Neis
 
React hooks
React hooksReact hooks
React hooks
Sadhna Rana
 
Its time to React.js
Its time to React.jsIts time to React.js
Its time to React.js
Ritesh Mehrotra
 
Angular
AngularAngular
React hooks
React hooksReact hooks
React hooks
Ramy ElBasyouni
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
Thanh Tuong
 
React Router: React Meetup XXL
React Router: React Meetup XXLReact Router: React Meetup XXL
React Router: React Meetup XXL
Rob Gietema
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooks
Maulik Shah
 
The Benefits of Using React JS for Web Development!
The Benefits of Using React JS for Web Development!The Benefits of Using React JS for Web Development!
The Benefits of Using React JS for Web Development!
Baharika Sopori
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
Amazon Web Services
 
React hooks
React hooksReact hooks
React hooks
Assaf Gannon
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation洪 鹏发
 
React hooks Episode #1: An introduction.
React hooks Episode #1: An introduction.React hooks Episode #1: An introduction.
React hooks Episode #1: An introduction.
ManojSatishKumar
 
React new features and intro to Hooks
React new features and intro to HooksReact new features and intro to Hooks
React new features and intro to Hooks
Soluto
 
Basics of React Hooks.pptx.pdf
Basics of React Hooks.pptx.pdfBasics of React Hooks.pptx.pdf
Basics of React Hooks.pptx.pdf
Knoldus Inc.
 

What's hot (20)

Angular state Management-NgRx
Angular state Management-NgRxAngular state Management-NgRx
Angular state Management-NgRx
 
Learn react-js
Learn react-jsLearn react-js
Learn react-js
 
Reactjs
Reactjs Reactjs
Reactjs
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
reactJS
reactJSreactJS
reactJS
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
 
React hooks
React hooksReact hooks
React hooks
 
Its time to React.js
Its time to React.jsIts time to React.js
Its time to React.js
 
Angular
AngularAngular
Angular
 
React hooks
React hooksReact hooks
React hooks
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
 
React Router: React Meetup XXL
React Router: React Meetup XXLReact Router: React Meetup XXL
React Router: React Meetup XXL
 
Understanding react hooks
Understanding react hooksUnderstanding react hooks
Understanding react hooks
 
The Benefits of Using React JS for Web Development!
The Benefits of Using React JS for Web Development!The Benefits of Using React JS for Web Development!
The Benefits of Using React JS for Web Development!
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
 
React hooks
React hooksReact hooks
React hooks
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
React hooks Episode #1: An introduction.
React hooks Episode #1: An introduction.React hooks Episode #1: An introduction.
React hooks Episode #1: An introduction.
 
React new features and intro to Hooks
React new features and intro to HooksReact new features and intro to Hooks
React new features and intro to Hooks
 
Basics of React Hooks.pptx.pdf
Basics of React Hooks.pptx.pdfBasics of React Hooks.pptx.pdf
Basics of React Hooks.pptx.pdf
 

Similar to Shields Up! Securing React Apps

The hidden gems of Spring Security
The hidden gems of Spring SecurityThe hidden gems of Spring Security
The hidden gems of Spring Security
Massimiliano Dessì
 
Technical Architecture of RASP Technology
Technical Architecture of RASP TechnologyTechnical Architecture of RASP Technology
Technical Architecture of RASP Technology
Priyanka Aash
 
RVASec AWS Survival Guide 2.0
RVASec AWS Survival Guide 2.0RVASec AWS Survival Guide 2.0
RVASec AWS Survival Guide 2.0
Ken Johnson
 
DevOpsDays - DevOps: Security 干我何事?
DevOpsDays - DevOps: Security 干我何事?DevOpsDays - DevOps: Security 干我何事?
DevOpsDays - DevOps: Security 干我何事?
smalltown
 
How to Use Stormpath in angular js
How to Use Stormpath in angular jsHow to Use Stormpath in angular js
How to Use Stormpath in angular js
Stormpath
 
Security for cloud native workloads
Security for cloud native workloadsSecurity for cloud native workloads
Security for cloud native workloads
Runcy Oommen
 
21 05-2018
21 05-201821 05-2018
21 05-2018
Praaveen Vr
 
Pentesting RESTful webservices
Pentesting RESTful webservicesPentesting RESTful webservices
Pentesting RESTful webservices
Mohammed A. Imran
 
Low Hanging Fruit, Making Your Basic MongoDB Installation More Secure
Low Hanging Fruit, Making Your Basic MongoDB Installation More SecureLow Hanging Fruit, Making Your Basic MongoDB Installation More Secure
Low Hanging Fruit, Making Your Basic MongoDB Installation More Secure
MongoDB
 
T4 – Understanding aws security
T4 – Understanding aws securityT4 – Understanding aws security
T4 – Understanding aws security
Amazon Web Services
 
Using Behavior to Protect Cloud Servers
Using Behavior to Protect Cloud ServersUsing Behavior to Protect Cloud Servers
Using Behavior to Protect Cloud Serversbanerjeea
 
2020-02-20 - HashiTalks 2020 - HashiCorp Vault configuration as code via Hash...
2020-02-20 - HashiTalks 2020 - HashiCorp Vault configuration as code via Hash...2020-02-20 - HashiTalks 2020 - HashiCorp Vault configuration as code via Hash...
2020-02-20 - HashiTalks 2020 - HashiCorp Vault configuration as code via Hash...
Andrey Devyatkin
 
Null bhopal Sep 2016: What it Takes to Secure a Web Application
Null bhopal Sep 2016: What it Takes to Secure a Web ApplicationNull bhopal Sep 2016: What it Takes to Secure a Web Application
Null bhopal Sep 2016: What it Takes to Secure a Web Application
Anant Shrivastava
 
Monkey man
Monkey manMonkey man
Monkey man
ShapeBlue
 
Breaking SAP portal (HackerHalted)
Breaking SAP portal (HackerHalted)Breaking SAP portal (HackerHalted)
Breaking SAP portal (HackerHalted)
ERPScan
 
Implementing Authorization
Implementing AuthorizationImplementing Authorization
Implementing Authorization
Torin Sandall
 
AtlasCamp 2014: Building a Production Ready Connect Add-on
AtlasCamp 2014: Building a Production Ready Connect Add-onAtlasCamp 2014: Building a Production Ready Connect Add-on
AtlasCamp 2014: Building a Production Ready Connect Add-on
Atlassian
 
Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...
Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...
Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...
Yandex
 
AppSec Tel Aviv - OWASP Top 10 For JavaScript Developers
AppSec Tel Aviv - OWASP Top 10 For JavaScript Developers AppSec Tel Aviv - OWASP Top 10 For JavaScript Developers
AppSec Tel Aviv - OWASP Top 10 For JavaScript Developers
Lewis Ardern
 
AWS Security - An Engineer’s Introduction to AWS Security Auditing using CIS ...
AWS Security - An Engineer’s Introduction to AWS Security Auditing using CIS ...AWS Security - An Engineer’s Introduction to AWS Security Auditing using CIS ...
AWS Security - An Engineer’s Introduction to AWS Security Auditing using CIS ...
😸 Richard Spindler
 

Similar to Shields Up! Securing React Apps (20)

The hidden gems of Spring Security
The hidden gems of Spring SecurityThe hidden gems of Spring Security
The hidden gems of Spring Security
 
Technical Architecture of RASP Technology
Technical Architecture of RASP TechnologyTechnical Architecture of RASP Technology
Technical Architecture of RASP Technology
 
RVASec AWS Survival Guide 2.0
RVASec AWS Survival Guide 2.0RVASec AWS Survival Guide 2.0
RVASec AWS Survival Guide 2.0
 
DevOpsDays - DevOps: Security 干我何事?
DevOpsDays - DevOps: Security 干我何事?DevOpsDays - DevOps: Security 干我何事?
DevOpsDays - DevOps: Security 干我何事?
 
How to Use Stormpath in angular js
How to Use Stormpath in angular jsHow to Use Stormpath in angular js
How to Use Stormpath in angular js
 
Security for cloud native workloads
Security for cloud native workloadsSecurity for cloud native workloads
Security for cloud native workloads
 
21 05-2018
21 05-201821 05-2018
21 05-2018
 
Pentesting RESTful webservices
Pentesting RESTful webservicesPentesting RESTful webservices
Pentesting RESTful webservices
 
Low Hanging Fruit, Making Your Basic MongoDB Installation More Secure
Low Hanging Fruit, Making Your Basic MongoDB Installation More SecureLow Hanging Fruit, Making Your Basic MongoDB Installation More Secure
Low Hanging Fruit, Making Your Basic MongoDB Installation More Secure
 
T4 – Understanding aws security
T4 – Understanding aws securityT4 – Understanding aws security
T4 – Understanding aws security
 
Using Behavior to Protect Cloud Servers
Using Behavior to Protect Cloud ServersUsing Behavior to Protect Cloud Servers
Using Behavior to Protect Cloud Servers
 
2020-02-20 - HashiTalks 2020 - HashiCorp Vault configuration as code via Hash...
2020-02-20 - HashiTalks 2020 - HashiCorp Vault configuration as code via Hash...2020-02-20 - HashiTalks 2020 - HashiCorp Vault configuration as code via Hash...
2020-02-20 - HashiTalks 2020 - HashiCorp Vault configuration as code via Hash...
 
Null bhopal Sep 2016: What it Takes to Secure a Web Application
Null bhopal Sep 2016: What it Takes to Secure a Web ApplicationNull bhopal Sep 2016: What it Takes to Secure a Web Application
Null bhopal Sep 2016: What it Takes to Secure a Web Application
 
Monkey man
Monkey manMonkey man
Monkey man
 
Breaking SAP portal (HackerHalted)
Breaking SAP portal (HackerHalted)Breaking SAP portal (HackerHalted)
Breaking SAP portal (HackerHalted)
 
Implementing Authorization
Implementing AuthorizationImplementing Authorization
Implementing Authorization
 
AtlasCamp 2014: Building a Production Ready Connect Add-on
AtlasCamp 2014: Building a Production Ready Connect Add-onAtlasCamp 2014: Building a Production Ready Connect Add-on
AtlasCamp 2014: Building a Production Ready Connect Add-on
 
Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...
Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...
Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...
 
AppSec Tel Aviv - OWASP Top 10 For JavaScript Developers
AppSec Tel Aviv - OWASP Top 10 For JavaScript Developers AppSec Tel Aviv - OWASP Top 10 For JavaScript Developers
AppSec Tel Aviv - OWASP Top 10 For JavaScript Developers
 
AWS Security - An Engineer’s Introduction to AWS Security Auditing using CIS ...
AWS Security - An Engineer’s Introduction to AWS Security Auditing using CIS ...AWS Security - An Engineer’s Introduction to AWS Security Auditing using CIS ...
AWS Security - An Engineer’s Introduction to AWS Security Auditing using CIS ...
 

More from Zachary Klein

Native Cloud-Native: Building Agile Microservices with the Micronaut Framework
Native Cloud-Native: Building Agile Microservices with the Micronaut FrameworkNative Cloud-Native: Building Agile Microservices with the Micronaut Framework
Native Cloud-Native: Building Agile Microservices with the Micronaut Framework
Zachary Klein
 
Groovy-Powered Microservices with Micronaut
Groovy-Powered Microservices with MicronautGroovy-Powered Microservices with Micronaut
Groovy-Powered Microservices with Micronaut
Zachary Klein
 
Micronaut: Changing the Micro Future
Micronaut: Changing the Micro FutureMicronaut: Changing the Micro Future
Micronaut: Changing the Micro Future
Zachary Klein
 
Grails 4: Upgrade your Game!
Grails 4: Upgrade your Game!Grails 4: Upgrade your Game!
Grails 4: Upgrade your Game!
Zachary Klein
 
Getting Groovy with JHipster and Micronaut
Getting Groovy with JHipster and MicronautGetting Groovy with JHipster and Micronaut
Getting Groovy with JHipster and Micronaut
Zachary Klein
 
Micronaut Launchpad
Micronaut LaunchpadMicronaut Launchpad
Micronaut Launchpad
Zachary Klein
 
Groovy for Java Devs
Groovy for Java DevsGroovy for Java Devs
Groovy for Java Devs
Zachary Klein
 
Micronaut For Single Page Apps
Micronaut For Single Page AppsMicronaut For Single Page Apps
Micronaut For Single Page Apps
Zachary Klein
 
Grails Launchpad - From Ground Zero to Orbit
Grails Launchpad - From Ground Zero to OrbitGrails Launchpad - From Ground Zero to Orbit
Grails Launchpad - From Ground Zero to Orbit
Zachary Klein
 
Room with a Vue - Introduction to Vue.js
Room with a Vue - Introduction to Vue.jsRoom with a Vue - Introduction to Vue.js
Room with a Vue - Introduction to Vue.js
Zachary Klein
 
Using React with Grails 3
Using React with Grails 3Using React with Grails 3
Using React with Grails 3Zachary Klein
 

More from Zachary Klein (11)

Native Cloud-Native: Building Agile Microservices with the Micronaut Framework
Native Cloud-Native: Building Agile Microservices with the Micronaut FrameworkNative Cloud-Native: Building Agile Microservices with the Micronaut Framework
Native Cloud-Native: Building Agile Microservices with the Micronaut Framework
 
Groovy-Powered Microservices with Micronaut
Groovy-Powered Microservices with MicronautGroovy-Powered Microservices with Micronaut
Groovy-Powered Microservices with Micronaut
 
Micronaut: Changing the Micro Future
Micronaut: Changing the Micro FutureMicronaut: Changing the Micro Future
Micronaut: Changing the Micro Future
 
Grails 4: Upgrade your Game!
Grails 4: Upgrade your Game!Grails 4: Upgrade your Game!
Grails 4: Upgrade your Game!
 
Getting Groovy with JHipster and Micronaut
Getting Groovy with JHipster and MicronautGetting Groovy with JHipster and Micronaut
Getting Groovy with JHipster and Micronaut
 
Micronaut Launchpad
Micronaut LaunchpadMicronaut Launchpad
Micronaut Launchpad
 
Groovy for Java Devs
Groovy for Java DevsGroovy for Java Devs
Groovy for Java Devs
 
Micronaut For Single Page Apps
Micronaut For Single Page AppsMicronaut For Single Page Apps
Micronaut For Single Page Apps
 
Grails Launchpad - From Ground Zero to Orbit
Grails Launchpad - From Ground Zero to OrbitGrails Launchpad - From Ground Zero to Orbit
Grails Launchpad - From Ground Zero to Orbit
 
Room with a Vue - Introduction to Vue.js
Room with a Vue - Introduction to Vue.jsRoom with a Vue - Introduction to Vue.js
Room with a Vue - Introduction to Vue.js
 
Using React with Grails 3
Using React with Grails 3Using React with Grails 3
Using React with Grails 3
 

Recently uploaded

Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Hivelance Technology
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
varshanayak241
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
NaapbooksPrivateLimi
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 

Recently uploaded (20)

Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 

Shields Up! Securing React Apps

  • 1. SECURING REACT APPS SHIELDS UP December 8, 2017
  • 2. SHIELDS UP - SECURING REACT APPS ABOUT US ▸ Me: Zachary Klein ▸ Based in St Louis, MO ▸ Web dev at Object Computing, ▸ Specialize in Grails & frontend development
  • 3. SHIELDS UP - SECURING REACT APPS ABOUT US ▸ My company: Object Computing, Inc ▸ Based in St Louis, MO ▸ Consulting and training provider (24+ years experience) ▸ Corporate sponsor to the Grails framework and Groovy language ▸ https://objectcomputing.com
  • 4.
  • 5. SHIELDS UP - SECURING REACT APPS ABOUT US ▸ Grails: A dynamic, flexible web application framework ▸ Built on top of Spring Boot ▸ First-class support for REST APIs ▸ Profiles for building applications using React, Angular, Webpack, and RESTful backends ▸ Powerful persistence layer with GORM - supports Hibernate, MongoDb, Neo4J, GraphQL, and more ▸ Rich plugin ecosystem: 200+ plugins and growing ▸ Active community and commercial support available. ▸ https://grails.org
  • 6. SHIELDS UP - SECURING REACT APPS
  • 9. SHIELDS UP - SECURING REACT APPS ABOUT US ▸ You: ▸?
  • 10. SHIELDS UP - SECURING REACT APPS OVERVIEW ▸ Security in the world of SPAs ▸ Client-side security ▸ Cross-site-scripting Prevention ▸ Role-based Routing ▸ Server-side security* ▸ Stateless Authentication ▸ Third-party authentication
  • 11. SHIELDS UP - SECURING REACT APPS WHAT ARE WE PREVENTING? ▸ Unauthorized access to data ▸ Unauthorized access to UI ▸ Unexpected input
  • 12. SHIELDS UP - SECURING REACT APPS WHAT ARE WE PREVENTING? ▸ Unauthorized access to data ▸ API authentication ▸ Local storage ▸ Unauthorized access to UI ▸ Unexpected input
  • 13. SHIELDS UP - SECURING REACT APPS WHAT ARE WE PREVENTING? ▸ Unauthorized access to data ▸ API authentication ▸ Local storage ▸ Unauthorized access to UI ▸ Role-based Routing ▸ Unexpected input
  • 14. SHIELDS UP - SECURING REACT APPS WHAT ARE WE PREVENTING? ▸ Unauthorized access to data ▸ API authentication ▸ Local storage ▸ Unauthorized access to UI ▸ Role-based Routing ▸ Unexpected input ▸ Cross-site scripting (XSS)
  • 15. SHIELDS UP - SECURING REACT APPS WHAT ARE WE PREVENTING? ▸ Unauthorized access to data ▸ API authentication ▸ Local Storage ▸ Unauthorized access to UI ▸ Role-based Routing ▸ Unexpected input ▸ Cross-site scripting (XSS)
  • 16. SHIELDS UP - SECURING REACT APPS WHAT ARE WE PREVENTING? ▸ Unauthorized access to data ▸ API authentication ▸ Local Storage ▸ Unauthorized access to UI ▸ Role-based Routing ▸ Unexpected input ▸ Cross-site scripting (XSS)
  • 17. SHIELDS UP - SECURING REACT APPS CROSS SITE SCRIPTING & REACT ▸ React is XSS-safe by default ▸ Potential loopholes - href, formaction ▸ Server-side rendered content ▸ dangerouslySetInnerHTML
  • 18. SHIELDS UP - SECURING REACT APPS CROSS SITE SCRIPTING & REACT ▸ React is XSS-safe by default ▸ Potential loopholes - href, formaction ▸ Server-side rendered content ▸ dangerouslySetInnerHTML ▸ Third-part JavaScript
  • 19. SHIELDS UP - SECURING REACT APPS LOCAL STORAGE ▸ Local storage by design is only available to the same domain ▸ If an XSS attack is successful, storage is compromised ▸ Alternative is to use cookies with secure & httpOnly flags for storage ▸ But… cookies are vulnerable to Cross-Site-Request-Forgery attacks ▸ https://stormpath.com/blog/where-to-store-your-jwts-cookies-vs- html5-web-storage ▸ Node CSRF Token generator: https://www.npmjs.com/package/csurf
  • 20. SHIELDS UP - SECURING REACT APPS CROSS SITE SCRIPTING & REACT DEMO
  • 21. SHIELDS UP - SECURING REACT APPS ROLE-BASED AUTHORIZATION & ROUTING ▸ Routing allows SPAs to expose “URLS” within the app ▸ Most popular JavaScript frameworks either include a router or support third-party libraries ▸ React-Router, Ng-Router, UI-Router, Vue-Router, etc ▸ Based on the URL, query params, and other criteria, different content will be rendered ▸ Either hash-based history or HTML 5 browser history http://myapp.com/#/my/route http://myapp.com/my/route
  • 22. SHIELDS UP - SECURING REACT APPS ROLE-BASED AUTHORIZATION & ROUTING ▸ User authorization vs authentication ▸ Some content should only be available to certain users ▸ E.g, admin screens, payroll management… ▸ Resources need to be secured at the server ▸ UI functionality and routes may still need to be secured
  • 23. SHIELDS UP - SECURING REACT APPS ROLE-BASED AUTHORIZATION & ROUTING ▸ Simple Approach ▸ Store current user roles in state ▸ Wrap routes/components in a container component ▸ Container component accepts list of required roles & conditionally renders component
  • 24. SHIELDS UP - SECURING REACT APPS ROLE-BASED AUTHORIZATION & ROUTING import React from ‘react' import { array, bool } from ‘prop-types‘ const Authorized = {roles, allowedRoles, requireAll, children} => { const matchesRoles = required => { roles.indexOf(required) >= 0; } const show = requireAll ? allowedRoles.every(matchesRoles) : allowedRoles.some(matchesRoles); return show ? children : null } Authorized.propTypes = { roles: array, allowedRoles: array, requireAll: bool }; export default Authorized;
  • 25. SHIELDS UP - SECURING REACT APPS WITH REDUX import React from ‘react’ import {connect} from ‘react-redux‘ const Authorized = {roles, allowedRoles, requireAll, children} => { const matchesRoles = required => { roles.indexOf(required) >= 0; } const show = requireAll ? allowedRoles.every(matchesRoles) : allowedRoles.some(matchesRoles); return show ? children : null } //.. const mapStateToProps = (state) => { return { allowedRoles: state.user.roles } }; Authorized = connect(mapStateToProps, null)(RequiresRole); export default Authorized;
  • 26. SHIELDS UP - SECURING REACT APPS ROLE-BASED AUTHORIZATION & ROUTING <Authorized allowedRoles={[‘ROLE_ADMIN', 'ROLE_ADMIN', 'ROLE_USER']}> <Profile user={user} /> </Authorized> <Authorized allowedRoles={['ROLE_ADMIN', 'ROLE_MANAGER']}> <ManageEmployees /> </Authorized> <Authorized allowedRoles={['ROLE_ADMIN', ‘ROLE_MANAGER']} requireAll={true}> <ManageDatabase /> </Authorized>
  • 27. SHIELDS UP - SECURING REACT APPS ROLE-BASED AUTHORIZATION & ROUTING ▸ Advanced Approach ▸ Encapsulate role evaluation in a Higher Order Component ▸ Slightly more complex to implement ▸ More reusable code
  • 28. SHIELDS UP - SECURING REACT APPS HIGHER ORDER COMPONENTS ▸ Not a “true” component ▸ “… a function that takes a component and returns a new component.” (React docs) ▸ Used to avoid cross-cutting concerns in components (e.g., accessing external data stores, such as Redux)
  • 29. SHIELDS UP - SECURING REACT APPS HIGHER ORDER COMPONENTS // This function takes a component... function withExternalLogic(WrappedComponent, inputFunction) { // ...and returns another component... return class ExternalLogic extends React.Component { constructor(props) { super(props); this.state = { //set up some state }; } componentDidMount() { //perform external logic by calling `inputFunction()` } render() { // ... and renders the wrapped component with the fresh data! return <WrappedComponent data={this.state.data} {...this.props} />; } }; } const MyComponentWithExtLogic = withExternalLogic( MyComponent, (external) => external.doSomething() ); https://reactjs.org/docs/higher-order-components.html
  • 30. SHIELDS UP - SECURING REACT APPS HIGHER ORDER COMPONENTS https://reactjs.org/docs/higher-order-components.html https://hackernoon.com/role-based-authorization-in-react-c70bb7641db4 import React, {Component} from 'react'; const Authorized = (allowedRoles, user) => { return (WrappedComponent) => { return class WithAuthorization extends Component { render() { const {role} = user; if (allowedRoles.includes(role)) { return <WrappedComponent {...this.props} /> } else { return <h1>No page for you!</h1> } } } } } export default Authorized;
  • 31. SHIELDS UP - SECURING REACT APPS HIGHER ORDER COMPONENTS https://reactjs.org/docs/higher-order-components.html import Authorized from "./Authorized"; render() { const {user, loggedIn} = this.state; const withAdminRole = Authorized(['admin'], user); const withUserRole = Authorized(['user', 'admin'], user); return ( <Router> <Route path="/restricted" component={withUserRole(Restricted)}/> <Route path="/admin" component={withAdminRole(Admin)}/> </Router> );
  • 32. SHIELDS UP - SECURING REACT APPS API AUTHENTICATION ▸ Once data makes it to the UI, it’s too late to secure ▸ Authorization needs to be checked at every endpoint ▸ In a microservice architecture, each service boundary should be secured ▸ Always use HTTPS
  • 33. SHIELDS UP - SECURING REACT APPS SESSION AUTHENTICATION ▸ Session-based security relies on the server to store state ▸ Usually a session cookie is provided to the client ▸ Ensures that sensitive data is stored only on the server ▸ Server controls session lifetime, timeouts, etc ▸ Typically requires interaction with data layer to verify user identity, session state, etc
  • 34. SHIELDS UP - SECURING REACT APPS SESSION AUTHENTICATION via auth0.com
  • 35. SHIELDS UP - SECURING REACT APPS STATELESS AUTHENTICATION ▸ Stateless authentication typically relies on encrypting session details in a token ▸ Token is provided to client upon successful login ▸ Token can contain its own expiration date, user details, roles (scopes) ▸ Client includes token in API requests ▸ Server can verify client’s identity/authorization via token
  • 36. SHIELDS UP - SECURING REACT APPS STATELESS AUTHENTICATION via auth0.com
  • 37. SHIELDS UP - SECURING REACT APPS STATELESS AUTHENTICATION ▸ Unauthorized request is made to API ▸ Responds with 401 ▸ Client POSTs to login endpoint ▸ Responds with authorization token ▸ Token included in subsequent request ▸ Responds with resource
  • 38. SHIELDS UP - SECURING REACT APPS JSON WEB TOKENS ▸ https://jwt.io ▸ Open, industry-standard method for representing claims securely between two parties ▸ Typically consist of a header, payload, and signature
  • 39. SHIELDS UP - SECURING REACT APPS JSON WEB TOKENS https://jwt.io/introduction/
  • 40. SHIELDS UP - SECURING REACT APPS STATELESS AUTH WITH JWT DEMO
  • 41. SHIELDS UP - SECURING REACT APPS OAUTH2 & THIRD-PARTY AUTHENTICATION ▸ OAuth2 is a standard for authentication and secured resource access w/o sharing credentials https://developer.okta.com/blog/2017/06/21/what-the-heck-is-oauth
  • 42. SHIELDS UP - SECURING REACT APPS OAUTH2 & THIRD-PARTY AUTHENTICATION ▸ OAuth2 is a standard flow for authentication and secured resource access w/o sharing credentials ▸ Many third party authentication providers on the market ▸ Doesn’t usually make sense to stand up your own ▸ https://hackernoon.com/authentication-as-a-service-an- honest-review-of-auth0-315277abcba1 ▸ https://hackernoon.com/dev-rant-stop-reinventing-user- auth-1193b138772
  • 43. SHIELDS UP - SECURING REACT APPS AUTH0 ▸ https://auth0.com/docs/quickstart/spa/react/01-login ▸ https://auth0.com/blog/reactjs-authentication-tutorial
  • 44. SHIELDS UP - SECURING REACT APPS OKTA ▸ https://developer.okta.com/blog/2017/03/30/react-okta- sign-in-widget ▸ https://developer.okta.com/blog/2017/12/06/bootiful- development-with-spring-boot-and-react
  • 45. SHIELDS UP - SECURING REACT APPS THIRD-PARTY AUTHENTICATION DEMO
  • 46. SHIELDS UP - SECURING REACT APPS SUMMARY ▸ React is largely very safe client-side attacks ▸ Always validate user input ▸ Plan routing strategies ▸ Secure your API first ▸ Don’t re-invent the wheel - leverage existing platforms for authentication/authorization ▸ Keep checking behind your back
  • 47. SHIELDS UP - SECURING REACT APPS LINKS ▸ http://www.jamesward.com/2013/05/13/securing-single-page-apps-and- rest-services ▸ http://guides.grails.org/react-spring-security/guide ▸ https://hackernoon.com/authentication-as-a-service-an-honest-review-of- auth0-315277abcba1 ▸ https://hackernoon.com/dev-rant-stop-reinventing-user-auth-1193b138772 ▸ https://medium.com/dailyjs/exploiting-script-injection-flaws-in- reactjs-883fb1fe36c1 ▸ https://stormpath.com/blog/where-to-store-your-jwts-cookies-vs-html5-web- storage
  • 48. THANK YOU Twitter: @ZacharyAKlein. Github: @ZacharyKlein. Email: zak@silver-chalice.com