Commit ·
2c39b7a
1
Parent(s): 9f288a7
Build focused master-detail audit workspace
Browse files
app.py
CHANGED
|
@@ -15,12 +15,7 @@ def _summary_markdown(result: ScanResult) -> str:
|
|
| 15 |
f"**{name.title()}: {counts.get(name, 0)}**"
|
| 16 |
for name in ("critical", "high", "medium", "low", "info")
|
| 17 |
)
|
| 18 |
-
dependencies = ", ".join(f"`{html.escape(item)}`" for item in result.dependencies) or "None declared in Hub metadata"
|
| 19 |
-
notes = "\n".join(f"- {html.escape(note)}" for note in result.notes)
|
| 20 |
-
metadata = result.metadata_summary
|
| 21 |
artifacts = result.artifacts
|
| 22 |
-
exact = sum(1 for item in result.package_inventory if item.get("source_type") == "exact")
|
| 23 |
-
unresolved = sum(1 for item in result.package_inventory if item.get("source_type") != "exact")
|
| 24 |
priorities = []
|
| 25 |
for finding in result.finding_groups():
|
| 26 |
if finding["status"] != "unresolved" or finding["severity"] == "info":
|
|
@@ -36,25 +31,12 @@ def _summary_markdown(result: ScanResult) -> str:
|
|
| 36 |
|
| 37 |
- **Repository type:** {result.repo_type.title()}
|
| 38 |
- **Immutable revision:** `{result.revision}`
|
| 39 |
-
- **License / task / library:** `{html.escape(str(metadata.get('license') or 'undeclared'))}` / `{html.escape(str(metadata.get('pipeline_tag') or 'undeclared'))}` / `{html.escape(str(metadata.get('library') or 'undeclared'))}`
|
| 40 |
-
- **Architecture:** `{html.escape(str(metadata.get('architecture') or 'not identified'))}`
|
| 41 |
-
- **Text/config files inspected:** {len(result.inspected_files)}
|
| 42 |
-
- **Candidate files skipped:** {result.skipped_files}
|
| 43 |
- **Static coverage:** `{html.escape(str(artifacts.get('static_coverage', 'unknown')).upper())}` ({artifacts.get('inspected_text_files', len(result.inspected_files))}/{artifacts.get('eligible_text_files', len(result.inspected_files))} eligible files inspected)
|
| 44 |
-
- **Published files:** {artifacts.get('repository_file_count', 0)} totaling {artifacts.get('repository_size', '0 B')}
|
| 45 |
-
- **Weight artifacts:** {artifacts.get('weight_file_count', 0)} totaling {artifacts.get('weight_size', '0 B')} ({html.escape(str(artifacts.get('weight_formats') or 'none'))})
|
| 46 |
-
- **Safetensors index:** {artifacts.get('index_referenced_shards', 0)} referenced shards; {artifacts.get('index_declared_tensor_size', '0 B')} declared tensor data
|
| 47 |
-
- **Declared dependencies:** {dependencies}
|
| 48 |
-
- **Package inventory:** {len(result.package_inventory)} components ({exact} exact; {unresolved} unresolved/direct)
|
| 49 |
- **OSV correlation:** `{html.escape(str(result.osv_summary.get('status', 'not checked')).upper())}` — {result.osv_summary.get('queried_packages', 0)}/{result.osv_summary.get('exact_packages', 0)} exact packages queried; {len(result.vulnerabilities)} known matches
|
| 50 |
|
| 51 |
### Fix first
|
| 52 |
|
| 53 |
{fix_first}
|
| 54 |
-
|
| 55 |
-
### Important limitations
|
| 56 |
-
|
| 57 |
-
{notes}
|
| 58 |
"""
|
| 59 |
|
| 60 |
|
|
@@ -63,36 +45,63 @@ def _safe(value: object, fallback: str = "not stated") -> str:
|
|
| 63 |
return html.escape(text)
|
| 64 |
|
| 65 |
|
| 66 |
-
def
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
for item in result.checks:
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
f"{_safe(item.detail)}"
|
| 73 |
-
)
|
| 74 |
-
return
|
| 75 |
|
| 76 |
|
| 77 |
-
def
|
| 78 |
-
|
| 79 |
for item in result.dependency_details:
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
| 83 |
f"- **Depth:** {_safe(item.get('depth'))}\n"
|
| 84 |
f"- **License:** {_safe(item.get('license'), 'undeclared')}\n"
|
| 85 |
f"- **Status:** {_safe(item.get('status'), 'unknown')}\n"
|
| 86 |
f"- **Revision:** `{_safe(item.get('revision'))}`\n"
|
| 87 |
-
f"- **Gated:** {_safe(item.get('gated', False))}"
|
| 88 |
-
)
|
| 89 |
-
if not
|
| 90 |
-
|
| 91 |
-
return "
|
| 92 |
|
| 93 |
|
| 94 |
-
def
|
| 95 |
-
|
| 96 |
for finding in result.finding_groups():
|
| 97 |
occurrences = finding["occurrences"]
|
| 98 |
locations = []
|
|
@@ -106,45 +115,68 @@ def _finding_markdown(result: ScanResult) -> str:
|
|
| 106 |
evidence = occurrence["evidence"]
|
| 107 |
location_text = ", ".join(locations) + (" …" if len(occurrences) > 3 else "")
|
| 108 |
evidence_line = f"\n- **Evidence:** `{_safe(evidence)}`" if evidence else ""
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
| 111 |
f"- **Status:** {_safe(finding['status'].upper())}\n"
|
| 112 |
f"- **Occurrences:** {len(occurrences)}\n"
|
| 113 |
f"- **Locations:** {_safe(location_text)}"
|
| 114 |
f"{evidence_line}\n"
|
| 115 |
f"- **Confidence:** {_safe(finding['confidence'])}\n\n"
|
| 116 |
f"**Why it matters**\n\n{_safe(finding['detail'])}\n\n"
|
| 117 |
-
f"**Remediation**\n\n{_safe(finding['remediation'])}"
|
| 118 |
-
)
|
| 119 |
-
return "
|
| 120 |
|
| 121 |
|
| 122 |
-
def
|
| 123 |
-
|
| 124 |
for item in result.package_inventory:
|
| 125 |
manifests = ", ".join(sorted({occurrence.get("path", "") for occurrence in item.get("occurrences", [])}))
|
| 126 |
-
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
| 128 |
f"- **Source type:** {_safe(item.get('source_type'))}\n"
|
| 129 |
f"- **Constraint:** `{_safe(item.get('constraint'))}`\n"
|
| 130 |
f"- **PURL:** `{_safe(item.get('purl'))}`\n"
|
| 131 |
-
f"- **Manifest:** {_safe(manifests)}"
|
| 132 |
-
)
|
| 133 |
-
return "
|
| 134 |
|
| 135 |
|
| 136 |
-
def
|
| 137 |
-
|
| 138 |
for item in result.vulnerabilities:
|
| 139 |
-
|
| 140 |
-
|
|
|
|
|
|
|
| 141 |
f"{_safe(item.get('summary'))}\n\n"
|
| 142 |
f"- **Package:** {_safe(item.get('package'))} `{_safe(item.get('version'))}`\n"
|
| 143 |
f"- **Aliases:** {_safe(', '.join(item.get('aliases') or []))}\n"
|
| 144 |
f"- **Fixed versions:** {_safe(', '.join(item.get('fixed_versions') or []))}\n"
|
| 145 |
-
f"- **Advisory:** {_safe(item.get('url'))}"
|
| 146 |
-
)
|
| 147 |
-
return "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
|
| 150 |
def _write_sbom(result: ScanResult) -> str:
|
|
@@ -163,15 +195,30 @@ def run_scan(target: str):
|
|
| 163 |
raise gr.Error(str(exc)) from exc
|
| 164 |
except Exception as exc:
|
| 165 |
raise gr.Error(f"The public repository could not be scanned: {type(exc).__name__}") from exc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
return (
|
| 167 |
_summary_markdown(result),
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
result_json(result),
|
| 174 |
_write_sbom(result),
|
|
|
|
| 175 |
)
|
| 176 |
|
| 177 |
|
|
@@ -183,21 +230,6 @@ files at an immutable commit, then reports evidence-backed supply-chain, licensi
|
|
| 183 |
"""
|
| 184 |
|
| 185 |
APP_CSS = """
|
| 186 |
-
#results-scroll {
|
| 187 |
-
max-height: min(72vh, 900px);
|
| 188 |
-
min-height: 28rem;
|
| 189 |
-
overflow-y: auto !important;
|
| 190 |
-
overflow-x: hidden;
|
| 191 |
-
overscroll-behavior: contain;
|
| 192 |
-
scrollbar-gutter: stable;
|
| 193 |
-
padding-right: 0.5rem;
|
| 194 |
-
}
|
| 195 |
-
#results-scroll .tab-nav {
|
| 196 |
-
position: sticky;
|
| 197 |
-
top: 0;
|
| 198 |
-
z-index: 5;
|
| 199 |
-
background: var(--background-fill-primary);
|
| 200 |
-
}
|
| 201 |
.audit-cards,
|
| 202 |
.audit-cards p,
|
| 203 |
.audit-cards li,
|
|
@@ -206,10 +238,41 @@ APP_CSS = """
|
|
| 206 |
word-break: break-word;
|
| 207 |
white-space: normal;
|
| 208 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
"""
|
| 210 |
|
| 211 |
with gr.Blocks(title="ModelSentry", delete_cache=(600, 1800)) as demo:
|
| 212 |
gr.Markdown("# 🛡️ ModelSentry\n### Hugging Face supply-chain and provenance auditor")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
gr.Markdown(DESCRIPTION)
|
| 214 |
with gr.Row():
|
| 215 |
target = gr.Textbox(
|
|
@@ -226,50 +289,108 @@ with gr.Blocks(title="ModelSentry", delete_cache=(600, 1800)) as demo:
|
|
| 226 |
inputs=target,
|
| 227 |
label="Public examples",
|
| 228 |
)
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
)
|
| 250 |
-
|
| 251 |
-
gr.
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
with gr.
|
| 263 |
-
|
| 264 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
gr.Markdown(
|
| 266 |
"ModelSentry performs bounded static analysis of untrusted public content. Findings require human review; "
|
| 267 |
"absence of a finding is not proof of safety. Repository contents are not intentionally retained by this app; "
|
| 268 |
"randomized SBOM download files are eligible for automatic cleanup within 30 minutes."
|
| 269 |
)
|
| 270 |
-
outputs = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
scan.click(run_scan, inputs=target, outputs=outputs)
|
| 272 |
target.submit(run_scan, inputs=target, outputs=outputs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
|
| 274 |
if __name__ == "__main__":
|
| 275 |
demo.launch(theme=gr.themes.Soft(), css=APP_CSS)
|
|
|
|
| 15 |
f"**{name.title()}: {counts.get(name, 0)}**"
|
| 16 |
for name in ("critical", "high", "medium", "low", "info")
|
| 17 |
)
|
|
|
|
|
|
|
|
|
|
| 18 |
artifacts = result.artifacts
|
|
|
|
|
|
|
| 19 |
priorities = []
|
| 20 |
for finding in result.finding_groups():
|
| 21 |
if finding["status"] != "unresolved" or finding["severity"] == "info":
|
|
|
|
| 31 |
|
| 32 |
- **Repository type:** {result.repo_type.title()}
|
| 33 |
- **Immutable revision:** `{result.revision}`
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
- **Static coverage:** `{html.escape(str(artifacts.get('static_coverage', 'unknown')).upper())}` ({artifacts.get('inspected_text_files', len(result.inspected_files))}/{artifacts.get('eligible_text_files', len(result.inspected_files))} eligible files inspected)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
- **OSV correlation:** `{html.escape(str(result.osv_summary.get('status', 'not checked')).upper())}` — {result.osv_summary.get('queried_packages', 0)}/{result.osv_summary.get('exact_packages', 0)} exact packages queried; {len(result.vulnerabilities)} known matches
|
| 36 |
|
| 37 |
### Fix first
|
| 38 |
|
| 39 |
{fix_first}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
"""
|
| 41 |
|
| 42 |
|
|
|
|
| 45 |
return html.escape(text)
|
| 46 |
|
| 47 |
|
| 48 |
+
def _overview_markdown(result: ScanResult) -> str:
|
| 49 |
+
metadata = result.metadata_summary
|
| 50 |
+
artifacts = result.artifacts
|
| 51 |
+
dependencies = ", ".join(f"`{_safe(item)}`" for item in result.dependencies) or "None declared in Hub metadata"
|
| 52 |
+
notes = "\n".join(f"- {_safe(note)}" for note in result.notes) or "- No additional note was produced."
|
| 53 |
+
exact = sum(1 for item in result.package_inventory if item.get("source_type") == "exact")
|
| 54 |
+
unresolved = sum(1 for item in result.package_inventory if item.get("source_type") != "exact")
|
| 55 |
+
return f"""### Repository details
|
| 56 |
+
|
| 57 |
+
- **License / task / library:** `{_safe(metadata.get('license'), 'undeclared')}` / `{_safe(metadata.get('pipeline_tag'), 'undeclared')}` / `{_safe(metadata.get('library'), 'undeclared')}`
|
| 58 |
+
- **Architecture:** `{_safe(metadata.get('architecture'), 'not identified')}`
|
| 59 |
+
- **Text/config files inspected:** {len(result.inspected_files)}
|
| 60 |
+
- **Candidate files skipped:** {result.skipped_files}
|
| 61 |
+
- **Published files:** {artifacts.get('repository_file_count', 0)} totaling {artifacts.get('repository_size', '0 B')}
|
| 62 |
+
- **Weight artifacts:** {artifacts.get('weight_file_count', 0)} totaling {artifacts.get('weight_size', '0 B')} ({_safe(artifacts.get('weight_formats') or 'none')})
|
| 63 |
+
- **Safetensors index:** {artifacts.get('index_referenced_shards', 0)} referenced shards; {artifacts.get('index_declared_tensor_size', '0 B')} declared tensor data
|
| 64 |
+
- **Declared dependencies:** {dependencies}
|
| 65 |
+
- **Package inventory:** {len(result.package_inventory)} components ({exact} exact; {unresolved} unresolved/direct)
|
| 66 |
+
|
| 67 |
+
### Important limitations
|
| 68 |
+
|
| 69 |
+
{notes}
|
| 70 |
+
"""
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def _coverage_items(result: ScanResult) -> list[dict[str, str]]:
|
| 74 |
+
items = []
|
| 75 |
for item in result.checks:
|
| 76 |
+
status = item.status.upper().replace("_", " ")
|
| 77 |
+
items.append({
|
| 78 |
+
"label": f"{status} · {item.category}",
|
| 79 |
+
"detail": f"### {_safe(item.category)}\n\n**Status:** `{_safe(status)}`\n\n{_safe(item.detail)}",
|
| 80 |
+
})
|
| 81 |
+
return items or [{"label": "No coverage records", "detail": "No coverage record was produced."}]
|
| 82 |
|
| 83 |
|
| 84 |
+
def _dependency_items(result: ScanResult) -> list[dict[str, str]]:
|
| 85 |
+
items = []
|
| 86 |
for item in result.dependency_details:
|
| 87 |
+
relations = ", ".join(item.get("relation") or [])
|
| 88 |
+
items.append({
|
| 89 |
+
"label": f"{relations or 'declared'} · {item.get('repository', 'unknown')}",
|
| 90 |
+
"detail": f"### {_safe(item.get('repository'))}\n\n"
|
| 91 |
+
f"- **Relationship:** {_safe(relations)}\n"
|
| 92 |
f"- **Depth:** {_safe(item.get('depth'))}\n"
|
| 93 |
f"- **License:** {_safe(item.get('license'), 'undeclared')}\n"
|
| 94 |
f"- **Status:** {_safe(item.get('status'), 'unknown')}\n"
|
| 95 |
f"- **Revision:** `{_safe(item.get('revision'))}`\n"
|
| 96 |
+
f"- **Gated:** {_safe(item.get('gated', False))}",
|
| 97 |
+
})
|
| 98 |
+
if not items:
|
| 99 |
+
items = [{"label": f"declared · {item}", "detail": f"### {_safe(item)}\n\nDeclared dependency; details were not checked."} for item in result.dependencies]
|
| 100 |
+
return items or [{"label": "No upstream dependencies", "detail": "No upstream repository dependency was declared."}]
|
| 101 |
|
| 102 |
|
| 103 |
+
def _finding_items(result: ScanResult) -> list[dict[str, str]]:
|
| 104 |
+
items = []
|
| 105 |
for finding in result.finding_groups():
|
| 106 |
occurrences = finding["occurrences"]
|
| 107 |
locations = []
|
|
|
|
| 115 |
evidence = occurrence["evidence"]
|
| 116 |
location_text = ", ".join(locations) + (" …" if len(occurrences) > 3 else "")
|
| 117 |
evidence_line = f"\n- **Evidence:** `{_safe(evidence)}`" if evidence else ""
|
| 118 |
+
label = f"{finding['severity'].upper()} · {finding['rule_id']} · {finding['title']}"
|
| 119 |
+
items.append({
|
| 120 |
+
"label": label,
|
| 121 |
+
"detail": f"### {_safe(label)}\n\n"
|
| 122 |
f"- **Status:** {_safe(finding['status'].upper())}\n"
|
| 123 |
f"- **Occurrences:** {len(occurrences)}\n"
|
| 124 |
f"- **Locations:** {_safe(location_text)}"
|
| 125 |
f"{evidence_line}\n"
|
| 126 |
f"- **Confidence:** {_safe(finding['confidence'])}\n\n"
|
| 127 |
f"**Why it matters**\n\n{_safe(finding['detail'])}\n\n"
|
| 128 |
+
f"**Remediation**\n\n{_safe(finding['remediation'])}",
|
| 129 |
+
})
|
| 130 |
+
return items or [{"label": "No findings", "detail": "No evidence-linked finding was produced."}]
|
| 131 |
|
| 132 |
|
| 133 |
+
def _package_items(result: ScanResult) -> list[dict[str, str]]:
|
| 134 |
+
items = []
|
| 135 |
for item in result.package_inventory:
|
| 136 |
manifests = ", ".join(sorted({occurrence.get("path", "") for occurrence in item.get("occurrences", [])}))
|
| 137 |
+
version = item.get("version") or "unresolved"
|
| 138 |
+
label = f"{item.get('name', 'unknown')} · {version}"
|
| 139 |
+
items.append({
|
| 140 |
+
"label": label,
|
| 141 |
+
"detail": f"### {_safe(label)}\n\n"
|
| 142 |
f"- **Source type:** {_safe(item.get('source_type'))}\n"
|
| 143 |
f"- **Constraint:** `{_safe(item.get('constraint'))}`\n"
|
| 144 |
f"- **PURL:** `{_safe(item.get('purl'))}`\n"
|
| 145 |
+
f"- **Manifest:** {_safe(manifests)}",
|
| 146 |
+
})
|
| 147 |
+
return items or [{"label": "No packages", "detail": "No supported package declaration was found."}]
|
| 148 |
|
| 149 |
|
| 150 |
+
def _vulnerability_items(result: ScanResult) -> list[dict[str, str]]:
|
| 151 |
+
items = []
|
| 152 |
for item in result.vulnerabilities:
|
| 153 |
+
label = f"{item.get('severity', '').upper()} · {item.get('id', 'unknown')} · {item.get('package', 'unknown')}"
|
| 154 |
+
items.append({
|
| 155 |
+
"label": label,
|
| 156 |
+
"detail": f"### {_safe(label)}\n\n"
|
| 157 |
f"{_safe(item.get('summary'))}\n\n"
|
| 158 |
f"- **Package:** {_safe(item.get('package'))} `{_safe(item.get('version'))}`\n"
|
| 159 |
f"- **Aliases:** {_safe(', '.join(item.get('aliases') or []))}\n"
|
| 160 |
f"- **Fixed versions:** {_safe(', '.join(item.get('fixed_versions') or []))}\n"
|
| 161 |
+
f"- **Advisory:** {_safe(item.get('url'))}",
|
| 162 |
+
})
|
| 163 |
+
return items or [{"label": "No known matches", "detail": "No known OSV match was returned for the exactly pinned packages checked."}]
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
def _selector_update(items: list[dict[str, str]], label: str):
|
| 167 |
+
choices = [(item["label"], str(index)) for index, item in enumerate(items)]
|
| 168 |
+
return gr.Dropdown(choices=choices, value="0", label=f"{label} ({len(items)})")
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
def _select_detail(selection: str | None, state: dict[str, list[str]] | None, section: str) -> str:
|
| 172 |
+
details = (state or {}).get(section) or []
|
| 173 |
+
try:
|
| 174 |
+
index = int(selection or 0)
|
| 175 |
+
except (TypeError, ValueError):
|
| 176 |
+
index = 0
|
| 177 |
+
if not details:
|
| 178 |
+
return "Run a scan to populate this section."
|
| 179 |
+
return details[index] if 0 <= index < len(details) else details[0]
|
| 180 |
|
| 181 |
|
| 182 |
def _write_sbom(result: ScanResult) -> str:
|
|
|
|
| 195 |
raise gr.Error(str(exc)) from exc
|
| 196 |
except Exception as exc:
|
| 197 |
raise gr.Error(f"The public repository could not be scanned: {type(exc).__name__}") from exc
|
| 198 |
+
sections = {
|
| 199 |
+
"coverage": _coverage_items(result),
|
| 200 |
+
"dependencies": _dependency_items(result),
|
| 201 |
+
"packages": _package_items(result),
|
| 202 |
+
"vulnerabilities": _vulnerability_items(result),
|
| 203 |
+
"findings": _finding_items(result),
|
| 204 |
+
}
|
| 205 |
+
view_state = {name: [item["detail"] for item in items] for name, items in sections.items()}
|
| 206 |
return (
|
| 207 |
_summary_markdown(result),
|
| 208 |
+
_overview_markdown(result),
|
| 209 |
+
_selector_update(sections["coverage"], "Coverage area"),
|
| 210 |
+
sections["coverage"][0]["detail"],
|
| 211 |
+
_selector_update(sections["dependencies"], "Upstream repository"),
|
| 212 |
+
sections["dependencies"][0]["detail"],
|
| 213 |
+
_selector_update(sections["packages"], "Package"),
|
| 214 |
+
sections["packages"][0]["detail"],
|
| 215 |
+
_selector_update(sections["vulnerabilities"], "Known vulnerability"),
|
| 216 |
+
sections["vulnerabilities"][0]["detail"],
|
| 217 |
+
_selector_update(sections["findings"], "Finding"),
|
| 218 |
+
sections["findings"][0]["detail"],
|
| 219 |
result_json(result),
|
| 220 |
_write_sbom(result),
|
| 221 |
+
view_state,
|
| 222 |
)
|
| 223 |
|
| 224 |
|
|
|
|
| 230 |
"""
|
| 231 |
|
| 232 |
APP_CSS = """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
.audit-cards,
|
| 234 |
.audit-cards p,
|
| 235 |
.audit-cards li,
|
|
|
|
| 238 |
word-break: break-word;
|
| 239 |
white-space: normal;
|
| 240 |
}
|
| 241 |
+
.scan-summary {
|
| 242 |
+
border: 1px solid var(--border-color-primary);
|
| 243 |
+
border-left: 0.35rem solid var(--primary-500);
|
| 244 |
+
border-radius: var(--radius-lg);
|
| 245 |
+
padding: 0.25rem 1rem;
|
| 246 |
+
background: var(--background-fill-secondary);
|
| 247 |
+
}
|
| 248 |
+
.detail-card {
|
| 249 |
+
border: 1px solid var(--border-color-primary);
|
| 250 |
+
border-radius: var(--radius-lg);
|
| 251 |
+
padding: 0.75rem 1rem;
|
| 252 |
+
min-height: 14rem;
|
| 253 |
+
background: var(--background-fill-primary);
|
| 254 |
+
}
|
| 255 |
+
.fullscreen-link {
|
| 256 |
+
display: inline-flex;
|
| 257 |
+
align-items: center;
|
| 258 |
+
gap: 0.35rem;
|
| 259 |
+
padding: 0.55rem 0.85rem;
|
| 260 |
+
border: 1px solid var(--border-color-primary);
|
| 261 |
+
border-radius: var(--radius-lg);
|
| 262 |
+
font-weight: 600;
|
| 263 |
+
text-decoration: none !important;
|
| 264 |
+
}
|
| 265 |
+
.fullscreen-link:hover {
|
| 266 |
+
border-color: var(--primary-500);
|
| 267 |
+
}
|
| 268 |
"""
|
| 269 |
|
| 270 |
with gr.Blocks(title="ModelSentry", delete_cache=(600, 1800)) as demo:
|
| 271 |
gr.Markdown("# 🛡️ ModelSentry\n### Hugging Face supply-chain and provenance auditor")
|
| 272 |
+
gr.HTML(
|
| 273 |
+
'<a class="fullscreen-link" href="https://seedofevil-modelsentry-hf-auditor.hf.space/" '
|
| 274 |
+
'target="_blank" rel="noopener noreferrer">↗ Open full-screen workspace</a>'
|
| 275 |
+
)
|
| 276 |
gr.Markdown(DESCRIPTION)
|
| 277 |
with gr.Row():
|
| 278 |
target = gr.Textbox(
|
|
|
|
| 289 |
inputs=target,
|
| 290 |
label="Public examples",
|
| 291 |
)
|
| 292 |
+
summary = gr.Markdown(
|
| 293 |
+
"Run a scan to see the prioritized result summary.",
|
| 294 |
+
elem_classes=["scan-summary", "audit-cards"],
|
| 295 |
+
)
|
| 296 |
+
view_state = gr.State({})
|
| 297 |
+
with gr.Tabs():
|
| 298 |
+
with gr.Tab("Overview"):
|
| 299 |
+
overview = gr.Markdown(
|
| 300 |
+
"Repository details will appear after a scan.",
|
| 301 |
+
elem_classes=["audit-cards"],
|
| 302 |
+
)
|
| 303 |
+
gr.Markdown("## Coverage inspector — PASSED does not mean certified safe")
|
| 304 |
+
with gr.Row(equal_height=False):
|
| 305 |
+
with gr.Column(scale=1, min_width=280):
|
| 306 |
+
coverage_selector = gr.Dropdown(label="Coverage area", choices=[], interactive=True)
|
| 307 |
+
with gr.Column(scale=2, min_width=360):
|
| 308 |
+
coverage_detail = gr.Markdown("Select a coverage area.", elem_classes=["detail-card", "audit-cards"])
|
| 309 |
+
with gr.Tab("Findings"):
|
| 310 |
+
gr.Markdown("## Findings inspector")
|
| 311 |
+
with gr.Row(equal_height=False):
|
| 312 |
+
with gr.Column(scale=1, min_width=280):
|
| 313 |
+
finding_selector = gr.Dropdown(label="Finding", choices=[], interactive=True)
|
| 314 |
+
with gr.Column(scale=2, min_width=360):
|
| 315 |
+
finding_detail = gr.Markdown("Select a finding.", elem_classes=["detail-card", "audit-cards"])
|
| 316 |
+
with gr.Tab("Provenance"):
|
| 317 |
+
gr.Markdown("## Provenance inspector")
|
| 318 |
+
with gr.Row(equal_height=False):
|
| 319 |
+
with gr.Column(scale=1, min_width=280):
|
| 320 |
+
dependency_selector = gr.Dropdown(label="Upstream repository", choices=[], interactive=True)
|
| 321 |
+
with gr.Column(scale=2, min_width=360):
|
| 322 |
+
dependency_detail = gr.Markdown("Select an upstream repository.", elem_classes=["detail-card", "audit-cards"])
|
| 323 |
+
with gr.Tab("Packages"):
|
| 324 |
+
gr.Markdown("## Package inspector")
|
| 325 |
+
with gr.Row(equal_height=False):
|
| 326 |
+
with gr.Column(scale=1, min_width=280):
|
| 327 |
+
package_selector = gr.Dropdown(label="Package", choices=[], interactive=True)
|
| 328 |
+
with gr.Column(scale=2, min_width=360):
|
| 329 |
+
package_detail = gr.Markdown("Select a package.", elem_classes=["detail-card", "audit-cards"])
|
| 330 |
+
with gr.Tab("Vulnerabilities"):
|
| 331 |
+
gr.Markdown("## Vulnerability inspector")
|
| 332 |
+
with gr.Row(equal_height=False):
|
| 333 |
+
with gr.Column(scale=1, min_width=280):
|
| 334 |
+
vulnerability_selector = gr.Dropdown(label="Known vulnerability", choices=[], interactive=True)
|
| 335 |
+
with gr.Column(scale=2, min_width=360):
|
| 336 |
+
vulnerability_detail = gr.Markdown("Select a vulnerability.", elem_classes=["detail-card", "audit-cards"])
|
| 337 |
+
with gr.Tab("JSON / SBOM"):
|
| 338 |
+
report = gr.Code(language="json", label="modelsentry.scan.v4 JSON")
|
| 339 |
+
sbom = gr.File(label="CycloneDX 1.6 SBOM", interactive=False)
|
| 340 |
gr.Markdown(
|
| 341 |
"ModelSentry performs bounded static analysis of untrusted public content. Findings require human review; "
|
| 342 |
"absence of a finding is not proof of safety. Repository contents are not intentionally retained by this app; "
|
| 343 |
"randomized SBOM download files are eligible for automatic cleanup within 30 minutes."
|
| 344 |
)
|
| 345 |
+
outputs = [
|
| 346 |
+
summary,
|
| 347 |
+
overview,
|
| 348 |
+
coverage_selector,
|
| 349 |
+
coverage_detail,
|
| 350 |
+
dependency_selector,
|
| 351 |
+
dependency_detail,
|
| 352 |
+
package_selector,
|
| 353 |
+
package_detail,
|
| 354 |
+
vulnerability_selector,
|
| 355 |
+
vulnerability_detail,
|
| 356 |
+
finding_selector,
|
| 357 |
+
finding_detail,
|
| 358 |
+
report,
|
| 359 |
+
sbom,
|
| 360 |
+
view_state,
|
| 361 |
+
]
|
| 362 |
scan.click(run_scan, inputs=target, outputs=outputs)
|
| 363 |
target.submit(run_scan, inputs=target, outputs=outputs)
|
| 364 |
+
coverage_selector.change(
|
| 365 |
+
lambda selection, state: _select_detail(selection, state, "coverage"),
|
| 366 |
+
inputs=[coverage_selector, view_state],
|
| 367 |
+
outputs=coverage_detail,
|
| 368 |
+
api_name=False,
|
| 369 |
+
)
|
| 370 |
+
dependency_selector.change(
|
| 371 |
+
lambda selection, state: _select_detail(selection, state, "dependencies"),
|
| 372 |
+
inputs=[dependency_selector, view_state],
|
| 373 |
+
outputs=dependency_detail,
|
| 374 |
+
api_name=False,
|
| 375 |
+
)
|
| 376 |
+
package_selector.change(
|
| 377 |
+
lambda selection, state: _select_detail(selection, state, "packages"),
|
| 378 |
+
inputs=[package_selector, view_state],
|
| 379 |
+
outputs=package_detail,
|
| 380 |
+
api_name=False,
|
| 381 |
+
)
|
| 382 |
+
vulnerability_selector.change(
|
| 383 |
+
lambda selection, state: _select_detail(selection, state, "vulnerabilities"),
|
| 384 |
+
inputs=[vulnerability_selector, view_state],
|
| 385 |
+
outputs=vulnerability_detail,
|
| 386 |
+
api_name=False,
|
| 387 |
+
)
|
| 388 |
+
finding_selector.change(
|
| 389 |
+
lambda selection, state: _select_detail(selection, state, "findings"),
|
| 390 |
+
inputs=[finding_selector, view_state],
|
| 391 |
+
outputs=finding_detail,
|
| 392 |
+
api_name=False,
|
| 393 |
+
)
|
| 394 |
|
| 395 |
if __name__ == "__main__":
|
| 396 |
demo.launch(theme=gr.themes.Soft(), css=APP_CSS)
|