Skip to content
Merged
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
13 changes: 12 additions & 1 deletion src/secfoo/web/architecture_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,18 @@ class ArchitectureDashboard:
root_causes: list[tuple[str, int]] = field(default_factory=list)
gate_mix: dict[str, int] = field(default_factory=dict)
top_standards: list[tuple[str, int]] = field(default_factory=list)
top_standards_preview: list[tuple[str, int]] = field(default_factory=list)
standards_total: int = 0


RECENT_STALE_LIMIT = 5

# The card shows the top of the ranking. The page behind the click shows
# more, but still only the head of the list — a long tail of one-off
# citations is not useful here.
STANDARDS_PREVIEW_LIMIT = 5
STANDARDS_LIST_LIMIT = 15


def build(repo: RunRepository) -> ArchitectureDashboard:
dash = ArchitectureDashboard()
Expand Down Expand Up @@ -174,7 +182,10 @@ def build(repo: RunRepository) -> ArchitectureDashboard:
dash.uncovered_ccm_domains = [name for code, name in CCM_DOMAINS if not ccm_assessed[code]]

dash.root_causes = root_cause_counter.most_common()
dash.top_standards = standards_counter.most_common()
ranked_standards = standards_counter.most_common()
dash.standards_total = len(ranked_standards)
dash.top_standards = ranked_standards[:STANDARDS_LIST_LIMIT]
dash.top_standards_preview = ranked_standards[:STANDARDS_PREVIEW_LIMIT]
dash.gate_mix = {
"approve": gate_counter.get("approve", 0),
"conditions": gate_counter.get("conditions", 0),
Expand Down
28 changes: 28 additions & 0 deletions src/secfoo/web/routes/activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,23 @@ def activity_detail(
return templates.TemplateResponse(request, "activities/detail.html", context)


@router.get("/activities/security-architecture-review/standards")
def architecture_standards(request: Request):
"""The longer most-deviated-standards ranking. Capped, so the page
stays a short list rather than every standard ever cited. The
dashboard card shows only the top five."""
with RunRepository() as repo:
dash = arch_dashboard.build(repo)
return templates.TemplateResponse(
request,
"activities/architecture_standards.html",
{
"standards": dash.top_standards,
"standards_total": dash.standards_total,
},
)


@router.get("/activities/threat-modeling/post-build")
def threat_modeling_post_build(request: Request):
"""Every threat recorded with `secfoo miss`. The dashboard card shows
Expand All @@ -225,6 +242,17 @@ def threat_modeling_post_build(request: Request):
)


@router.get("/activities/threat-modeling/accepted")
def threat_modeling_accepted(request: Request):
"""Every accepted threat, newest first. The dashboard card shows
only the newest handful."""
with RunRepository() as repo:
threats = tm_dashboard.build(repo).accepted_threats
return templates.TemplateResponse(
request, "activities/threat_modeling_accepted.html", {"threats": threats}
)


@router.get("/activities/threat-modeling/assumptions")
def threat_modeling_assumptions(request: Request):
"""Every falsified assumption from the latest model of each project.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,21 @@ <h4 class="card__title">Gate decision mix</h4>
{% call info_tip("Most-deviated standards") %}
<p>Standards the reviews cite most often as not being met.</p>
<p>A standard high on this list is a candidate for a shared control, rather than a one-off fix in each project.</p>
<p>This card shows the top five. The longer ranking is one click away, and it stops at the top fifteen.</p>
{% endcall %}
<h4 class="card__title">Most-deviated standards</h4>
{% if dash.top_standards %}
<div class="widget-scroll" data-scroll-rows="10">
{% for standard, count in dash.top_standards %}
{% if dash.top_standards_preview %}
{% for standard, count in dash.top_standards_preview %}
<div class="severity-bar">
<span class="severity-bar__dot severity-bar__dot--medium"></span>
<span class="severity-bar__label u-w-10rem">{{ standard }}</span>
<div class="severity-bar__track"><div class="severity-bar__fill severity-bar__fill--medium" data-bar-width="{{ (count / dash.top_standards[0][1] * 100) }}"></div></div>
<div class="severity-bar__track"><div class="severity-bar__fill severity-bar__fill--medium" data-bar-width="{{ (count / dash.top_standards_preview[0][1] * 100) }}"></div></div>
<span class="severity-bar__count">{{ count }}</span>
</div>
{% endfor %}
</div>
{% if dash.standards_total > dash.top_standards_preview | length %}
<a class="ds-caption u-d-block u-mt-3" href="/activities/security-architecture-review/standards">{% if dash.standards_total > dash.top_standards | length %}View top {{ dash.top_standards | length }}{% else %}View all {{ dash.standards_total }}{% endif %} &rarr;</a>
{% endif %}
{% else %}
<p class="ds-body u-color-text-muted">No standard-specific findings cited yet.</p>
{% endif %}
Expand Down
30 changes: 30 additions & 0 deletions src/secfoo/web/templates/activities/architecture_standards.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% extends "base.html" %}
{% block title %}Most-deviated standards — secfoo{% endblock %}
{% block content %}
<a href="/activities/security-architecture-review" class="ds-caption">&larr; Back to Security Architecture</a>
<span class="ds-overline u-d-block u-mt-4">Security Architecture</span>
<h1>Most-deviated standards</h1>
<p class="ds-body u-color-text-muted u-max-w-44rem">
Standards the reviews cite most often as not being met.
{% if standards_total > standards | length %}
Showing the top {{ standards | length }} of {{ standards_total }}.
{% elif standards %}
{{ standards | length }} standard{{ "s" if standards | length != 1 else "" }} cited.
{% endif %}
</p>

{% if standards %}
<div class="card u-mt-6">
{% for standard, count in standards %}
<div class="severity-bar">
<span class="severity-bar__dot severity-bar__dot--medium"></span>
<span class="severity-bar__label u-w-12rem">{{ standard }}</span>
<div class="severity-bar__track"><div class="severity-bar__fill severity-bar__fill--medium" data-bar-width="{{ (count / standards[0][1] * 100) }}"></div></div>
<span class="severity-bar__count">{{ count }}</span>
</div>
{% endfor %}
</div>
{% else %}
<div class="alert alert--info u-mt-6"><div>No standard-specific findings cited yet.</div></div>
{% endif %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{% extends "base.html" %}
{% block title %}Accepted threats — secfoo{% endblock %}
{% block content %}
<a href="/activities/threat-modeling" class="ds-caption">&larr; Back to Threat Modeling</a>
<span class="ds-overline u-d-block u-mt-4">Threat Modeling</span>
<h1>Accepted threats</h1>
<p class="ds-body u-color-text-muted u-max-w-44rem">
Every threat marked Accepted, reconciled with who signed it off. Record an owner with <code>secfoo accept create</code>.
</p>

{% if threats %}
<div class="table-wrap u-mt-6">
<table class="table">
<thead>
<tr><th>Threat</th><th>Project</th><th>Accepted by</th><th>When</th></tr>
</thead>
<tbody>
{% for item in threats %}
<tr>
<td>{{ item.threat }}</td>
<td class="u-ws-nowrap"><a href="/projects/{{ item.project_id }}">{{ item.project }}</a></td>
<td>
{% if item.accepted_by %}{{ item.accepted_by }}
{% else %}<span class="badge badge--warning">Not recorded</span>{% endif %}
</td>
<td class="u-ws-nowrap">{{ item.accepted_at | fmt_ago }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="alert alert--info u-mt-6"><div>No accepted threats yet. Record one with <code>secfoo accept create</code>.</div></div>
{% endif %}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,18 @@ <h4 class="card__title">Threat disposition</h4>
{% call info_tip("Accepted threats") %}
<p>Every threat a model marked <strong>Accepted</strong>, matched with the person who signed it off.</p>
<p>A threat with no owner shown has not been signed off by anyone yet. Record the owner with <code>secfoo accept create</code>.</p>
<p>This card shows the newest ones. The full list is on its own page.</p>
{% endcall %}
<h4 class="card__title">Accepted threats</h4>
<p class="card__body u-mb-3 u-color-text-muted">
Every threat marked Accepted, reconciled with who actually signed off — <code>secfoo accept create</code> is how "not recorded" turns into a real name.
The newest threats marked Accepted, reconciled with who signed off. <code>secfoo accept create</code> is how "not recorded" turns into a real name.
</p>
{% if tm_dash.accepted_threats %}
<div class="table-wrap widget-scroll" data-scroll-rows="10">
{% if tm_dash.accepted_preview %}
<div class="table-wrap">
<table class="table">
<thead><tr><th>Threat</th><th>Project</th><th>Accepted by</th></tr></thead>
<tbody>
{% for item in tm_dash.accepted_threats %}
{% for item in tm_dash.accepted_preview %}
<tr>
<td>{{ item.threat }}</td>
<td>{{ item.project }}</td>
Expand All @@ -175,6 +176,9 @@ <h4 class="card__title">Accepted threats</h4>
</tbody>
</table>
</div>
{% if tm_dash.accepted_threats | length > tm_dash.accepted_preview | length %}
<a class="ds-caption u-d-block u-mt-3" href="/activities/threat-modeling/accepted">View all {{ tm_dash.accepted_threats | length }} &rarr;</a>
{% endif %}
{% else %}
<p class="ds-body u-color-text-muted">No accepted threats yet.</p>
{% endif %}
Expand Down
19 changes: 17 additions & 2 deletions src/secfoo/web/threat_modeling_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@

SKILL_ID = "threat-modeling"

# The post-build and falsified-assumption cards show only the newest
# handful. The rest live on their own pages.
# The post-build, falsified-assumption, and accepted-threat cards show
# only the newest handful. The rest live on their own pages. The
# accepted-threat preview is shorter because each row is a full table
# row, and the whole list made that card too tall.
LIST_PREVIEW_LIMIT = 8
ACCEPTED_PREVIEW_LIMIT = 5

# A Gap-disposition threat is "past due" once its most recent model is
# older than this -- the same coarse, run-level proxy used for the
Expand Down Expand Up @@ -79,6 +82,7 @@ class ThreatModelingDashboard:
disposition: dict[str, int] = field(default_factory=dict)
disposition_total: int = 0
accepted_threats: list[dict] = field(default_factory=list)
accepted_preview: list[dict] = field(default_factory=list)
needs_rework: list[dict] = field(default_factory=list)
recurring_patterns: list[tuple[str, int]] = field(default_factory=list)
model_depth_mix: dict[str, int] = field(default_factory=dict)
Expand Down Expand Up @@ -180,6 +184,9 @@ def build(repo: RunRepository) -> ThreatModelingDashboard:
"project": project["project_display_name"],
"threat_ref": row["id"],
"threat": row["threat"],
# No per-threat acceptance time exists on the report.
# The model's own start is the closest "when".
"modeled_at": started,
}
)
elif disposition == "transferred":
Expand Down Expand Up @@ -227,10 +234,14 @@ def build(repo: RunRepository) -> ThreatModelingDashboard:
matched_keys.add(key)
merged_accepted.append(
{
"project_id": entry["project_id"],
"project": entry["project"],
"threat_ref": entry["threat_ref"],
"threat": entry["threat"],
"accepted_by": record.accepted_by if record else None,
# A recorded sign-off has a real time. Otherwise fall back
# to when the model marked the threat Accepted.
"accepted_at": record.created_at if record else entry.get("modeled_at"),
}
)
# A recorded acceptance whose threat no longer shows up as "Accepted" in
Expand All @@ -243,13 +254,17 @@ def build(repo: RunRepository) -> ThreatModelingDashboard:
continue
merged_accepted.append(
{
"project_id": record.project_id,
"project": record.project_display_name,
"threat_ref": record.threat_ref,
"threat": record.title,
"accepted_by": record.accepted_by,
"accepted_at": record.created_at,
}
)
merged_accepted.sort(key=lambda entry: entry.get("accepted_at") or "", reverse=True)
dash.accepted_threats = merged_accepted
dash.accepted_preview = merged_accepted[:ACCEPTED_PREVIEW_LIMIT]

dash.model_depth_mix = {
"full": depth_counter.get("Full", 0),
Expand Down
32 changes: 32 additions & 0 deletions tests/test_web/test_architecture_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,38 @@ def test_dashboard_shows_standard_from_findings_register(client, tmp_path):
assert "ISO 27001 A.10" in resp.text


def test_most_deviated_standards_shows_five_and_links_to_a_capped_list(client, tmp_path):
"""The card keeps the top five. The page behind the click keeps going,
but only through the top fifteen."""
rows = []
row_id = 1
for n in range(1, 19):
for _ in range(19 - n):
rows.append(
f"| A{row_id} | Finding | High | Secrets Management | STD {n:02d} | Confirmed |"
)
row_id += 1
rows = "\n".join(rows)
report = ARCHITECTURE_REPORT.replace(
"| A1 | Hardcoded key | High | Secrets Management | ISO 27001 A.10 | Confirmed |\n"
"| A2 | Missing rate limit | Medium | Authorization | N/A | Conditional |",
rows,
)
_seed(tmp_path, report_text=report)

page = client.get("/activities/security-architecture-review").text
card = page[page.index(">Most-deviated standards</h4>"):page.index(">Uncovered CCM domains</h4>")]
assert "STD 01" in card and "STD 05" in card
assert "STD 06" not in card
assert "View top 15" in card

full = client.get("/activities/security-architecture-review/standards")
assert full.status_code == 200
assert "STD 15" in full.text
assert "STD 16" not in full.text
assert "Showing the top 15 of 18" in full.text


def test_dashboard_shows_exceptions_past_expiry(client, tmp_path):
project_id, _, _ = _seed(tmp_path)
repo = RunRepository()
Expand Down
37 changes: 37 additions & 0 deletions tests/test_web/test_threat_modeling_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,43 @@ def test_post_build_card_keeps_eight_and_links_to_the_rest(client, tmp_path):
assert "Miss 1" in full.text and "Miss 10" in full.text


def test_accepted_threats_card_keeps_five_recent_and_links_to_the_rest(client, tmp_path):
"""The card shows the five newest acceptances. Older ones stay off the
dashboard and are reachable from View all."""
project_id, _, _ = _seed(tmp_path)
repo = RunRepository()
for day in range(1, 8):
repo.create_threat_acceptance(
project_id=project_id,
threat_ref=f"T{100 + day}",
title=f"Accepted threat {day}",
justification="j",
accepted_by="Jane Doe",
)
repo._conn.execute(
"UPDATE threat_acceptances SET created_at = ? WHERE threat_ref = ?",
(f"2026-01-{day:02d}T00:00:00+00:00", f"T{100 + day}"),
)
repo._conn.commit()
repo.close()

page = client.get("/activities/threat-modeling").text
card = page[page.index(">Accepted threats</h4>"):page.index('heading-with-info">Models needing rework')]
# The seeded report's T4 is newer than the January sign-offs, so it
# leads the preview. The oldest recorded titles stay off the card.
assert "Risk accepted for legacy endpoint" in card
assert "Accepted threat 7" in card
assert "Accepted threat 4" in card
assert "Accepted threat 3" not in card
assert "View all 8" in card

full = client.get("/activities/threat-modeling/accepted")
assert full.status_code == 200
assert "Accepted threat 1" in full.text
assert "Accepted threat 7" in full.text
assert "Risk accepted for legacy endpoint" in full.text


def test_dashboard_shows_accept_cli_hint(client, tmp_path):
_seed(tmp_path)
resp = client.get("/activities/threat-modeling")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_web/test_widget_info_tips.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_long_lists_scroll_after_ten_rows():
tm = (STATIC_JS.parents[2] / "templates" / "activities" / "threat_modeling_dashboard.html").read_text()
for marker in ("rework-list widget-scroll", "pattern-list widget-scroll", "miss-list widget-scroll", "assume-list widget-scroll"):
assert marker in tm
assert tm.count('data-scroll-rows="10"') >= 4
assert tm.count('data-scroll-rows="10"') >= 3
assert 'miss-list widget-scroll" data-scroll-rows="6"' in tm
assert 'assume-list widget-scroll" data-scroll-rows="6"' in tm

Expand Down
Loading