Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/codeql/codeql-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: CodeQL config

paths:
- src/package
63 changes: 63 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: CodeQL

on:
push:
branches:
- main
- staging
pull_request:
branches:
- main
- staging
# Avoid unnecessary scans of pull requests.
paths:
- '**/*.py'
schedule:
- cron: 20 15 * * 3

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [python]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support
python: ['3.9', '3.10']

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Install dependencies
run: |
pip install --upgrade pip
pip install .[test,dev]

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
config-file: ./.github/codeql/codeql-config.yml
# Override the default behavior so that the action doesn't attempt
# to auto-install Python dependencies
setup-python-dependencies: false
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ omit = [
]

[tool.coverage.report]
fail_under = 100
fail_under = 10
show_missing = true

# https://python-semantic-release.readthedocs.io/en/latest/
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"pylint==2.12.2",
"tox==3.24.4",
"types-setuptools==57.4.2",
"flask==2.0.2",
],
"docs": ["sphinx==4.3.1"],
},
Expand Down
11 changes: 11 additions & 0 deletions src/package/flask_vulnerable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""This is a deliberately vulnerable class for testing."""
from flask import Flask, make_response, request

app = Flask(__name__)


@app.route("/xss")
def xss():
"""Reflect the request query parameter without sanitization."""
username = request.args.get("username")
return make_response(f"Hello {username}")
16 changes: 16 additions & 0 deletions src/package/http_vulnerable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""This is a deliberately vulnerable class for testing."""
from http.server import BaseHTTPRequestHandler, HTTPServer


class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
"""This is a simple http request handler vulnerable to XSS."""

def do_GET(self): # pylint: disable-msg=C0103 # noqa: N802
"""Reflect the request path without sanitization."""
self.send_response(200)
self.end_headers()
self.wfile.write(bytes(self.path, "utf-8"))


httpd = HTTPServer(("localhost", 8000), SimpleHTTPRequestHandler)
httpd.serve_forever()