SlideShare a Scribd company logo
1 of 38
Security	Regression
Addressing	Security	Regression	by	Unit	Testing
Christopher	Grayson
@_lavalamp
InfoQ.com: News & Community Site
• 750,000 unique visitors/month
• Published in 4 languages (English, Chinese, Japanese and Brazilian
Portuguese)
• Post content from our QCon conferences
• News 15-20 / week
• Articles 3-4 / week
• Presentations (videos) 12-15 / week
• Interviews 2-3 / week
• Books 1 / month
Watch the video with slide
synchronization on InfoQ.com!
https://www.infoq.com/presentations/
security-regression-unit-testing
Presented at QCon New York
www.qconnewyork.com
Purpose of QCon
- to empower software development by facilitating the spread of
knowledge and innovation
Strategy
- practitioner-driven conference designed for YOU: influencers of
change and innovation in your teams
- speakers and topics driving the evolution and innovation
- connecting and catalyzing the influencers and innovators
Highlights
- attended by more than 12,000 delegates since 2007
- held in 9 cities worldwide
Introduction
WHOAMI
3
• ATL
• Web	development
• Academic	researcher
• Haxin’	all	the	things
• (but	I	rlllly like	networks)
• Founder
• Red	team
@_lavalamp
• Security	regression	is	a	huge
problem
• Lots	of	infrastructure	built	around	
regression	testing	already
• Let’s	leverage	all	of	that	existing	
infrastructure	to	improve	
application	security	posture	at	a	
minimal	cost	to	development	teams
WHY’S DIS
4
1. Background
2. Dynamic	Security	Test	Generation
3. Non-dynamic	Security	Test	
Generation
4. Conclusion
Agenda
5
Background
• I’ve	always	loved	breaking	into	
things,	have	been	doing	this	
professionally	since	2012
• Go	in,	break	app,	help	client	with	
remediation,	check	that	
remediation	worked	– great!
• Come	back	3-6	months	later	and	
test	again,	same	vulns are	back	
(commonly	in	the	same	places)
• Offensive	testing	is	good	at	
diagnosing	- not	solving
A Bit More on Motivation…
7
• Standard	tool	in	any	development	
team’s	toolbox
• Unit	tests	to	ensure	code	does	not	
regress	to	a	prior	state	of	instability
• Lots	of	great	tools	(especially	in	the	
CI/CD	chain)	for	ensuring	tests	are	
passing	before	deployment
Regression Testing
8
Why	not	take	the	problem	of	security	
regression	and	use	all	of	the	tools	
already	built	for	regression	testing	to	
improve	the	security	posture	of	
tested	applications?
Putting it All Together
9
• Street	Art	Around	the	World!
• Written	in	Django	(standard	
framework,	no	API,	full	post-back)
• Same	techniques	work	for	any	
programming	language	and	
framework	that	support	
introspection
• These	examples	require	a	
framework	that	has	explicit	URL	
mapping
The Demo Application
10
https://github.com/lavalamp-/security-unit-testing
Dynamic Generation
• Django	requires	users	to	write	views	
and	then	explicitly	map	these	views	
to	URL	routes	where	they	are	
served	from
• Views	come	from	a	set	of	pre-
defined	base	classes	that	support	
default	functionality	(UpdateView,	
DeleteView,	DetailView,	FormView,	
etc)
Django Registered Routes
12
• We	can	use	introspection	to	
enumerate	all	of	the	views	
registered	within	an	application
• Now	that	we	know	the	views,	how	
can	we	support	testing	functionality	
that	issues	requests	to	all	of	the	
view	functionality?
• Enter	the	Requestor class
Testing Registered Routes
13
• Requestors	mapped	to	views	they	
are	meant	to	send	requests	to	via	
Python	decorators
• Singleton	registry	contains	mapping	
of	views	to	requestors
• Importing	all	of	the	views	
automatically	establishes	all	of	the	
mappings
Requestor Registry Architecture
14
• We	now	can	enumerate	all	of	the	
views	and	access	classes	that	are	
designed	to	submit	requests	to	the	
views
• With	this	capability	we	can	
dynamically	generate	test	cases	for	
all	of	the	views	in	an	application
• Test	cases	take	view	classes	and	
HTTP	verbs	as	arguments	to	
constructors
Dynamic Test Generation
15
If	we	are	relying	on	requestor	classes	being	defined	for	all	
views,	then	let’s	test	for	it!
Testing for Requestors
16
We’ve	got	the	ability	to	test	every	known	HTTP	verb	of	every	
registered	view,	so	let’s	test	for	successful	HTTP	responses.
Testing for Denial of Service
17
Test	to	ensure	that	the	methods	supported	by	requestors	match	
the	methods	returned	by	OPTIONS	request.
Testing for Unknown Methods
18
• Tell	the	requestors	whether	or	not	the	tested	view	requires	authentication
• Can	improve	upon	this	demo	by	checking	for	inheritance	of	the	
LoginRequiredMixin
• Check	that	unauthenticated	request	is	denied
Testing for Auth Enforcement
19
Response Header Inclusion
20
We	already	built	out	requestors	based	on	the	OPTIONS	response,	so	now	
let’s	make	sure	that	the	OPTIONS	response	included	the	correct	HTTP	
verbs.
Testing for OPTIONS Accuracy
21
Test	to	ensure	that	CSRF	tokens	are	required	for	function	
invocation	on	non-idempotent	view	functionality.
Testing for CSRF Enforcement
22
• We	now	have	guarantees	that
• Our	app	contains	no	hidden	
functionality
• All	of	our	views	are	working	as	
intended	given	expected	input
• Authentication	is	being	properly	
enforced
• Security	headers	are	present
• CSRF	is	properly	protected	against
What Have We Gained?
23
• Those	guarantees	are	great	and	all,	
but	can’t	we	just	write	individual	
unit	tests	to	test	for	them?
• In	a	development	team	we	have	
multiple	people	contributing	code	
all	the	time
• Through	dynamic	generation,	these	
tests	will	automatically	be	applied	
to	all	new	views,	providing	the	
same	guarantees	to	code	that	
hasn’t	even	been	written	yet
Why Dynamic Generation?
24
• Other	things	that	we	could	write	
dynamic	tests	for
• Rate-limiting
• Fuzzing	of	all	input	values	to	
POST/PUT/PATCH/DELETE	
(introspection	into	forms	used	to	
power	the	views)
• Proper	updating,	creation,	and	
deletion	of	new	models	based	on	
input	data
Where Can We Go?
25
Testing Other Vulns
Test	for	proper	encoding	of	output	data!
Testing for Cross-site Scripting
27
Submit	two	requests	to	the	server,	one	making	the	SQL	query	match	none	and	
another	making	the	SQL	query	match	all,	test	to	see	if	the	results	match	the	
none and	all expected	responses
Testing for SQL Injection
28
Submit	malicious	input	and	see	if	HTTP	redirect	
response	redirects	to	full	URL
Testing for Open Redirects
29
Conclusion
• Initial	overhead	is	greater	than	
writing	individual	unit	tests,	but	
new	views	added	to	the	application	
also	benefit	from	the	tests
• Provide	us	with	strong	guarantees	
about	known	application	
functionality	and	basic	HTTP-based	
security	controls
Benefits of Dynamic Generation
31
• Security	guarantees	now	enforced	
by	CI/CD	integration
• Test	Driven	Development?	Great –
have	your	security	testers	write	
failing	unit	tests	that	you	then	
incorporate	into	your	test	suite
• A	new	interface	for	how	security	
and	development	teams	can	work	
together	in	harmony
Benefits of Sec. Unit Testing
32
• Security	regression	is	a	big	problem
• We	can	use	the	development	paradigm	of	regression	testing	to	address	
security	regression
• Dynamic	test	generation	can	take	us	a	long	way
• Individual	tests	for	individual	cases	further	augment	dynamic	test	generation	
capabilities
Recap
33
• Security	Unit	Testing	Project
https://github.com/lavalamp-/security-unit-testing
• Lavalamp’s Personal	Blog
https://l.avala.mp/
• Django	Web	Framework
https://www.djangoproject.com/
Resources
34
THANK YOU!
@_lavalamp
chris [AT] websight [DOT] io
github.com/lavalamp-
Watch the video with slide
synchronization on InfoQ.com!
https://www.infoq.com/presentations/
security-regression-unit-testing

More Related Content

More from C4Media

More from C4Media (20)

Shifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDShifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CD
 
CI/CD for Machine Learning
CI/CD for Machine LearningCI/CD for Machine Learning
CI/CD for Machine Learning
 
Fault Tolerance at Speed
Fault Tolerance at SpeedFault Tolerance at Speed
Fault Tolerance at Speed
 
Architectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsArchitectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep Systems
 
ML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.js
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly Compiler
 
User & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleUser & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix Scale
 
Scaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeScaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's Edge
 
Make Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereMake Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home Everywhere
 
The Talk You've Been Await-ing For
The Talk You've Been Await-ing ForThe Talk You've Been Await-ing For
The Talk You've Been Await-ing For
 
Future of Data Engineering
Future of Data EngineeringFuture of Data Engineering
Future of Data Engineering
 
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreAutomated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
 
Navigating Complexity: High-performance Delivery and Discovery Teams
Navigating Complexity: High-performance Delivery and Discovery TeamsNavigating Complexity: High-performance Delivery and Discovery Teams
Navigating Complexity: High-performance Delivery and Discovery Teams
 
High Performance Cooperative Distributed Systems in Adtech
High Performance Cooperative Distributed Systems in AdtechHigh Performance Cooperative Distributed Systems in Adtech
High Performance Cooperative Distributed Systems in Adtech
 
Rust's Journey to Async/await
Rust's Journey to Async/awaitRust's Journey to Async/await
Rust's Journey to Async/await
 
Opportunities and Pitfalls of Event-Driven Utopia
Opportunities and Pitfalls of Event-Driven UtopiaOpportunities and Pitfalls of Event-Driven Utopia
Opportunities and Pitfalls of Event-Driven Utopia
 
Datadog: a Real-Time Metrics Database for One Quadrillion Points/Day
Datadog: a Real-Time Metrics Database for One Quadrillion Points/DayDatadog: a Real-Time Metrics Database for One Quadrillion Points/Day
Datadog: a Real-Time Metrics Database for One Quadrillion Points/Day
 
Are We Really Cloud-Native?
Are We Really Cloud-Native?Are We Really Cloud-Native?
Are We Really Cloud-Native?
 
CockroachDB: Architecture of a Geo-Distributed SQL Database
CockroachDB: Architecture of a Geo-Distributed SQL DatabaseCockroachDB: Architecture of a Geo-Distributed SQL Database
CockroachDB: Architecture of a Geo-Distributed SQL Database
 
A Dive into Streams @LinkedIn with Brooklin
A Dive into Streams @LinkedIn with BrooklinA Dive into Streams @LinkedIn with Brooklin
A Dive into Streams @LinkedIn with Brooklin
 

Recently uploaded

Recently uploaded (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 

Addressing Security Regression by Unit Testing