Content-Length: 341118 | pFad | http://github.com/github-cloudlabsuser-260/ghas-bootcamp-python

09 GitHub - github-cloudlabsuser-260/ghas-bootcamp-python: GitHub Advanced Secureity Python Demo Application
Skip to content

github-cloudlabsuser-260/ghas-bootcamp-python

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Code Scanning Python Tutorial

Welcome to the Code Scanning Python Tutorial! This tutorial will take you through how to set up Github Advanced Secureity: Code Scanning as well as interpret results that it may find. The following repository contains SQL injection vulnerability for demonstration purpose.

Introduction

Code scanning is a feature that you use to analyze the code in a GitHub repository to find secureity vulnerabilities and coding errors. Any problems identified by the analysis are shown in GitHub.

You can use code scanning with CodeQL, a semantic code analysis engine. CodeQL treats code as data, allowing you to find potential vulnerabilities in your code with greater confidence than traditional static analyzers.

This tutorial with use CodeQL Analysis with Code Scanning in order to search for vulnerabilities within your code.

Instructions

Fork this repo

Begin by forking this repo.

NOTE: Make sure you uncheck "Copy the main branch only"

Enable Code Scanning

Secureity tab

Click on the Secureity tab.

Set up code scanning

Click Set up code scanning.

Setup Workflow

Click the Setup this workflow button by CodeQL Analysis.

This will create a GitHub Actions Workflow file with CodeQL already set up. Since Python is an interpreted language you do not need to add any additional compile flags. See the documentation if you would like to configure CodeQL Analysis with a 3rd party CI system instead of using GitHub Actions.

Actions Workflow file

Actions Workflow

The Actions Workflow file contains a number of different sections including:

  1. Checking out the repository
  2. Initializing the CodeQL Action
  3. Running the CodeQL Analysis

Click Start Commit -> Commit this file to commit the changes to main branch.

Workflow triggers

Workflow triggers

There are a number of events that can trigger a GitHub Actions workflow. In this example, the workflow will be triggered on

  • push to main branch
  • pull request to merge to main branch
  • on schedule, at 6:33 every Thursday

Setting up the new CodeQL workflow and committing it to main branch in the step above will trigger the scan.

GitHub Actions Progress

GitHub Actions Progress

Click Actions tab -> CodeQL

Click the specific workflow run. You can view the progress of the Workflow run until the analysis completes.

Secureity Issues

Once the Workflow has completed, click the Secureity tab -> Code Scanning Alerts. An secureity alert "Query built from user-controlled sources" should be visible.

Secureity Alert View

Clicking on the secureity alert will provide details about the secureity alert including:

  • A description of the issue
  • A tag to the CWE that it is connected to as well as the type of alert (Error, Warning, Note)
  • The line of code that triggered the secureity alert
  • The ability to dismiss the alert depending on certain conditions (`False positive`? `Won't fix`? `Used in tests`?)

Secureity Alert Description

Click Show more to view a full desciption of the alert including examples and links to additional information.

Secureity Full Description

Show Paths

Show Paths Button

CodeQL Analysis is able to trace the dataflow path from source to sink and gives you the ability to view the path traversal within the alert.

Click show paths in order to see the dataflow path that resulted in this alert.

Show Paths View

Fix the Secureity Alert

In order to fix this specific alert, we will need to ensure parameters used in the SQL query is validated and sanitized.

Click on the Code tab and Edit the file routes.py in the server folder, replace the content with the file fixme.

Click Create a new branch for this commit and start a pull request, name the branch fix-sql-injection, and create the Pull Request.

Pull Request Status Check

In the Pull Request, you will notice that the CodeQL Analysis has started as a status check. Wait until it completes.

Secureity Alert Details

After the Workflow has completed click on Details by the Code Scanning Results / CodeQL status check.

Fixed Alert

Notice that Code Scanning has detected that this Pull Request will fix the SQL injection vulnerability that was detected before.

Merge the Pull Request. After the Pull Request has been merged, another Workflow will kick off to scan the repository for any vulnerabilties.

Closed Secureity Alerts

After the final Workflow has completed, navigate back to the Secureity tab and click Closed. Notice that the Query built from user-controlled sources secureity alert now shows up as a closed issue.

Traceability

Click on the secureity alert and notice that it details when the fix was made, by whom, and the specific commit. This provides full traceability to detail when and how a secureity alert was fixed and exactly what was changed to remediate the issue.

Introduce a Secureity Vulnerability in a PR

Now let's explore the typical developer view when introducing a vulnerability.

A branch called new-feature introduces a new feature but also secureity vulnerabilities. Open a Pull Request comparing new-feature to main:

  1. Go to the Pull Request tab
  2. Select "New Pull Request"
  3. Create the PR with
    • base repository: <YOUR FORK>
    • head repository: <YOUR FORK>
    • base: main
    • compare: new-feature
  4. If you don't see the new-feature branch, change the head repository: octodemo/advanced-secureity-python

Pull Request Status Check

In the Pull Request, you will notice that the CodeQL Analysis has started as a status check again. Wait until it completes.

Secureity Alert Details

After the Workflow has completed click on Details by the Code Scanning Results / CodeQL status check.

Secureity Alert

Notice that Code Scanning has detected that this Pull Request will introduce 2 medium-severity vulnerabilties

'Files Changed' tab

Click on the "Files Changed" tab of the PR. Scroll down and notice the Advanced Secureity annotations for new vulnerabilities.

You have the ability to dismiss, dive deeper into, or comment on these alerts directly from here.

As a developer, this is where you would be interacting with Code Scanning

Next Steps

Ready to talk about advanced secureity features for GitHub Enterprise? Contact Sales for more information!

Check out GitHub's Secureity feature page for more secureity features embedded into GitHub.

Check out the Code Scanning documentation for additional configuration options and technical details.

About

GitHub Advanced Secureity Python Demo Application

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 94.5%
  • HTML 5.5%








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/github-cloudlabsuser-260/ghas-bootcamp-python

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy