-
Notifications
You must be signed in to change notification settings - Fork 0
Add public Cloud Run repository audit service #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| FROM python:3.11-slim | ||
| RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/* | ||
| WORKDIR /app | ||
| COPY . . | ||
| RUN pip install --no-cache-dir . | ||
| CMD ["python","service.py"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <meta name="viewport" content="width=device-width,initial-scale=1"> | ||
| <title>pubskill audit</title> | ||
| <style> | ||
| body{font-family:sans-serif;max-width:800px;margin:auto;padding:24px} | ||
| input{width:100%;padding:12px;box-sizing:border-box} | ||
| button{margin-top:10px;padding:12px 18px} | ||
| .finding{border:1px solid #ccc;border-radius:8px;padding:12px;margin:12px 0} | ||
| .meta{font-size:.9em;opacity:.7} | ||
| pre{white-space:pre-wrap} | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <h1>Repository Audit</h1> | ||
|
|
||
| <input id="repo" placeholder="https://github.com/owner/repo.git"> | ||
| <button onclick="runAudit()">Audit</button> | ||
|
|
||
| <div id="out"></div> | ||
|
|
||
| <script> | ||
| async function runAudit() { | ||
| const out = document.getElementById("out"); | ||
| out.innerHTML = "<p>Running audit...</p>"; | ||
|
|
||
| const response = await fetch("/audit", { | ||
| method: "POST", | ||
| headers: {"Content-Type": "application/json"}, | ||
| body: JSON.stringify({ | ||
| repo_url: document.getElementById("repo").value | ||
| }) | ||
| }); | ||
|
|
||
| const r = await response.json(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
|
|
||
| if (!response.ok) { | ||
| out.innerHTML = `<pre>${r.error || "Audit failed"}</pre>`; | ||
| return; | ||
| } | ||
|
|
||
| let html = ` | ||
| <h2>${r.target?.remote || "Repository"}</h2> | ||
| <p class="meta">Commit: ${r.target?.commit || "unknown"}</p> | ||
| <h3>${r.findings.length} findings</h3> | ||
| `; | ||
|
|
||
| for (const f of r.findings) { | ||
| html += ` | ||
| <div class="finding"> | ||
| <strong>${f.id} — ${f.surface}</strong> | ||
| <p>${f.claim}</p> | ||
| <div class="meta"> | ||
| Evidence: ${f.evidence}<br> | ||
|
Comment on lines
+54
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When auditing an attacker-controlled repository, fields such as Useful? React with 👍 / 👎. |
||
| Class: ${f.class} | ||
| </div> | ||
| </div> | ||
| `; | ||
| } | ||
|
|
||
| if (r.hmmm?.length) { | ||
| html += `<h3>hmmm</h3><ul>` + | ||
| r.hmmm.map(x => `<li>${x}</li>`).join("") + | ||
| `</ul>`; | ||
| } | ||
|
|
||
| out.innerHTML = html; | ||
| } | ||
| </script> | ||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import json | ||
| import os | ||
| import re | ||
| import subprocess | ||
| import tempfile | ||
| from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer | ||
| from pathlib import Path | ||
|
|
||
| from pubskill_lib.audit import audit_path | ||
|
|
||
| REPO = re.compile(r"^https://github\.com/[^/]+/[^/]+(?:\.git)?$") | ||
|
|
||
|
|
||
| class Handler(BaseHTTPRequestHandler): | ||
| def reply(self, status, body): | ||
| data = json.dumps(body).encode() | ||
| self.send_response(status) | ||
| self.send_header("Content-Type", "application/json") | ||
| self.send_header("Content-Length", str(len(data))) | ||
| self.end_headers() | ||
| self.wfile.write(data) | ||
|
|
||
| def do_GET(self): | ||
| data = Path("index.html").read_bytes() | ||
| self.send_response(200) | ||
| self.send_header("Content-Type", "text/html; charset=utf-8") | ||
| self.send_header("Content-Length", str(len(data))) | ||
| self.end_headers() | ||
| self.wfile.write(data) | ||
|
|
||
| def do_POST(self): | ||
| if self.path != "/audit": | ||
| return self.reply(404, {"error": "not found"}) | ||
|
|
||
| try: | ||
| length = int(self.headers.get("Content-Length", 0)) | ||
| body = json.loads(self.rfile.read(min(length, 8192))) | ||
| repo_url = body["repo_url"] | ||
|
|
||
| if not REPO.fullmatch(repo_url): | ||
| return self.reply(400, {"error": "public github.com repository required"}) | ||
|
|
||
| with tempfile.TemporaryDirectory() as tmp: | ||
| target = os.path.join(tmp, "repo") | ||
| subprocess.run( | ||
| ["git", "clone", "--depth=1", repo_url, target], | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
On this unauthenticated public endpoint, every request can start a concurrent clone into instance-local storage without a byte, disk, or concurrency limit. Useful? React with 👍 / 👎. |
||
| check=True, | ||
| timeout=120, | ||
| ) | ||
| result = audit_path(target) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a public repository commits Useful? React with 👍 / 👎. |
||
|
|
||
| self.reply(200, result) | ||
|
|
||
| except Exception as exc: | ||
| self.reply(500, {"error": str(exc)}) | ||
|
Comment on lines
+54
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a POST contains malformed JSON, omits Useful? React with 👍 / 👎. |
||
|
|
||
|
|
||
| ThreadingHTTPServer( | ||
| ("0.0.0.0", int(os.environ.get("PORT", "8080"))), | ||
| Handler, | ||
| ).serve_forever() | ||
|
Comment on lines
+58
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This starts a network-facing remote-repository service even though the required matching AGENTS.md reference: AGENTS.md:L3-L5 Useful? React with 👍 / 👎. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a developer builds this image from a checkout containing the repository's ignored
.envcredential file,COPY . .includes that file because.gitignoredoes not filter Docker build contexts and no.dockerignoreexists. The credentials then remain in the final image and its layers, exposing them to deployments and anyone with image access; add a.dockerignorethat excludes.env*,.git, and other local artifacts while explicitly retaining only safe examples if needed.Useful? React with 👍 / 👎.