8000 feat: RBAC audit tool and SKOS skeleton by dominicusin · Pull Request #12 · dominicusin/portfolio · GitHub
[go: up one dir, main page]

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
47 changes: 47 additions & 0 deletions artifacts/SUR-004-rbac-audit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"total": 10,
"unguarded_count": 8,
"note": "Heuristic static audit of Surypus source. Routes reported as unguarded are candidates for manual review, not confirmed vulnerabilities; login/health and publicPaths are expected false positives.",
"unguarded": [
{
"route": "/api/v1/login",
"file": "Middleware.hs",
"line": 41
},
{
"route": "/api/v1/",
"file": "Authorization.hs",
"line": 103
},
{
"route": "/api/v1/health",
"file": "Server.hs",
"line": 213
},
{
"route": "/api/v1/health/db",
"file": "Server.hs",
"line": 215
},
{
"route": "/api/v1/reports/download/",
"file": "Server.hs",
"line": 222
},
{
"route": "/api/v1/reports/download/",
"file": "Server.hs",
"line": 224
},
{
"route": "/api/v1/metrics",
"file": "Server.hs",
"line": 230
},
{
"route": "/api/v1/reports/download/",
"file": "Server.hs",
"line": 679
}
]
}
20 changes: 20 additions & 0 deletions artifacts/neo-006-skos-skeleton.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix ex: <https://new.allunity.ru/vocab/> .

ex:MaterialType a skos:ConceptScheme ;
skos:prefLabel "NeoAllUnity material types"@en .

ex:primary_source a skos:Concept ; skos:inScheme ex:MaterialType ;
skos:prefLabel "Primary source"@en ; skos:definition "Immutable source material"@en .
ex:author_text a skos:Concept ; skos:inScheme ex:MaterialType ;
skos:prefLabel "Author text"@en .
ex:translation a skos:Concept ; skos:inScheme ex:MaterialType ;
skos:prefLabel "Translation"@en ; skos:broader ex:author_text .
ex:commentary a skos:Concept ; skos:inScheme ex:MaterialType ;
skos:prefLabel "Commentary"@en ; skos:broader ex:author_text .
ex:media a skos:Concept ; skos:inScheme ex:MaterialType ;
skos:prefLabel "Media"@en .

ex:relatedTo a skos:Concept ; skos:inScheme ex:MaterialType ;
skos:prefLabel "related to"@en ;
skos:definition "Links source, translation and commentary records"@en .
Binary file modified automation/__pycache__/polyglot_cm.cpython-311.pyc
Binary file not shown.
Binary file not shown.
43 changes: 43 additions & 0 deletions automation/rbac_audit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3
"""SUR-004 advisory audit: find API routes with no permission check nearby.

This is a static heuristic, not a proof of safety. It produces evidence for a
manual review and fails only when a route has neither a permission call nor an
explicit public-path annotation within the lookahead window.
"""
import json
import re
import sys
from pathlib import Path

ROUTE = re.compile(r'"(/api/[^"]+)"')
GUARD = re.compile(r'(requirePermission|checkPermission|authorize|publicPaths|publicPath)', re.I)


def audit_file(path: Path, lookahead: int = 20):
lines = path.read_text(encoding="utf-8", errors="replace").splitlines()
findings = []
for i, line in enumerate(lines):
for route in ROUTE.findall(line):
window = "\n".join(lines[i + 1:i + 1 + lookahead])
guarded = bool(GUARD.search(line) or GUARD.search(window))
findings.append({"route": route, "file": str(path), "line": i + 1,
"guarded": guarded})
return findings


def main():
root = Path(sys.argv[1]) if len(sys.argv) > 1 else Path(".")
files = list(root.rglob("*.hs"))
findings = []
for f in files:
findings.extend(audit_file(f))
unguarded = [f for f in findings if not f["guarded"]]
out = {"routes": findings, "unguarded": unguarded,
"total": len(findings), "unguarded_count": len(unguarded)}
print(json.dumps(out, indent=2, ensure_ascii=False))
return 0


if __name__ == "__main__":
raise SystemExit(main())
Binary file not shown.
33 changes: 33 additions & 0 deletions tests/test_rbac_audit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""SUR-004 audit tool tests."""
import tempfile
import unittest
from pathlib import Path

from automation.rbac_audit import audit_file


class TestRbacAudit(unittest.TestCase):
def test_route_with_permission_is_guarded(self):
with tempfile.TemporaryDirectory() as d:
f = Path(d) / "Api.hs"
f.write_text('handle = get "/api/v1/accounts" $ do\n requirePermission "accounts.read"\n pure ()\n')
out = audit_file(f)
self.assertEqual(len(out), 1)
self.assertTrue(out[0]["guarded"])

def test_route_without_permission_is_reported(self):
with tempfile.TemporaryDirectory() as d:
f = Path(d) / "Api.hs"
f.write_text('handle = get "/api/v1/accounts" $ do\n pure []\n')
out = audit_file(f)
self.assertFalse(out[0]["guarded"])

def test_public_annotation_is_accepted(self):
with tempfile.TemporaryDirectory() as d:
f = Path(d) / "Api.hs"
f.write_text('publicPaths = ["/api/v1/login"]\nget "/api/v1/login" $ pure ()\n')
self.assertTrue(audit_file(f)[0]["guarded"])


if __name__ == "__main__":
unittest.main()
Loading
0