SlideShare a Scribd company logo
1 of 31
Download to read offline
© 2020 Puma Security, LLC | All Rights Reserved
DevSecOps
Let's Write Security Unit Tests
February 20th, 2022
OWASP DevSlop
© 2022 Puma Security, LLC | All Rights Reserved
© 2020 Puma Security, LLC | All Rights Reserved
PRINCIPAL SECURITY ENGINEER
PUMA SECURITY
Security assessments:
Cloud, DevSecOps, source
code, web apps, mobile apps
Coder:
Cloud automation, static
analysis engine, security
tools
SENIOR INSTRUCTOR
SANS INSTITUTE
Author and instructor
SEC540: Cloud Security &
DevSecOps Automation
SEC510: Public Cloud
Security: AWS, Azure, and
GCP
EDUCATION AND
TRAINING
Iowa State M.S. Information
Assurance, B.S. Computer
Engineering
AWS, CISSP, GSSP, GWAPT
CONTACT
Email:
ejohnson@pumasecurity.io
Twitter: @emjohn20
LinkedIn:
www.linkedin.com/in/eric-m-
johnson
@
gcloud auth print-identity-token
© 2022 Puma Security, LLC | All Rights Reserved
© 2019 Puma Security, LLC | All Rights Reserved
DevSecOps
Let's Write Security
Unit Tests
DevSecOps Security
Controls
Unit Testing
101
Security Unit
Testing
Evil User
Stories
Continuous Integration
Testing
AGENDA
© 2022 Puma Security, LLC | All Rights Reserved
© 2020 Puma Security, LLC | All Rights Reserved
CLOUD & DEVSECOPS
SECURITY CONTROLS
© 2022 Puma Security, LLC | All Rights Reserved
© 2019 Puma Security, LLC | All Rights Reserved
PRE-COMMIT
Threat Modeling
IDE Security Plugins
Pre-Commit Hooks
Peer Code Reviews
COMMIT (CI) ACCEPTANCE PRODUCTION OPERATIONS
Static Code Analysis
Security Unit Tests
Container Security
Dependency Management
Infrastructure as Code
Cloud Infrastructure
Dynamic Security Tests
Security Acceptance Tests
Security Smoke Tests
Secrets Management
Security Configuration
Server Hardening
Blameless Postmortems
Continuous Monitoring
Penetration Testing
Threat Intelligence
CLOUD & DEVOPS SECURITY CONTROLS
© 2022 Puma Security, LLC | All Rights Reserved
© 2020 Puma Security, LLC | All Rights Reserved
PRE-COMMIT:
UNIT TESTING 101
© 2022 Puma Security, LLC | All Rights Reserved
© 2020 Puma Security, LLC | All Rights Reserved
Mature systems typically contain thousands
of unit tests written by software engineers:
• Easy to write, easy to change
• Fast execution in code editors and CI
pipelines
• Foundation of test-driven development
(TDD)
• Code coverage measures % of code
execution as tests run
• Rarely utilized security control in DevSecOps
UNIT TESTING
© 2022 Puma Security, LLC | All Rights Reserved
© 2020 Puma Security, LLC | All Rights Reserved
Unit testing frameworks for various
development platforms:
• JUnit (Java)
– https://junit.org
• XUnit (C#, F#, VB)
– https://xunit.github.io/
• Mocha (NodeJS)
– https://mochajs.org/
• RSpec (Ruby)
– http://rspec.info/
• PyUnit (Python)
– https://wiki.python.org/moin/PyUnit
UNIT TESTING TOOLS
© 2022 Puma Security, LLC | All Rights Reserved
© 2020 Puma Security, LLC | All Rights Reserved
UNIT TEST EXAMPLE | XUNIT
xUnit example testing the happy path login:
[Fact]
public async Task Authenticate_Succeed_GivenPasswordIsValid()
{
// Act
var response = await Client.SendAuthenticationPostRequestAsync(
SeedData.Member1Email, SeedData.User1Password);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
var authenticationResponse =
await response.Content.ReadFromJsonAsync<AuthenticateResponse>();
authenticationResponse.JwtToken.Should().NotBeNull();
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
© 2022 Puma Security, LLC | All Rights Reserved
© 2020 Puma Security, LLC | All Rights Reserved
UNIT TEST EXAMPLE | XUNIT EXECUTION
Running xUnit test cases against .NET Core:
Microsoft (R) Test Execution Command Line Tool Version 17.0.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Passed! - Failed: 0, Passed: 11, Skipped: 0, Total: 11, Duration: 466 ms
1
2
3
4
5
6
$ cd ./test/Coyote.Tests
$ dotnet test
1
2
Example xUnit output results:
© 2022 Puma Security, LLC | All Rights Reserved
© 2020 Puma Security, LLC | All Rights Reserved
PRE-COMMIT:
SECURITY UNIT TESTING
© 2022 Puma Security, LLC | All Rights Reserved
© 2020 Puma Security, LLC | All Rights Reserved
Security unit testing is often missing from
DevSecOps pipelines because it requires
collaboration between Development and
Security:
• Software engineers often stay on the
"happy path"
• InfoSec teams have the "attacker
mindset"
• Working together can provide a valuable
custom security control for applications
SECURITY UNIT TESTING ROADBLOCKS
© 2022 Puma Security, LLC | All Rights Reserved
© 2020 Puma Security, LLC | All Rights Reserved
OWASP Application Security Verification Standards
• https://owasp.org/www-project-application-security-
verification-standard/
OWASP User Security Stories
• https://github.com/OWASP/user-security-stories
Puma Security: Puma Prey Tests
• https://github.com/pumasecurity/puma-prey
SPUTR
• https://github.com/sethlaw/sputr
• https://www.blackhat.com/asia-
17/briefings.html#domo-arigato-mr.-roboto-security-
robots-a-la-unit-testing
SECURITY UNIT TESTING RESOURCES
© 2022 Puma Security, LLC | All Rights Reserved
© 2020 Puma Security, LLC | All Rights Reserved
InfoSec Pro Tip - Work with software engineers to build
security-focused unit test suites:
• Create abuse cases and evil user stories
• Burn the security stories into code
• Run security test cases to enforce security requirements
• Require negative test cases that should never pass
• Focus on high risk code and business logic flaws first
BUILDING A SECURITY UNIT TESTING SUITE
© 2022 Puma Security, LLC | All Rights Reserved
© 2020 Puma Security, LLC | All Rights Reserved
High risk code responsible for any of the following functionality
are logical candidates:
HIGH RISK CODE CANDIDATES
• Authentication
• Password handling
• Access control
• Output encoding
• Input validation
• Security Unit Tests
• Data entitlement checks
• User management
• Handling confidential data
• Cryptography
• Infrastructure code
• Declarative pipeline definitions
© 2022 Puma Security, LLC | All Rights Reserved
© 2020 Puma Security, LLC | All Rights Reserved
EVIL USER STORIES
© 2022 Puma Security, LLC | All Rights Reserved
© 2020 Puma Security, LLC | All Rights Reserved
As a user, I shall not be able to create an
account with a weak password.
ASVS 2.1| PASSWORD SECURITY
© 2022 Puma Security, LLC | All Rights Reserved
ASVS 2.1.1: Verify that user set passwords are at least 12
characters in length (after multiple spaces are combined).
ASVS 2.1.7: Verify that passwords submitted during account
registration, login, and password change are checked against
a set of breached passwords
© 2020 Puma Security, LLC | All Rights Reserved
ASVS 2.1.1 & 2.1.7 | SECURITY UNIT TEST
Creating a new user account with a weak, known breached password:
[Theory]
[InlineData(7, "Tinkerbell", HttpStatusCode.BadRequest)]
public async Task ASVS_2_1_7(int index, string password, HttpStatusCode
statusCode)
{
// Act
…
CreateUserRequest.Password = password;
var response = await Client.CreateUser(CreateUserRequest);
// Assert
response.StatusCode.Should().Be(statusCode);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
© 2022 Puma Security, LLC | All Rights Reserved
© 2020 Puma Security, LLC | All Rights Reserved
As an attacker, I shall not be able to tamper
with authentication tokens.
ASVS 3.5 | TOKEN SESSION MANAGEMENT
© 2022 Puma Security, LLC | All Rights Reserved
ASVS 3.5.3: Verify that stateless session tokens use digital
signatures, encryption, and other countermeasures to
protect against tampering, enveloping, replay, null cipher,
and key substitution attacks.
ASVS 3.5.2: Verify the application uses session tokens rather
than static API secrets and keys, except with legacy
implementations.
© 2020 Puma Security, LLC | All Rights Reserved
ASVS 2.5.3 | SECURTY UNIT TEST
Request user profile data without a JWT signature:
[Theory]
[InlineData(SeedData.Member2Email, SeedData.User2Password,
HttpStatusCode.Unauthorized)]
public async Task ASVS_3_5_3(string username, string password, HttpStatusCode
statusCode) {
// Act
var token = await Client.GetJwtAsync(username, password);
//Strip signature
var tamperedToken = $"{token.Split(".")[0]}.{token.Split(".")[1]}.";
Client.DefaultRequestHeaders.Add("Authorization", $"Bearer {tamperedToken}");
var response = await Client.GetUserByMemberId(Convert.ToInt32(memberId));
// Assert
response.StatusCode.Should().Be(statusCode);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
© 2022 Puma Security, LLC | All Rights Reserved
© 2020 Puma Security, LLC | All Rights Reserved
As an attacker, I shall not be able to access a
profile that belongs to another user.
ASVS 4.2 | OPERATION LEVEL ACCESS CONTROL
© 2022 Puma Security, LLC | All Rights Reserved
ASVS 4.2.1: Verify that sensitive data and APIs are protected
against Insecure Direct Object Reference (IDOR) attacks
targeting creation, reading, updating and deletion of
records, such as creating or updating someone else's record,
viewing everyone's records, or deleting all records.
© 2020 Puma Security, LLC | All Rights Reserved
ASVS 4.2.1 | SECURITY UNIT TEST
Member level user reading the admin user's profile:
[Theory]
[InlineData(SeedData.Member2Email, SeedData.User2Password, 2, HttpStatusCode.OK)]
[InlineData(SeedData.Member2Email, SeedData.User2Password, 1,
HttpStatusCode.Unauthorized)]
public async Task ASVS_4_2_1(string username, string password, int memberId,
HttpStatusCode statusCode)
{
// Act
var token = await Client.GetJwtAsync(username, password);
Client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}");
var response = await Client.GetUserByMemberId(memberId);
// Assert
response.StatusCode.Should().Be(statusCode);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
© 2022 Puma Security, LLC | All Rights Reserved
© 2020 Puma Security, LLC | All Rights Reserved
As an attacker, I shall not be able to inject
malicious data into the application.
ASVS 5.2 | SANITIZATION & SANDBOXING
© 2022 Puma Security, LLC | All Rights Reserved
ASVS 5.2.2: Verify that unstructured data is sanitized to
enforce safety measures such as allowed characters and
length.
ASVS 5.2.6: Verify that the application protects against SSRF
attacks, by validating or sanitizing untrusted data or HTTP
file metadata, such as filenames and URL input fields, and
uses allow lists of protocols, domains, paths and ports.
© 2020 Puma Security, LLC | All Rights Reserved
ASVS 5.2 | SECURITY UNIT TEST
Storing malicious SSRF input data in the database name field:
[InlineData(SeedData.Member1Email, SeedData.User1Password,
"http://169.254.169.254", HttpStatusCode.BadRequest)]
[InlineData(SeedData.Member1Email, SeedData.User1Password,
"http://metadata.google.internal", HttpStatusCode.BadRequest)]
public async Task ASVS_5_2(string username, string password, string name,
HttpStatusCode statusCode)
{
…
//Set payload and test
CreateAnimalRequest.Name = name;
var response = await Client.PostAnimal(CreateAnimalRequest);
// Assert
response.StatusCode.Should().Be(statusCode);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
© 2022 Puma Security, LLC | All Rights Reserved
© 2020 Puma Security, LLC | All Rights Reserved
CONTINUOUS INTEGRATION
TESTING
© 2022 Puma Security, LLC | All Rights Reserved
© 2020 Puma Security, LLC | All Rights Reserved
Prerequisite for automating build, test,
and deployment:
• Commit triggers an automated
pipeline
• Executes security unit tests
• Provides fast feedback to engineers
(and security)
• Enforces continuous security
compliance
CONTINUOUS INTEGRATION TESTING
© 2022 Puma Security, LLC | All Rights Reserved
© 2020 Puma Security, LLC | All Rights Reserved
.NET TEST | GENERATING TEST RESULT DATA
Exporting unit tests results to a test results file:
<ResultSummary outcome="Failed">
<Counters total="10" executed="10" passed="9" failed="1" error="0"
timeout="0" aborted="0" inconclusive="0" passedButRunAborted="0"
notRunnable="0" notExecuted="0" disconnected="0" warning="0" completed="0"
inProgress="0" pending="0" />
</ResultSummary>
1
2
3
4
5
6
$ cd ./test/Coyote.Tests
$ dotnet test –logger "trx;LogFileName=coyote.trx"
1
2
Example .NET test unit test output results:
© 2022 Puma Security, LLC | All Rights Reserved
© 2020 Puma Security, LLC | All Rights Reserved
GH ACTION | UNIT TEST CONFIGURATION
GH Action workflow executing and parsing unit test results:
jobs:
build:
name: Puma Prey
runs-on: ubuntu-18.04
steps:
…
- name: Test
shell: bash
run: |
cd ./test/Coyote.Tests
dotnet test --logger "trx;LogFileName=coyote.trx"
- name: Publish Test Results
uses: dorny/test-reporter@v1
with:
name: "Coyote Test Results"
path: "test/Coyote.Tests/TestResults/*.trx"
reporter: "dotnet-trx"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
© 2022 Puma Security, LLC | All Rights Reserved
© 2020 Puma Security, LLC | All Rights Reserved
GH ACTION | UNIT TEST RESULTS
Viewing GH Action workflows and unit test results:
© 2022 Puma Security, LLC | All Rights Reserved
© 2020 Puma Security, LLC | All Rights Reserved
Keys To Success:
• Security teams often ignore unit testing and opt for long running,
unreliable scanners to find low hanging fruit
• Work with software engineers to create abuse cases and unit &
integration tests based on ASVS requirements
• Integrate security unit tests in Continuous Integration pipelines &
monitor failing test cases
• Failing security tests should halt the build and require immediate
attention before releasing changes
SECURITY UNIT TESTING SUMMARY
© 2022 Puma Security, LLC | All Rights Reserved
© 2020 Puma Security, LLC | All Rights Reserved
THANK YOU FOR ATTENDING!
OWASP DevSlop
Eric Johnson
Principal Security Engineer, Puma Security
Senior Instructor, SANS Institute
www.linkedin.com/in/eric-m-johnson
@emjohn20
ejohnson@pumasecurity.io
© 2022 Puma Security, LLC | All Rights Reserved

More Related Content

What's hot

Security Process in DevSecOps
Security Process in DevSecOpsSecurity Process in DevSecOps
Security Process in DevSecOpsOpsta
 
Introdução do DEVSECOPS
Introdução do DEVSECOPSIntrodução do DEVSECOPS
Introdução do DEVSECOPSGDGFoz
 
DevSecOps Training Bootcamp - A Practical DevSecOps Course
DevSecOps Training Bootcamp - A Practical DevSecOps CourseDevSecOps Training Bootcamp - A Practical DevSecOps Course
DevSecOps Training Bootcamp - A Practical DevSecOps CourseTonex
 
[DevSecOps Live] DevSecOps: Challenges and Opportunities
[DevSecOps Live] DevSecOps: Challenges and Opportunities[DevSecOps Live] DevSecOps: Challenges and Opportunities
[DevSecOps Live] DevSecOps: Challenges and OpportunitiesMohammed A. Imran
 
若手エンジニアのためのセキュリティ講座
若手エンジニアのためのセキュリティ講座若手エンジニアのためのセキュリティ講座
若手エンジニアのためのセキュリティ講座Hiroshi Tokumaru
 
インフラエンジニアの綺麗で優しい手順書の書き方
インフラエンジニアの綺麗で優しい手順書の書き方インフラエンジニアの綺麗で優しい手順書の書き方
インフラエンジニアの綺麗で優しい手順書の書き方Shohei Koyama
 
ドメイン分析勉強会
ドメイン分析勉強会ドメイン分析勉強会
ドメイン分析勉強会Kosuke Fujisawa
 
The Twelve-Factor Appで考えるAWSのサービス開発
The Twelve-Factor Appで考えるAWSのサービス開発The Twelve-Factor Appで考えるAWSのサービス開発
The Twelve-Factor Appで考えるAWSのサービス開発Amazon Web Services Japan
 
セキュリティの都市伝説を暴く
セキュリティの都市伝説を暴くセキュリティの都市伝説を暴く
セキュリティの都市伝説を暴くHiroshi Tokumaru
 
「関心の分離」と「疎結合」 ソフトウェアアーキテクチャのひとかけら
「関心の分離」と「疎結合」   ソフトウェアアーキテクチャのひとかけら「関心の分離」と「疎結合」   ソフトウェアアーキテクチャのひとかけら
「関心の分離」と「疎結合」 ソフトウェアアーキテクチャのひとかけらAtsushi Nakamura
 
How to Get Started with DevSecOps
How to Get Started with DevSecOpsHow to Get Started with DevSecOps
How to Get Started with DevSecOpsCYBRIC
 
deep dive distributed tracing
deep dive distributed tracingdeep dive distributed tracing
deep dive distributed tracingTakayoshi Tanaka
 
最近のやられアプリを試してみた
最近のやられアプリを試してみた最近のやられアプリを試してみた
最近のやられアプリを試してみたzaki4649
 
Monitoring - 入門監視
Monitoring - 入門監視Monitoring - 入門監視
Monitoring - 入門監視Eiji KOMINAMI
 
ぼくらが体験入社にこだわるワケ
ぼくらが体験入社にこだわるワケぼくらが体験入社にこだわるワケ
ぼくらが体験入社にこだわるワケDaisuke Sato
 
Continuous Security: Using Automation to Expand Security's Reach
Continuous Security: Using Automation to Expand Security's ReachContinuous Security: Using Automation to Expand Security's Reach
Continuous Security: Using Automation to Expand Security's ReachMatt Tesauro
 
node-gypを使ったネイティブモジュールの作成
node-gypを使ったネイティブモジュールの作成node-gypを使ったネイティブモジュールの作成
node-gypを使ったネイティブモジュールの作成shigeki_ohtsu
 
DevSecOps Implementation Journey
DevSecOps Implementation JourneyDevSecOps Implementation Journey
DevSecOps Implementation JourneyDevOps Indonesia
 

What's hot (20)

Security Process in DevSecOps
Security Process in DevSecOpsSecurity Process in DevSecOps
Security Process in DevSecOps
 
Introdução do DEVSECOPS
Introdução do DEVSECOPSIntrodução do DEVSECOPS
Introdução do DEVSECOPS
 
DevSecOps Training Bootcamp - A Practical DevSecOps Course
DevSecOps Training Bootcamp - A Practical DevSecOps CourseDevSecOps Training Bootcamp - A Practical DevSecOps Course
DevSecOps Training Bootcamp - A Practical DevSecOps Course
 
[DevSecOps Live] DevSecOps: Challenges and Opportunities
[DevSecOps Live] DevSecOps: Challenges and Opportunities[DevSecOps Live] DevSecOps: Challenges and Opportunities
[DevSecOps Live] DevSecOps: Challenges and Opportunities
 
若手エンジニアのためのセキュリティ講座
若手エンジニアのためのセキュリティ講座若手エンジニアのためのセキュリティ講座
若手エンジニアのためのセキュリティ講座
 
Intro to Azure DevOps
Intro to Azure DevOpsIntro to Azure DevOps
Intro to Azure DevOps
 
インフラエンジニアの綺麗で優しい手順書の書き方
インフラエンジニアの綺麗で優しい手順書の書き方インフラエンジニアの綺麗で優しい手順書の書き方
インフラエンジニアの綺麗で優しい手順書の書き方
 
ドメイン分析勉強会
ドメイン分析勉強会ドメイン分析勉強会
ドメイン分析勉強会
 
The Twelve-Factor Appで考えるAWSのサービス開発
The Twelve-Factor Appで考えるAWSのサービス開発The Twelve-Factor Appで考えるAWSのサービス開発
The Twelve-Factor Appで考えるAWSのサービス開発
 
セキュリティの都市伝説を暴く
セキュリティの都市伝説を暴くセキュリティの都市伝説を暴く
セキュリティの都市伝説を暴く
 
「関心の分離」と「疎結合」 ソフトウェアアーキテクチャのひとかけら
「関心の分離」と「疎結合」   ソフトウェアアーキテクチャのひとかけら「関心の分離」と「疎結合」   ソフトウェアアーキテクチャのひとかけら
「関心の分離」と「疎結合」 ソフトウェアアーキテクチャのひとかけら
 
How to Get Started with DevSecOps
How to Get Started with DevSecOpsHow to Get Started with DevSecOps
How to Get Started with DevSecOps
 
Introduction to DevSecOps
Introduction to DevSecOpsIntroduction to DevSecOps
Introduction to DevSecOps
 
deep dive distributed tracing
deep dive distributed tracingdeep dive distributed tracing
deep dive distributed tracing
 
最近のやられアプリを試してみた
最近のやられアプリを試してみた最近のやられアプリを試してみた
最近のやられアプリを試してみた
 
Monitoring - 入門監視
Monitoring - 入門監視Monitoring - 入門監視
Monitoring - 入門監視
 
ぼくらが体験入社にこだわるワケ
ぼくらが体験入社にこだわるワケぼくらが体験入社にこだわるワケ
ぼくらが体験入社にこだわるワケ
 
Continuous Security: Using Automation to Expand Security's Reach
Continuous Security: Using Automation to Expand Security's ReachContinuous Security: Using Automation to Expand Security's Reach
Continuous Security: Using Automation to Expand Security's Reach
 
node-gypを使ったネイティブモジュールの作成
node-gypを使ったネイティブモジュールの作成node-gypを使ったネイティブモジュールの作成
node-gypを使ったネイティブモジュールの作成
 
DevSecOps Implementation Journey
DevSecOps Implementation JourneyDevSecOps Implementation Journey
DevSecOps Implementation Journey
 

Similar to DevSecOps: Let's Write Security Unit Tests

Weaponizing Your DevOps Pipeline
Weaponizing Your DevOps PipelineWeaponizing Your DevOps Pipeline
Weaponizing Your DevOps PipelinePuma Security, LLC
 
Java EE Application Security With PicketLink
Java EE Application Security With PicketLinkJava EE Application Security With PicketLink
Java EE Application Security With PicketLinkpigorcraveiro
 
Problems with parameters b sides-msp
Problems with parameters b sides-mspProblems with parameters b sides-msp
Problems with parameters b sides-mspMike Saunders
 
1.3. (In)security Software
1.3. (In)security Software1.3. (In)security Software
1.3. (In)security Softwaredefconmoscow
 
DevSecOps: Key Controls for Modern Security Success
DevSecOps: Key Controls for Modern Security SuccessDevSecOps: Key Controls for Modern Security Success
DevSecOps: Key Controls for Modern Security SuccessPuma Security, LLC
 
Data Driven Decisions in DevOps
Data Driven Decisions in DevOpsData Driven Decisions in DevOps
Data Driven Decisions in DevOpsLeon Stigter
 
Secure coding presentation Oct 3 2020
Secure coding presentation Oct 3 2020Secure coding presentation Oct 3 2020
Secure coding presentation Oct 3 2020Moataz Kamel
 
Pragmatic Pipeline Security
Pragmatic Pipeline SecurityPragmatic Pipeline Security
Pragmatic Pipeline SecurityJames Wickett
 
Take Control: Design a Complete DevSecOps Program
Take Control: Design a Complete DevSecOps ProgramTake Control: Design a Complete DevSecOps Program
Take Control: Design a Complete DevSecOps ProgramDeborah Schalm
 
Take Control: Design a Complete DevSecOps Program
Take Control: Design a Complete DevSecOps Program Take Control: Design a Complete DevSecOps Program
Take Control: Design a Complete DevSecOps Program DevOps.com
 
Using Security to Build with Confidence in AWS - Trend Micro
Using Security to Build with Confidence in AWS - Trend Micro Using Security to Build with Confidence in AWS - Trend Micro
Using Security to Build with Confidence in AWS - Trend Micro Amazon Web Services
 
Ccnp sisas 300 208
Ccnp sisas 300 208Ccnp sisas 300 208
Ccnp sisas 300 208p4sco
 
Java Web Application Security - Denver JUG 2013
Java Web Application Security - Denver JUG 2013Java Web Application Security - Denver JUG 2013
Java Web Application Security - Denver JUG 2013Matt Raible
 
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
 
Webinar: Extend The Power of The ForgeRock Identity Platform Through Scripting
Webinar: Extend The Power of The ForgeRock Identity Platform Through ScriptingWebinar: Extend The Power of The ForgeRock Identity Platform Through Scripting
Webinar: Extend The Power of The ForgeRock Identity Platform Through ScriptingForgeRock
 
Microservices with Node.js and Apache Cassandra
Microservices with Node.js and Apache CassandraMicroservices with Node.js and Apache Cassandra
Microservices with Node.js and Apache CassandraJorge Bay Gondra
 
Top Ten Web Application Defenses v12
Top Ten Web Application Defenses v12Top Ten Web Application Defenses v12
Top Ten Web Application Defenses v12Jim Manico
 

Similar to DevSecOps: Let's Write Security Unit Tests (20)

Secure DevOps: A Puma's Tail
Secure DevOps: A Puma's TailSecure DevOps: A Puma's Tail
Secure DevOps: A Puma's Tail
 
Weaponizing Your DevOps Pipeline
Weaponizing Your DevOps PipelineWeaponizing Your DevOps Pipeline
Weaponizing Your DevOps Pipeline
 
Java EE Application Security With PicketLink
Java EE Application Security With PicketLinkJava EE Application Security With PicketLink
Java EE Application Security With PicketLink
 
Problems with parameters b sides-msp
Problems with parameters b sides-mspProblems with parameters b sides-msp
Problems with parameters b sides-msp
 
1.3. (In)security Software
1.3. (In)security Software1.3. (In)security Software
1.3. (In)security Software
 
DevSecOps: Key Controls for Modern Security Success
DevSecOps: Key Controls for Modern Security SuccessDevSecOps: Key Controls for Modern Security Success
DevSecOps: Key Controls for Modern Security Success
 
Data Driven Decisions in DevOps
Data Driven Decisions in DevOpsData Driven Decisions in DevOps
Data Driven Decisions in DevOps
 
Azure from scratch part 4
Azure from scratch part 4Azure from scratch part 4
Azure from scratch part 4
 
Secure coding presentation Oct 3 2020
Secure coding presentation Oct 3 2020Secure coding presentation Oct 3 2020
Secure coding presentation Oct 3 2020
 
Pragmatic Pipeline Security
Pragmatic Pipeline SecurityPragmatic Pipeline Security
Pragmatic Pipeline Security
 
Take Control: Design a Complete DevSecOps Program
Take Control: Design a Complete DevSecOps ProgramTake Control: Design a Complete DevSecOps Program
Take Control: Design a Complete DevSecOps Program
 
Take Control: Design a Complete DevSecOps Program
Take Control: Design a Complete DevSecOps Program Take Control: Design a Complete DevSecOps Program
Take Control: Design a Complete DevSecOps Program
 
Using Security to Build with Confidence in AWS - Trend Micro
Using Security to Build with Confidence in AWS - Trend Micro Using Security to Build with Confidence in AWS - Trend Micro
Using Security to Build with Confidence in AWS - Trend Micro
 
Ccnp sisas 300 208
Ccnp sisas 300 208Ccnp sisas 300 208
Ccnp sisas 300 208
 
Java Web Application Security - Denver JUG 2013
Java Web Application Security - Denver JUG 2013Java Web Application Security - Denver JUG 2013
Java Web Application Security - Denver JUG 2013
 
DevSecOps
DevSecOpsDevSecOps
DevSecOps
 
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
 
Webinar: Extend The Power of The ForgeRock Identity Platform Through Scripting
Webinar: Extend The Power of The ForgeRock Identity Platform Through ScriptingWebinar: Extend The Power of The ForgeRock Identity Platform Through Scripting
Webinar: Extend The Power of The ForgeRock Identity Platform Through Scripting
 
Microservices with Node.js and Apache Cassandra
Microservices with Node.js and Apache CassandraMicroservices with Node.js and Apache Cassandra
Microservices with Node.js and Apache Cassandra
 
Top Ten Web Application Defenses v12
Top Ten Web Application Defenses v12Top Ten Web Application Defenses v12
Top Ten Web Application Defenses v12
 

More from Puma Security, LLC

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Lessons Learned Deploying Modern Cloud Systems in Highly Regulated Environments
Lessons Learned Deploying Modern Cloud Systems in Highly Regulated EnvironmentsLessons Learned Deploying Modern Cloud Systems in Highly Regulated Environments
Lessons Learned Deploying Modern Cloud Systems in Highly Regulated EnvironmentsPuma Security, LLC
 
Winning in the Dark: Defending Serverless Infrastructure
Winning in the Dark: Defending Serverless InfrastructureWinning in the Dark: Defending Serverless Infrastructure
Winning in the Dark: Defending Serverless InfrastructurePuma Security, LLC
 
Defending Serverless Infrastructure in the Cloud RSAC 2020
Defending Serverless Infrastructure in the Cloud RSAC 2020Defending Serverless Infrastructure in the Cloud RSAC 2020
Defending Serverless Infrastructure in the Cloud RSAC 2020Puma Security, LLC
 
Cloud Security: Attacking The Metadata Service v2
Cloud Security: Attacking The Metadata Service v2Cloud Security: Attacking The Metadata Service v2
Cloud Security: Attacking The Metadata Service v2Puma Security, LLC
 
Cloud Security: Attacking The Metadata Service
Cloud Security: Attacking The Metadata ServiceCloud Security: Attacking The Metadata Service
Cloud Security: Attacking The Metadata ServicePuma Security, LLC
 
DevSecOps: Key Controls to Modern Security Success
DevSecOps: Key Controls to Modern Security SuccessDevSecOps: Key Controls to Modern Security Success
DevSecOps: Key Controls to Modern Security SuccessPuma Security, LLC
 
Continuous Integration - Live Static Analysis with Puma Scan
Continuous Integration - Live Static Analysis with Puma ScanContinuous Integration - Live Static Analysis with Puma Scan
Continuous Integration - Live Static Analysis with Puma ScanPuma Security, LLC
 

More from Puma Security, LLC (9)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Breaking The Cloud Kill Chain
Breaking The Cloud Kill ChainBreaking The Cloud Kill Chain
Breaking The Cloud Kill Chain
 
Lessons Learned Deploying Modern Cloud Systems in Highly Regulated Environments
Lessons Learned Deploying Modern Cloud Systems in Highly Regulated EnvironmentsLessons Learned Deploying Modern Cloud Systems in Highly Regulated Environments
Lessons Learned Deploying Modern Cloud Systems in Highly Regulated Environments
 
Winning in the Dark: Defending Serverless Infrastructure
Winning in the Dark: Defending Serverless InfrastructureWinning in the Dark: Defending Serverless Infrastructure
Winning in the Dark: Defending Serverless Infrastructure
 
Defending Serverless Infrastructure in the Cloud RSAC 2020
Defending Serverless Infrastructure in the Cloud RSAC 2020Defending Serverless Infrastructure in the Cloud RSAC 2020
Defending Serverless Infrastructure in the Cloud RSAC 2020
 
Cloud Security: Attacking The Metadata Service v2
Cloud Security: Attacking The Metadata Service v2Cloud Security: Attacking The Metadata Service v2
Cloud Security: Attacking The Metadata Service v2
 
Cloud Security: Attacking The Metadata Service
Cloud Security: Attacking The Metadata ServiceCloud Security: Attacking The Metadata Service
Cloud Security: Attacking The Metadata Service
 
DevSecOps: Key Controls to Modern Security Success
DevSecOps: Key Controls to Modern Security SuccessDevSecOps: Key Controls to Modern Security Success
DevSecOps: Key Controls to Modern Security Success
 
Continuous Integration - Live Static Analysis with Puma Scan
Continuous Integration - Live Static Analysis with Puma ScanContinuous Integration - Live Static Analysis with Puma Scan
Continuous Integration - Live Static Analysis with Puma Scan
 

Recently uploaded

Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
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 Takeoffsammart93
 
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...apidays
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
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 SavingEdi Saputra
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
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, ...apidays
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
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...apidays
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 

Recently uploaded (20)

Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
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
 
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...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
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, ...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 

DevSecOps: Let's Write Security Unit Tests

  • 1. © 2020 Puma Security, LLC | All Rights Reserved DevSecOps Let's Write Security Unit Tests February 20th, 2022 OWASP DevSlop © 2022 Puma Security, LLC | All Rights Reserved
  • 2. © 2020 Puma Security, LLC | All Rights Reserved PRINCIPAL SECURITY ENGINEER PUMA SECURITY Security assessments: Cloud, DevSecOps, source code, web apps, mobile apps Coder: Cloud automation, static analysis engine, security tools SENIOR INSTRUCTOR SANS INSTITUTE Author and instructor SEC540: Cloud Security & DevSecOps Automation SEC510: Public Cloud Security: AWS, Azure, and GCP EDUCATION AND TRAINING Iowa State M.S. Information Assurance, B.S. Computer Engineering AWS, CISSP, GSSP, GWAPT CONTACT Email: ejohnson@pumasecurity.io Twitter: @emjohn20 LinkedIn: www.linkedin.com/in/eric-m- johnson @ gcloud auth print-identity-token © 2022 Puma Security, LLC | All Rights Reserved
  • 3. © 2019 Puma Security, LLC | All Rights Reserved DevSecOps Let's Write Security Unit Tests DevSecOps Security Controls Unit Testing 101 Security Unit Testing Evil User Stories Continuous Integration Testing AGENDA © 2022 Puma Security, LLC | All Rights Reserved
  • 4. © 2020 Puma Security, LLC | All Rights Reserved CLOUD & DEVSECOPS SECURITY CONTROLS © 2022 Puma Security, LLC | All Rights Reserved
  • 5. © 2019 Puma Security, LLC | All Rights Reserved PRE-COMMIT Threat Modeling IDE Security Plugins Pre-Commit Hooks Peer Code Reviews COMMIT (CI) ACCEPTANCE PRODUCTION OPERATIONS Static Code Analysis Security Unit Tests Container Security Dependency Management Infrastructure as Code Cloud Infrastructure Dynamic Security Tests Security Acceptance Tests Security Smoke Tests Secrets Management Security Configuration Server Hardening Blameless Postmortems Continuous Monitoring Penetration Testing Threat Intelligence CLOUD & DEVOPS SECURITY CONTROLS © 2022 Puma Security, LLC | All Rights Reserved
  • 6. © 2020 Puma Security, LLC | All Rights Reserved PRE-COMMIT: UNIT TESTING 101 © 2022 Puma Security, LLC | All Rights Reserved
  • 7. © 2020 Puma Security, LLC | All Rights Reserved Mature systems typically contain thousands of unit tests written by software engineers: • Easy to write, easy to change • Fast execution in code editors and CI pipelines • Foundation of test-driven development (TDD) • Code coverage measures % of code execution as tests run • Rarely utilized security control in DevSecOps UNIT TESTING © 2022 Puma Security, LLC | All Rights Reserved
  • 8. © 2020 Puma Security, LLC | All Rights Reserved Unit testing frameworks for various development platforms: • JUnit (Java) – https://junit.org • XUnit (C#, F#, VB) – https://xunit.github.io/ • Mocha (NodeJS) – https://mochajs.org/ • RSpec (Ruby) – http://rspec.info/ • PyUnit (Python) – https://wiki.python.org/moin/PyUnit UNIT TESTING TOOLS © 2022 Puma Security, LLC | All Rights Reserved
  • 9. © 2020 Puma Security, LLC | All Rights Reserved UNIT TEST EXAMPLE | XUNIT xUnit example testing the happy path login: [Fact] public async Task Authenticate_Succeed_GivenPasswordIsValid() { // Act var response = await Client.SendAuthenticationPostRequestAsync( SeedData.Member1Email, SeedData.User1Password); // Assert response.StatusCode.Should().Be(HttpStatusCode.OK); var authenticationResponse = await response.Content.ReadFromJsonAsync<AuthenticateResponse>(); authenticationResponse.JwtToken.Should().NotBeNull(); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 © 2022 Puma Security, LLC | All Rights Reserved
  • 10. © 2020 Puma Security, LLC | All Rights Reserved UNIT TEST EXAMPLE | XUNIT EXECUTION Running xUnit test cases against .NET Core: Microsoft (R) Test Execution Command Line Tool Version 17.0.0 Copyright (c) Microsoft Corporation. All rights reserved. Starting test execution, please wait... A total of 1 test files matched the specified pattern. Passed! - Failed: 0, Passed: 11, Skipped: 0, Total: 11, Duration: 466 ms 1 2 3 4 5 6 $ cd ./test/Coyote.Tests $ dotnet test 1 2 Example xUnit output results: © 2022 Puma Security, LLC | All Rights Reserved
  • 11. © 2020 Puma Security, LLC | All Rights Reserved PRE-COMMIT: SECURITY UNIT TESTING © 2022 Puma Security, LLC | All Rights Reserved
  • 12. © 2020 Puma Security, LLC | All Rights Reserved Security unit testing is often missing from DevSecOps pipelines because it requires collaboration between Development and Security: • Software engineers often stay on the "happy path" • InfoSec teams have the "attacker mindset" • Working together can provide a valuable custom security control for applications SECURITY UNIT TESTING ROADBLOCKS © 2022 Puma Security, LLC | All Rights Reserved
  • 13. © 2020 Puma Security, LLC | All Rights Reserved OWASP Application Security Verification Standards • https://owasp.org/www-project-application-security- verification-standard/ OWASP User Security Stories • https://github.com/OWASP/user-security-stories Puma Security: Puma Prey Tests • https://github.com/pumasecurity/puma-prey SPUTR • https://github.com/sethlaw/sputr • https://www.blackhat.com/asia- 17/briefings.html#domo-arigato-mr.-roboto-security- robots-a-la-unit-testing SECURITY UNIT TESTING RESOURCES © 2022 Puma Security, LLC | All Rights Reserved
  • 14. © 2020 Puma Security, LLC | All Rights Reserved InfoSec Pro Tip - Work with software engineers to build security-focused unit test suites: • Create abuse cases and evil user stories • Burn the security stories into code • Run security test cases to enforce security requirements • Require negative test cases that should never pass • Focus on high risk code and business logic flaws first BUILDING A SECURITY UNIT TESTING SUITE © 2022 Puma Security, LLC | All Rights Reserved
  • 15. © 2020 Puma Security, LLC | All Rights Reserved High risk code responsible for any of the following functionality are logical candidates: HIGH RISK CODE CANDIDATES • Authentication • Password handling • Access control • Output encoding • Input validation • Security Unit Tests • Data entitlement checks • User management • Handling confidential data • Cryptography • Infrastructure code • Declarative pipeline definitions © 2022 Puma Security, LLC | All Rights Reserved
  • 16. © 2020 Puma Security, LLC | All Rights Reserved EVIL USER STORIES © 2022 Puma Security, LLC | All Rights Reserved
  • 17. © 2020 Puma Security, LLC | All Rights Reserved As a user, I shall not be able to create an account with a weak password. ASVS 2.1| PASSWORD SECURITY © 2022 Puma Security, LLC | All Rights Reserved ASVS 2.1.1: Verify that user set passwords are at least 12 characters in length (after multiple spaces are combined). ASVS 2.1.7: Verify that passwords submitted during account registration, login, and password change are checked against a set of breached passwords
  • 18. © 2020 Puma Security, LLC | All Rights Reserved ASVS 2.1.1 & 2.1.7 | SECURITY UNIT TEST Creating a new user account with a weak, known breached password: [Theory] [InlineData(7, "Tinkerbell", HttpStatusCode.BadRequest)] public async Task ASVS_2_1_7(int index, string password, HttpStatusCode statusCode) { // Act … CreateUserRequest.Password = password; var response = await Client.CreateUser(CreateUserRequest); // Assert response.StatusCode.Should().Be(statusCode); } 1 2 3 4 5 6 7 8 9 10 11 12 13 © 2022 Puma Security, LLC | All Rights Reserved
  • 19. © 2020 Puma Security, LLC | All Rights Reserved As an attacker, I shall not be able to tamper with authentication tokens. ASVS 3.5 | TOKEN SESSION MANAGEMENT © 2022 Puma Security, LLC | All Rights Reserved ASVS 3.5.3: Verify that stateless session tokens use digital signatures, encryption, and other countermeasures to protect against tampering, enveloping, replay, null cipher, and key substitution attacks. ASVS 3.5.2: Verify the application uses session tokens rather than static API secrets and keys, except with legacy implementations.
  • 20. © 2020 Puma Security, LLC | All Rights Reserved ASVS 2.5.3 | SECURTY UNIT TEST Request user profile data without a JWT signature: [Theory] [InlineData(SeedData.Member2Email, SeedData.User2Password, HttpStatusCode.Unauthorized)] public async Task ASVS_3_5_3(string username, string password, HttpStatusCode statusCode) { // Act var token = await Client.GetJwtAsync(username, password); //Strip signature var tamperedToken = $"{token.Split(".")[0]}.{token.Split(".")[1]}."; Client.DefaultRequestHeaders.Add("Authorization", $"Bearer {tamperedToken}"); var response = await Client.GetUserByMemberId(Convert.ToInt32(memberId)); // Assert response.StatusCode.Should().Be(statusCode); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 © 2022 Puma Security, LLC | All Rights Reserved
  • 21. © 2020 Puma Security, LLC | All Rights Reserved As an attacker, I shall not be able to access a profile that belongs to another user. ASVS 4.2 | OPERATION LEVEL ACCESS CONTROL © 2022 Puma Security, LLC | All Rights Reserved ASVS 4.2.1: Verify that sensitive data and APIs are protected against Insecure Direct Object Reference (IDOR) attacks targeting creation, reading, updating and deletion of records, such as creating or updating someone else's record, viewing everyone's records, or deleting all records.
  • 22. © 2020 Puma Security, LLC | All Rights Reserved ASVS 4.2.1 | SECURITY UNIT TEST Member level user reading the admin user's profile: [Theory] [InlineData(SeedData.Member2Email, SeedData.User2Password, 2, HttpStatusCode.OK)] [InlineData(SeedData.Member2Email, SeedData.User2Password, 1, HttpStatusCode.Unauthorized)] public async Task ASVS_4_2_1(string username, string password, int memberId, HttpStatusCode statusCode) { // Act var token = await Client.GetJwtAsync(username, password); Client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}"); var response = await Client.GetUserByMemberId(memberId); // Assert response.StatusCode.Should().Be(statusCode); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 © 2022 Puma Security, LLC | All Rights Reserved
  • 23. © 2020 Puma Security, LLC | All Rights Reserved As an attacker, I shall not be able to inject malicious data into the application. ASVS 5.2 | SANITIZATION & SANDBOXING © 2022 Puma Security, LLC | All Rights Reserved ASVS 5.2.2: Verify that unstructured data is sanitized to enforce safety measures such as allowed characters and length. ASVS 5.2.6: Verify that the application protects against SSRF attacks, by validating or sanitizing untrusted data or HTTP file metadata, such as filenames and URL input fields, and uses allow lists of protocols, domains, paths and ports.
  • 24. © 2020 Puma Security, LLC | All Rights Reserved ASVS 5.2 | SECURITY UNIT TEST Storing malicious SSRF input data in the database name field: [InlineData(SeedData.Member1Email, SeedData.User1Password, "http://169.254.169.254", HttpStatusCode.BadRequest)] [InlineData(SeedData.Member1Email, SeedData.User1Password, "http://metadata.google.internal", HttpStatusCode.BadRequest)] public async Task ASVS_5_2(string username, string password, string name, HttpStatusCode statusCode) { … //Set payload and test CreateAnimalRequest.Name = name; var response = await Client.PostAnimal(CreateAnimalRequest); // Assert response.StatusCode.Should().Be(statusCode); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 © 2022 Puma Security, LLC | All Rights Reserved
  • 25. © 2020 Puma Security, LLC | All Rights Reserved CONTINUOUS INTEGRATION TESTING © 2022 Puma Security, LLC | All Rights Reserved
  • 26. © 2020 Puma Security, LLC | All Rights Reserved Prerequisite for automating build, test, and deployment: • Commit triggers an automated pipeline • Executes security unit tests • Provides fast feedback to engineers (and security) • Enforces continuous security compliance CONTINUOUS INTEGRATION TESTING © 2022 Puma Security, LLC | All Rights Reserved
  • 27. © 2020 Puma Security, LLC | All Rights Reserved .NET TEST | GENERATING TEST RESULT DATA Exporting unit tests results to a test results file: <ResultSummary outcome="Failed"> <Counters total="10" executed="10" passed="9" failed="1" error="0" timeout="0" aborted="0" inconclusive="0" passedButRunAborted="0" notRunnable="0" notExecuted="0" disconnected="0" warning="0" completed="0" inProgress="0" pending="0" /> </ResultSummary> 1 2 3 4 5 6 $ cd ./test/Coyote.Tests $ dotnet test –logger "trx;LogFileName=coyote.trx" 1 2 Example .NET test unit test output results: © 2022 Puma Security, LLC | All Rights Reserved
  • 28. © 2020 Puma Security, LLC | All Rights Reserved GH ACTION | UNIT TEST CONFIGURATION GH Action workflow executing and parsing unit test results: jobs: build: name: Puma Prey runs-on: ubuntu-18.04 steps: … - name: Test shell: bash run: | cd ./test/Coyote.Tests dotnet test --logger "trx;LogFileName=coyote.trx" - name: Publish Test Results uses: dorny/test-reporter@v1 with: name: "Coyote Test Results" path: "test/Coyote.Tests/TestResults/*.trx" reporter: "dotnet-trx" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 © 2022 Puma Security, LLC | All Rights Reserved
  • 29. © 2020 Puma Security, LLC | All Rights Reserved GH ACTION | UNIT TEST RESULTS Viewing GH Action workflows and unit test results: © 2022 Puma Security, LLC | All Rights Reserved
  • 30. © 2020 Puma Security, LLC | All Rights Reserved Keys To Success: • Security teams often ignore unit testing and opt for long running, unreliable scanners to find low hanging fruit • Work with software engineers to create abuse cases and unit & integration tests based on ASVS requirements • Integrate security unit tests in Continuous Integration pipelines & monitor failing test cases • Failing security tests should halt the build and require immediate attention before releasing changes SECURITY UNIT TESTING SUMMARY © 2022 Puma Security, LLC | All Rights Reserved
  • 31. © 2020 Puma Security, LLC | All Rights Reserved THANK YOU FOR ATTENDING! OWASP DevSlop Eric Johnson Principal Security Engineer, Puma Security Senior Instructor, SANS Institute www.linkedin.com/in/eric-m-johnson @emjohn20 ejohnson@pumasecurity.io © 2022 Puma Security, LLC | All Rights Reserved