"""Gradio UI and MCP surface for Whitehack Flashlight.""" import gradio as gr from flashlight import prepare_runtime, scan_code # Fail the Space build/start instead of presenting a scanner whose exact # artifact cannot be verified and unpacked. prepare_runtime() DESCRIPTION = """ Paste a small JavaScript/TypeScript, Python, or Solidity excerpt. Whitehack returns **review prompts**, not vulnerability verdicts, and an empty result is not proof of safety. This public Space processes text on Hugging Face infrastructure. The app does not intentionally persist or return source, but hosting-platform retention is unknown. **Do not submit secrets, private repositories, or proprietary code.** """ ARTICLE = """ ### Deliberately small boundary - One text value and one language enum; no dedicated file, archive, path, repository, URL, wallet, or credential capability. Strings containing these remain inert text and are never opened, fetched, authenticated, signed, or broadcast. - The submitted text is inspected as text and is never executed. - Output omits source, filenames, snippets, raw scanner messages, hashes, timestamps, user identifiers, and raw errors. - Hard limits: 65,536 UTF-8 bytes, 2,000 lines, 500 findings, and a 3-second scanner timeout. - JavaScript means the current shared JS/TS/JSX rule pack. This is not a general-purpose analyzer for every language or vulnerability class. The MCP endpoint is `/gradio_api/mcp/`. It exposes the same `scan_code` function as this page, with a concurrency limit of one. """ API_DESCRIPTION = """ Return bounded Whitehack review prompts for caller-provided source text. Heuristic only: findings are not vulnerability verdicts and an empty result is not proof of safety. The tool has no dedicated path, file, archive, repository, URL, wallet, or credential capability; such strings remain inert text and are never opened, fetched, authenticated, signed, broadcast, or executed. It cannot reliably recognize every secret. Source and snippets are omitted from output. This runs on Hugging Face infrastructure; platform retention is unknown, so never submit secrets, private, or proprietary code. """.strip() demo = gr.Interface( fn=scan_code, inputs=[ gr.Code( label="Source text", language="javascript", lines=18, value="const value = await fetch(url)\nreturn value.json()\n", ), gr.Dropdown( choices=[ ("JavaScript / TypeScript", "javascript"), ("Python", "python"), ("Solidity", "solidity"), ], value="javascript", label="Language rule pack", ), ], outputs=gr.Code( label="Closed Whitehack JSON", language="json", lines=22, ), title="Whitehack Flashlight 🔦", description=DESCRIPTION, article=ARTICLE, api_name="scan_code", api_description=API_DESCRIPTION, api_visibility="public", analytics_enabled=False, flagging_mode="never", concurrency_limit=1, submit_btn="Point the flashlight", clear_btn="Clear locally", ) demo.queue(max_size=16, default_concurrency_limit=1) if __name__ == "__main__": demo.launch(mcp_server=True, show_error=False)