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
core/catalog_views.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""Public pages: the rule catalogue, standards coverage and how ratings are calculated."""
|
|
2
|
+
from collections import Counter
|
|
3
|
+
|
|
4
|
+
from django.contrib import messages
|
|
5
|
+
from django.contrib.auth.decorators import login_not_required
|
|
6
|
+
from django.core.exceptions import PermissionDenied
|
|
7
|
+
from django.core.paginator import Paginator
|
|
8
|
+
from django.http import Http404
|
|
9
|
+
from django.shortcuts import redirect, render
|
|
10
|
+
from django.utils.safestring import mark_safe
|
|
11
|
+
from django.views.decorators.http import require_POST, require_safe
|
|
12
|
+
from markdown_it import MarkdownIt
|
|
13
|
+
|
|
14
|
+
from . import catalog, ratings
|
|
15
|
+
from .catalog import update
|
|
16
|
+
|
|
17
|
+
LANGUAGES = [("python", "Python"), ("javascript", "JS / TS"), ("html", "HTML"), ("css", "CSS"),
|
|
18
|
+
("web", "Live pages"), ("c/c++", "C / C++"), ("iac", "Docker / IaC")]
|
|
19
|
+
ORIGINS = [("imported", "Imported"), ("codewatch", "codewatch built-in"), ("custom", "Custom")]
|
|
20
|
+
# Raw HTML in tool documentation is not rendered; links and code blocks are.
|
|
21
|
+
MARKDOWN = MarkdownIt("commonmark", {"html": False}).enable("table")
|
|
22
|
+
|
|
23
|
+
FILTERS = {
|
|
24
|
+
"tool": lambda r, v: r["tool"] == v,
|
|
25
|
+
"type": lambda r, v: r["type"] == v,
|
|
26
|
+
"origin": lambda r, v: r.get("origin") == v,
|
|
27
|
+
"language": catalog.speaks,
|
|
28
|
+
"cwe": lambda r, v: v.isdigit() and int(v) in r["cwe"],
|
|
29
|
+
"owasp": lambda r, v: v in r["owasp"],
|
|
30
|
+
"wcag": lambda r, v: v in r["wcag"],
|
|
31
|
+
"duplicates": lambda r, _v: bool(r.get("same_as")),
|
|
32
|
+
"q": lambda r, v: v.lower() in f"{r['id']} {r['title']} {r['summary']}".lower(),
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def matches(rule, params):
|
|
37
|
+
return all(test(rule, params[key]) for key, test in FILTERS.items() if params.get(key))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@login_not_required
|
|
41
|
+
@require_safe
|
|
42
|
+
def rules(request):
|
|
43
|
+
all_rules, standards = catalog.load()
|
|
44
|
+
if request.user.is_authenticated:
|
|
45
|
+
update.maybe_launch()
|
|
46
|
+
found = [r for r in all_rules if matches(r, request.GET)]
|
|
47
|
+
page = Paginator(found, 50).get_page(request.GET.get("page"))
|
|
48
|
+
query = request.GET.copy()
|
|
49
|
+
query.pop("page", None)
|
|
50
|
+
return render(request, "core/rules.html", {
|
|
51
|
+
"page": page, "total": len(all_rules), "f": request.GET, "query": query.urlencode(),
|
|
52
|
+
"tools": sorted(Counter(r["tool"] for r in all_rules).items()), "languages": LANGUAGES,
|
|
53
|
+
"origins": [(o, n, sum(1 for r in all_rules if r.get("origin") == o)) for o, n in ORIGINS],
|
|
54
|
+
"types": sorted({r["type"] for r in all_rules}), "standards": standards,
|
|
55
|
+
"meta": catalog.meta(), "changes": catalog.changes(), "status": update.status(),
|
|
56
|
+
"interval_days": update.update_interval().days,
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@require_POST
|
|
61
|
+
def update_rules(request):
|
|
62
|
+
if not request.user.is_superuser:
|
|
63
|
+
raise PermissionDenied
|
|
64
|
+
if update.running():
|
|
65
|
+
messages.info(request, "An update is already running.")
|
|
66
|
+
else:
|
|
67
|
+
update.launch(upgrade=request.POST.get("upgrade") == "1")
|
|
68
|
+
messages.success(request, "Rule update started. Reload this page in a minute or two.")
|
|
69
|
+
return redirect("rules")
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@login_not_required
|
|
73
|
+
@require_safe
|
|
74
|
+
def rule_detail(request, rule_id):
|
|
75
|
+
rule = catalog.find(rule_id)
|
|
76
|
+
if rule is None:
|
|
77
|
+
raise Http404(rule_id)
|
|
78
|
+
_, standards = catalog.load()
|
|
79
|
+
names, details = standards.get("cwe_names", {}), standards.get("cwe_details", {})
|
|
80
|
+
doc = catalog.docs().get(rule_id)
|
|
81
|
+
return render(request, "core/rule.html", {
|
|
82
|
+
"rule": rule,
|
|
83
|
+
# Safe to mark: MARKDOWN is configured with html=False, so raw HTML in the source is escaped.
|
|
84
|
+
"doc": mark_safe(MARKDOWN.render(doc)) if doc else None, # nosec B308 B703 # nosemgrep
|
|
85
|
+
"cwes": [{"id": c, "name": names.get(str(c), ""), **(details.get(str(c)) or {})} for c in rule["cwe"]],
|
|
86
|
+
"same_as": [r for r in (catalog.find(i) for i in rule.get("same_as", [])) if r],
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@login_not_required
|
|
91
|
+
@require_safe
|
|
92
|
+
def standards(request):
|
|
93
|
+
all_rules, std = catalog.load()
|
|
94
|
+
if not std:
|
|
95
|
+
raise Http404("Catalogue not imported; run manage.py buildcatalog")
|
|
96
|
+
langs = [code for code, _ in LANGUAGES if code not in ("web", "html", "css")]
|
|
97
|
+
top25, owasp, wcag = catalog.coverage(all_rules, std, langs)
|
|
98
|
+
by_level = Counter((sc["level"], sc["rules"] > 0) for sc in wcag)
|
|
99
|
+
return render(request, "core/standards.html", {
|
|
100
|
+
"std": std, "top25": top25, "owasp": owasp, "wcag": [sc for sc in wcag if sc["level"] in ("A", "AA")],
|
|
101
|
+
"langs": [(c, n) for c, n in LANGUAGES if c in langs],
|
|
102
|
+
"wcag_summary": {lvl: (by_level[(lvl, True)], by_level[(lvl, True)] + by_level[(lvl, False)])
|
|
103
|
+
for lvl in ("A", "AA")},
|
|
104
|
+
"rule_count": len(all_rules),
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
@login_not_required
|
|
109
|
+
@require_safe
|
|
110
|
+
def ratings_help(request):
|
|
111
|
+
return render(request, "core/ratings.html", {
|
|
112
|
+
"remediation": ratings.REMEDIATION_MINUTES, "minutes_per_line": ratings.MINUTES_PER_LINE,
|
|
113
|
+
"debt_limits": ratings.DEBT_RATIO_LIMITS, "review_limits": ratings.REVIEW_LIMITS,
|
|
114
|
+
"score": ratings.SCORE,
|
|
115
|
+
})
|