codewatch-scan 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- codewatch/__init__.py +0 -0
- codewatch/__main__.py +14 -0
- codewatch/asgi.py +16 -0
- codewatch/settings.py +175 -0
- codewatch/urls.py +40 -0
- codewatch/wsgi.py +16 -0
- codewatch_scan-0.1.0.dist-info/METADATA +81 -0
- codewatch_scan-0.1.0.dist-info/RECORD +136 -0
- codewatch_scan-0.1.0.dist-info/WHEEL +5 -0
- codewatch_scan-0.1.0.dist-info/entry_points.txt +4 -0
- codewatch_scan-0.1.0.dist-info/licenses/LICENSE +21 -0
- codewatch_scan-0.1.0.dist-info/top_level.txt +2 -0
- core/__init__.py +0 -0
- core/analyzers/__init__.py +19 -0
- core/analyzers/accessibility.py +199 -0
- core/analyzers/base.py +192 -0
- core/analyzers/body_models.py +154 -0
- core/analyzers/codewatch_checks.py +394 -0
- core/analyzers/constant_branches.py +251 -0
- core/analyzers/containers.py +316 -0
- core/analyzers/coverage.py +131 -0
- core/analyzers/dependencies.py +347 -0
- core/analyzers/drf_serializers.py +65 -0
- core/analyzers/else_branches.py +106 -0
- core/analyzers/extra.py +400 -0
- core/analyzers/flask_resources.py +65 -0
- core/analyzers/inline_scripts.py +50 -0
- core/analyzers/jinja_sandboxes.py +63 -0
- core/analyzers/match_statements.py +148 -0
- core/analyzers/multi_tools.py +888 -0
- core/analyzers/php_template_sinks.py +444 -0
- core/analyzers/project_checks.py +150 -0
- core/analyzers/python_tools.py +333 -0
- core/analyzers/route_converters.py +237 -0
- core/analyzers/slices.py +94 -0
- core/analyzers/starred_targets.py +42 -0
- core/analyzers/stored_fields.py +386 -0
- core/analyzers/summaries.py +1387 -0
- core/analyzers/template_sinks.py +162 -0
- core/api.py +360 -0
- core/apps.py +6 -0
- core/benchmark.py +955 -0
- core/bundled/catalog/codewatch/rules/javascript-crypto.yml +224 -0
- core/bundled/catalog/codewatch/rules/javascript-injection.yml +116 -0
- core/bundled/catalog/codewatch/rules/javascript-taint.yml +1539 -0
- core/bundled/catalog/codewatch/rules/javascript-web.yml +562 -0
- core/bundled/catalog/codewatch/rules/php-web.yml +719 -0
- core/bundled/catalog/codewatch/rules/python-crypto.yml +203 -0
- core/bundled/catalog/codewatch/rules/python-django.yml +267 -0
- core/bundled/catalog/codewatch/rules/python-injection.yml +115 -0
- core/bundled/catalog/codewatch/rules/python-web.yml +3382 -0
- core/bundled/catalog/custom/mappings.json +360 -0
- core/bundled/catalog/custom/overrides.json +4 -0
- core/bundled/catalog/custom/rules/django-settings.yml +19 -0
- core/bundled/catalog/imported/changes.json +5 -0
- core/bundled/catalog/imported/docs.json +1143 -0
- core/bundled/catalog/imported/meta.json +54 -0
- core/bundled/catalog/imported/rules.json +85421 -0
- core/bundled/catalog/imported/standards.json +11191 -0
- core/bundled/tools/analyzers.lock +786 -0
- core/bundled/tools/axe-scan.mjs +45 -0
- core/bundled/tools/checkov.lock +2463 -0
- core/bundled/tools/codewatch-checks.mjs +99 -0
- core/bundled/tools/eslint-a11y.config.js +16 -0
- core/bundled/tools/eslint-quality.config.js +63 -0
- core/bundled/tools/eslint-typed.config.js +18 -0
- core/bundled/tools/package-lock.json +6102 -0
- core/bundled/tools/package.json +32 -0
- core/bundled/tools/rule-metadata.mjs +56 -0
- core/bundled/tools/semgrep.lock +1232 -0
- core/bundled/tools/stylelint.config.json +11 -0
- core/catalog/__init__.py +190 -0
- core/catalog/build.py +84 -0
- core/catalog/merge.py +122 -0
- core/catalog/sources.py +418 -0
- core/catalog/standards.py +119 -0
- core/catalog/update.py +99 -0
- core/catalog_views.py +115 -0
- core/client.py +645 -0
- core/collect.py +518 -0
- core/duplicates.py +60 -0
- core/fingerprint.py +25 -0
- core/folders.py +73 -0
- core/gate.py +77 -0
- core/git.py +149 -0
- core/jobs.py +86 -0
- core/management/__init__.py +0 -0
- core/management/commands/__init__.py +0 -0
- core/management/commands/addproject.py +40 -0
- core/management/commands/buildcatalog.py +15 -0
- core/management/commands/scan.py +74 -0
- core/management/commands/updatecatalog.py +14 -0
- core/mcp_server.py +140 -0
- core/middleware.py +17 -0
- core/migrations/0001_initial.py +115 -0
- core/migrations/0002_auth_tokens_a11y.py +60 -0
- core/migrations/0003_default_admin.py +43 -0
- core/migrations/0004_project_members.py +28 -0
- core/migrations/0005_uploads_and_sources.py +55 -0
- core/migrations/0006_thresholds.py +28 -0
- core/migrations/0007_also_reported_by.py +18 -0
- core/migrations/0008_new_code_period.py +18 -0
- core/migrations/0009_resolution_safe.py +18 -0
- core/migrations/0010_analysis_progress.py +18 -0
- core/migrations/0011_overall_gate_conditions.py +20 -0
- core/migrations/__init__.py +0 -0
- core/models.py +323 -0
- core/network.py +41 -0
- core/paths.py +29 -0
- core/ratings.py +67 -0
- core/runner.py +168 -0
- core/templates/core/account.html +30 -0
- core/templates/core/analysis.html +49 -0
- core/templates/core/base.html +121 -0
- core/templates/core/form_table.html +12 -0
- core/templates/core/gate_badge.html +1 -0
- core/templates/core/index.html +26 -0
- core/templates/core/issues.html +38 -0
- core/templates/core/login.html +13 -0
- core/templates/core/new_project.html +27 -0
- core/templates/core/password_change.html +10 -0
- core/templates/core/project.html +40 -0
- core/templates/core/rating.html +1 -0
- core/templates/core/ratings.html +32 -0
- core/templates/core/rule.html +33 -0
- core/templates/core/rules.html +42 -0
- core/templates/core/scan_progress.html +2 -0
- core/templates/core/settings.html +36 -0
- core/templates/core/source.html +15 -0
- core/templates/core/standards.html +30 -0
- core/templates/core/user_edit.html +15 -0
- core/templates/core/users.html +18 -0
- core/templatetags/__init__.py +0 -0
- core/templatetags/codewatch.py +42 -0
- core/tool_setup.py +68 -0
- core/views.py +564 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{% extends "core/base.html" %}{% load codewatch %}
|
|
2
|
+
{% block title %}Standards coverage · codewatch{% endblock %}
|
|
3
|
+
{% block crumbs %}<li aria-current="page">Standards</li>{% endblock %}
|
|
4
|
+
{% block content %}
|
|
5
|
+
<h1>Standards coverage</h1>
|
|
6
|
+
<p>How many of codewatch's {{ rule_count }} rules address each weakness or category, by language. A rule counts towards a CWE if it targets that CWE or a more specific one beneath it in MITRE's hierarchy. A zero is a gap. Automated rules can only partially cover most of these, so a non-zero count doesn't mean a weakness is fully prevented.</p>
|
|
7
|
+
<p class="muted">Data: {{ std.source }}; CWE {{ std.cwe_version }} ({{ std.cwe_date }}). {{ std.wcag.source }}.</p>
|
|
8
|
+
|
|
9
|
+
<section class="card" aria-labelledby="top25-h"><h2 id="top25-h">{{ std.top25.name }}</h2>
|
|
10
|
+
<table><caption class="sr-only">Rules per language for each Top 25 weakness</caption>
|
|
11
|
+
<thead><tr><th scope="col">Rank</th><th scope="col">Weakness</th>{% for c, n in langs %}<th scope="col">{{ n }}</th>{% endfor %}</tr></thead><tbody>
|
|
12
|
+
{% for t in top25 %}<tr><td>{{ t.rank }}</td><th scope="row"><a href="{% url 'rules' %}?cwe={{ t.cwe }}">CWE-{{ t.cwe }}</a> {{ t.name }}</th>
|
|
13
|
+
{% for c, n in langs %}{% with v=t.by_language|get:c %}<td{% if not v %} class="fail"{% endif %}>{% if v %}{{ v }}{% else %}gap{% endif %}</td>{% endwith %}{% endfor %}</tr>{% endfor %}
|
|
14
|
+
</tbody></table></section>
|
|
15
|
+
|
|
16
|
+
<section class="card" aria-labelledby="owasp-h"><h2 id="owasp-h">{{ std.owasp.name }}</h2>
|
|
17
|
+
<table><caption class="sr-only">Rules per language for each OWASP category</caption>
|
|
18
|
+
<thead><tr><th scope="col">Category</th>{% for c, n in langs %}<th scope="col">{{ n }}</th>{% endfor %}</tr></thead><tbody>
|
|
19
|
+
{% for o in owasp %}<tr><th scope="row"><a href="{% url 'rules' %}?owasp={{ o.id|urlencode }}">{{ o.id }}</a> {{ o.name }}</th>
|
|
20
|
+
{% for c, n in langs %}{% with v=o.by_language|get:c %}<td{% if not v %} class="fail"{% endif %}>{% if v %}{{ v }}{% else %}gap{% endif %}</td>{% endwith %}{% endfor %}</tr>{% endfor %}
|
|
21
|
+
</tbody></table></section>
|
|
22
|
+
|
|
23
|
+
<section class="card" aria-labelledby="wcag-h"><h2 id="wcag-h">WCAG 2.2 levels A and AA</h2>
|
|
24
|
+
<p>Automated checks reach {{ wcag_summary.A.0 }} of {{ wcag_summary.A.1 }} level A and {{ wcag_summary.AA.0 }} of {{ wcag_summary.AA.1 }} level AA success criteria. The rest need manual testing, as they do with any tool.</p>
|
|
25
|
+
<table><caption class="sr-only">Rules per WCAG success criterion</caption>
|
|
26
|
+
<thead><tr><th scope="col">Criterion</th><th scope="col">Level</th><th scope="col">Rules</th></tr></thead><tbody>
|
|
27
|
+
{% for sc in wcag %}<tr><th scope="row"><a href="{{ sc.url }}" rel="noopener noreferrer">{{ sc.sc }} {{ sc.title }}</a></th><td>{{ sc.level }}</td>
|
|
28
|
+
<td>{% if sc.rules %}<a href="{% url 'rules' %}?wcag={{ sc.sc }}">{{ sc.rules }}</a>{% else %}<span class="muted">manual</span>{% endif %}</td></tr>{% endfor %}
|
|
29
|
+
</tbody></table></section>
|
|
30
|
+
{% endblock %}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{% extends "core/base.html" %}
|
|
2
|
+
{% block title %}{{ target.username }} · Users{% endblock %}
|
|
3
|
+
{% block crumbs %}<li><a href="{% url 'users' %}">Users</a></li><li aria-current="page">{{ target.username }}</li>{% endblock %}
|
|
4
|
+
{% block content %}
|
|
5
|
+
<h1>{{ target.username }}</h1>
|
|
6
|
+
<section class="card" aria-labelledby="reset-h" style="max-width:720px">
|
|
7
|
+
<h2 id="reset-h">Reset password</h2>
|
|
8
|
+
<p class="muted">They will be asked to change it when they next log in.</p>
|
|
9
|
+
<form method="post">{% csrf_token %}{% include "core/form_table.html" %}<p><button>Set password</button></p></form>
|
|
10
|
+
</section>
|
|
11
|
+
<section class="card" aria-labelledby="status-h">
|
|
12
|
+
<h2 id="status-h">Status</h2>
|
|
13
|
+
<form method="post">{% csrf_token %}<button name="toggle_active" value="1">{% if target.is_active %}Deactivate{% else %}Activate{% endif %} {{ target.username }}</button></form>
|
|
14
|
+
</section>
|
|
15
|
+
{% endblock %}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{% extends "core/base.html" %}
|
|
2
|
+
{% block title %}Users · codewatch{% endblock %}
|
|
3
|
+
{% block crumbs %}<li aria-current="page">Users</li>{% endblock %}
|
|
4
|
+
{% block content %}
|
|
5
|
+
<h1>Users</h1>
|
|
6
|
+
<div class="card"><table>
|
|
7
|
+
<caption class="sr-only">All users</caption>
|
|
8
|
+
<thead><tr><th scope="col">Username</th><th scope="col">Email</th><th scope="col">Role</th><th scope="col">Status</th><th scope="col">Last login</th></tr></thead>
|
|
9
|
+
<tbody>
|
|
10
|
+
{% for u in users %}<tr><th scope="row"><a href="{% url 'user_edit' u.pk %}">{{ u.username }}</a></th><td>{{ u.email }}</td>
|
|
11
|
+
<td>{% if u.is_superuser %}Administrator{% else %}User{% endif %}</td><td>{% if u.is_active %}Active{% else %}<span class="muted">Deactivated</span>{% endif %}</td>
|
|
12
|
+
<td>{{ u.last_login|date:"Y-m-d H:i"|default:"never" }}</td></tr>{% endfor %}
|
|
13
|
+
</tbody></table></div>
|
|
14
|
+
<section class="card" aria-labelledby="add-h" style="max-width:720px">
|
|
15
|
+
<h2 id="add-h">Add a user</h2>
|
|
16
|
+
<form method="post">{% csrf_token %}{% include "core/form_table.html" %}<p><button>Add user</button></p></form>
|
|
17
|
+
</section>
|
|
18
|
+
{% endblock %}
|
|
File without changes
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from django import template
|
|
2
|
+
|
|
3
|
+
register = template.Library()
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@register.filter
|
|
7
|
+
def num(value):
|
|
8
|
+
if value is None:
|
|
9
|
+
return "\u2013"
|
|
10
|
+
return f"{value:g}" if isinstance(value, float) else value
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@register.filter
|
|
14
|
+
def label(key):
|
|
15
|
+
return str(key).replace("_", " ")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@register.filter
|
|
19
|
+
def grade(rating):
|
|
20
|
+
from core.ratings import grade as to_grade
|
|
21
|
+
|
|
22
|
+
return to_grade(rating)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@register.filter
|
|
26
|
+
def score_grade(score):
|
|
27
|
+
from core.ratings import score_grade as to_grade
|
|
28
|
+
|
|
29
|
+
return to_grade(score) if score is not None else "\u2013"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@register.simple_tag
|
|
33
|
+
def rule_for(issue):
|
|
34
|
+
"""Catalogue entry for an issue, or None."""
|
|
35
|
+
from core.catalog import lookup
|
|
36
|
+
|
|
37
|
+
return lookup(issue.tool, issue.rule)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@register.filter
|
|
41
|
+
def get(mapping, key):
|
|
42
|
+
return mapping.get(key) if mapping else None
|
core/tool_setup.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""Installing the analyzers codewatch runs (`codewatch setup`, `make tools`, a catalogue update's tool upgrade).
|
|
2
|
+
|
|
3
|
+
Always at the versions and hashes in tools/*.lock and tools/package-lock.json, never whatever an index serves today:
|
|
4
|
+
new versions come from regenerating those files (make lock) and committing them. Semgrep and checkov get a venv
|
|
5
|
+
each, because their pins clash with codewatch's.
|
|
6
|
+
"""
|
|
7
|
+
import shutil
|
|
8
|
+
import subprocess
|
|
9
|
+
import sys
|
|
10
|
+
|
|
11
|
+
from .analyzers.base import TOOLS_DIR
|
|
12
|
+
from .paths import INSTALLED, shipped
|
|
13
|
+
|
|
14
|
+
ISOLATED_ANALYZERS = ["semgrep", "checkov"]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def run_step(args, log, cwd=None):
|
|
18
|
+
log("$ " + " ".join(str(a) for a in args))
|
|
19
|
+
proc = subprocess.run(args, capture_output=True, text=True, check=False, cwd=cwd)
|
|
20
|
+
if proc.returncode:
|
|
21
|
+
log(proc.stderr.strip()[-1500:])
|
|
22
|
+
return proc.returncode == 0
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def pip_install_locked(pip, lock, log):
|
|
26
|
+
return run_step([*pip, "install", "-q", "--require-hashes", "-r", str(lock)], log)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def copy_tool_files(target, log):
|
|
30
|
+
"""An installed package's tool files (configs, scripts, lock files) into the folder its analyzers go in: the Node
|
|
31
|
+
scripts and configs load their packages from the node_modules beside them."""
|
|
32
|
+
source = shipped("tools")
|
|
33
|
+
if source.resolve() == target.resolve():
|
|
34
|
+
return
|
|
35
|
+
target.mkdir(parents=True, exist_ok=True)
|
|
36
|
+
for path in sorted(source.iterdir()):
|
|
37
|
+
if path.is_file():
|
|
38
|
+
shutil.copy2(path, target / path.name)
|
|
39
|
+
log(f"Copied codewatch's tool files to {target}")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def install_node_tools(target, log, browser):
|
|
43
|
+
if not shutil.which("npm"):
|
|
44
|
+
log("npm not found: install Node.js 20 or later for the JavaScript, CSS and HTML analyzers, then run "
|
|
45
|
+
"codewatch setup again")
|
|
46
|
+
return False
|
|
47
|
+
ok = run_step(["npm", "ci", "--no-fund", "--no-audit"], log, cwd=target)
|
|
48
|
+
if browser:
|
|
49
|
+
ok &= run_step([str(target / "node_modules/.bin/playwright"), "install", "--only-shell", "chromium"], log)
|
|
50
|
+
return ok
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def install_tools(log, create_venvs=True, browser=False, target=TOOLS_DIR):
|
|
54
|
+
"""Every analyzer into `target`; False if any step failed. create_venvs=False only refreshes the venvs that
|
|
55
|
+
exist. An installed package's own Python analyzers came pinned with it (pyproject.toml), so analyzers.lock is
|
|
56
|
+
only for a checkout's venv."""
|
|
57
|
+
copy_tool_files(target, log)
|
|
58
|
+
ok = INSTALLED or pip_install_locked([sys.executable, "-m", "pip"], target / "analyzers.lock", log)
|
|
59
|
+
for name in ISOLATED_ANALYZERS:
|
|
60
|
+
venv = target / f"{name}-venv"
|
|
61
|
+
pip = venv / "bin" / "pip"
|
|
62
|
+
if create_venvs and not pip.exists():
|
|
63
|
+
ok &= run_step([sys.executable, "-m", "venv", str(venv)], log)
|
|
64
|
+
if pip.exists():
|
|
65
|
+
ok &= pip_install_locked([str(pip)], target / f"{name}.lock", log)
|
|
66
|
+
if (target / "package-lock.json").exists():
|
|
67
|
+
ok &= install_node_tools(target, log, browser)
|
|
68
|
+
return ok
|