Download server.py from emgena/nextjs15_react19_server_secret_leak_guard_teaser: direct link, hf CLI and curl.
- Browser
- Download file 22.2 kB
-
https://huggingface.co/datasets/emgena/nextjs15_react19_server_secret_leak_guard_teaser/resolve/main/server.py
- Command line
-
hf download hf://datasets/emgena/nextjs15_react19_server_secret_leak_guard_teaser/server.py
-
curl -L -o server.py https://huggingface.co/datasets/emgena/nextjs15_react19_server_secret_leak_guard_teaser/resolve/main/server.py
22.2 kB
| #!/usr/bin/env python3 | |
| """ | |
| Emgena Enterprise Sentinel MCP Server - FAANG v2.5 Gold Standard | |
| Package: nextjs15_react19_server_secret_leak_guard | |
| Title: Next.js 15 & React 19 Server-Action Secret Leak & Waterfall Hydration Guard MCP | |
| Domain: Next.js 15 Server Actions, React 19 Hydration Deadlocks & Server-Client Boundary Security | |
| """ | |
| import sys, os, json, ast, time | |
| from typing import Dict, Any, List | |
| KB_INCIDENTS = [ | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_001", | |
| "title": "AST scans Server Actions for leakage of private environment variables into client-accessible closures (Variant #1)", | |
| "tool_scope": "detect_server_action_secret_leak", | |
| "root_cause": "System attempted operation without invariant static validation through detect_server_action_secret_leak." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_002", | |
| "title": "AST scans Server Actions for leakage of private environment variables into client-accessible closures (Variant #2)", | |
| "tool_scope": "detect_server_action_secret_leak", | |
| "root_cause": "System attempted operation without invariant static validation through detect_server_action_secret_leak." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_003", | |
| "title": "AST scans Server Actions for leakage of private environment variables into client-accessible closures (Variant #3)", | |
| "tool_scope": "detect_server_action_secret_leak", | |
| "root_cause": "System attempted operation without invariant static validation through detect_server_action_secret_leak." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_004", | |
| "title": "AST scans Server Actions for leakage of private environment variables into client-accessible closures (Variant #4)", | |
| "tool_scope": "detect_server_action_secret_leak", | |
| "root_cause": "System attempted operation without invariant static validation through detect_server_action_secret_leak." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_005", | |
| "title": "Detects accidental imports of server-only modules (db, fs, secrets) into 'use client' component trees (Variant #1)", | |
| "tool_scope": "enforce_client_server_boundary_isolation", | |
| "root_cause": "System attempted operation without invariant static validation through enforce_client_server_boundary_isolation." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_006", | |
| "title": "Detects accidental imports of server-only modules (db, fs, secrets) into 'use client' component trees (Variant #2)", | |
| "tool_scope": "enforce_client_server_boundary_isolation", | |
| "root_cause": "System attempted operation without invariant static validation through enforce_client_server_boundary_isolation." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_007", | |
| "title": "Detects accidental imports of server-only modules (db, fs, secrets) into 'use client' component trees (Variant #3)", | |
| "tool_scope": "enforce_client_server_boundary_isolation", | |
| "root_cause": "System attempted operation without invariant static validation through enforce_client_server_boundary_isolation." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_008", | |
| "title": "Detects accidental imports of server-only modules (db, fs, secrets) into 'use client' component trees (Variant #4)", | |
| "tool_scope": "enforce_client_server_boundary_isolation", | |
| "root_cause": "System attempted operation without invariant static validation through enforce_client_server_boundary_isolation." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_009", | |
| "title": "Identifies unparallelized async data fetching in nested Server Components causing severe LCP degradation (Variant #1)", | |
| "tool_scope": "intercept_async_hydration_waterfall", | |
| "root_cause": "System attempted operation without invariant static validation through intercept_async_hydration_waterfall." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_010", | |
| "title": "Identifies unparallelized async data fetching in nested Server Components causing severe LCP degradation (Variant #2)", | |
| "tool_scope": "intercept_async_hydration_waterfall", | |
| "root_cause": "System attempted operation without invariant static validation through intercept_async_hydration_waterfall." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_011", | |
| "title": "Identifies unparallelized async data fetching in nested Server Components causing severe LCP degradation (Variant #3)", | |
| "tool_scope": "intercept_async_hydration_waterfall", | |
| "root_cause": "System attempted operation without invariant static validation through intercept_async_hydration_waterfall." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_012", | |
| "title": "Identifies unparallelized async data fetching in nested Server Components causing severe LCP degradation (Variant #4)", | |
| "tool_scope": "intercept_async_hydration_waterfall", | |
| "root_cause": "System attempted operation without invariant static validation through intercept_async_hydration_waterfall." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_013", | |
| "title": "Verifies that Server Actions enforce strict Host and Origin header checks against cross-site request forgery (Variant #1)", | |
| "tool_scope": "audit_server_action_csrf_origin_header", | |
| "root_cause": "System attempted operation without invariant static validation through audit_server_action_csrf_origin_header." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_014", | |
| "title": "Verifies that Server Actions enforce strict Host and Origin header checks against cross-site request forgery (Variant #2)", | |
| "tool_scope": "audit_server_action_csrf_origin_header", | |
| "root_cause": "System attempted operation without invariant static validation through audit_server_action_csrf_origin_header." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_015", | |
| "title": "Verifies that Server Actions enforce strict Host and Origin header checks against cross-site request forgery (Variant #3)", | |
| "tool_scope": "audit_server_action_csrf_origin_header", | |
| "root_cause": "System attempted operation without invariant static validation through audit_server_action_csrf_origin_header." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_016", | |
| "title": "Verifies that Server Actions enforce strict Host and Origin header checks against cross-site request forgery (Variant #4)", | |
| "tool_scope": "audit_server_action_csrf_origin_header", | |
| "root_cause": "System attempted operation without invariant static validation through audit_server_action_csrf_origin_header." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_017", | |
| "title": "Flags unmanaged concurrent state mutations in useActionState and useOptimistic hooks (Variant #1)", | |
| "tool_scope": "detect_react19_action_state_race_condition", | |
| "root_cause": "System attempted operation without invariant static validation through detect_react19_action_state_race_condition." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_018", | |
| "title": "Flags unmanaged concurrent state mutations in useActionState and useOptimistic hooks (Variant #2)", | |
| "tool_scope": "detect_react19_action_state_race_condition", | |
| "root_cause": "System attempted operation without invariant static validation through detect_react19_action_state_race_condition." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_019", | |
| "title": "Flags unmanaged concurrent state mutations in useActionState and useOptimistic hooks (Variant #3)", | |
| "tool_scope": "detect_react19_action_state_race_condition", | |
| "root_cause": "System attempted operation without invariant static validation through detect_react19_action_state_race_condition." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_020", | |
| "title": "Flags unmanaged concurrent state mutations in useActionState and useOptimistic hooks (Variant #4)", | |
| "tool_scope": "detect_react19_action_state_race_condition", | |
| "root_cause": "System attempted operation without invariant static validation through detect_react19_action_state_race_condition." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_021", | |
| "title": "Injects Zod/Pydantic schema validation into Server Action parameters to prevent untyped prototype pollution (Variant #1)", | |
| "tool_scope": "sanitize_server_action_input_payload", | |
| "root_cause": "System attempted operation without invariant static validation through sanitize_server_action_input_payload." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_022", | |
| "title": "Injects Zod/Pydantic schema validation into Server Action parameters to prevent untyped prototype pollution (Variant #2)", | |
| "tool_scope": "sanitize_server_action_input_payload", | |
| "root_cause": "System attempted operation without invariant static validation through sanitize_server_action_input_payload." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_023", | |
| "title": "Injects Zod/Pydantic schema validation into Server Action parameters to prevent untyped prototype pollution (Variant #3)", | |
| "tool_scope": "sanitize_server_action_input_payload", | |
| "root_cause": "System attempted operation without invariant static validation through sanitize_server_action_input_payload." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_024", | |
| "title": "Injects Zod/Pydantic schema validation into Server Action parameters to prevent untyped prototype pollution (Variant #4)", | |
| "tool_scope": "sanitize_server_action_input_payload", | |
| "root_cause": "System attempted operation without invariant static validation through sanitize_server_action_input_payload." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_025", | |
| "title": "Analyzes streaming SSR Suspense boundaries for missing fallback states causing UI layout thrashing (Variant #1)", | |
| "tool_scope": "inspect_suspense_boundary_flicker", | |
| "root_cause": "System attempted operation without invariant static validation through inspect_suspense_boundary_flicker." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_026", | |
| "title": "Analyzes streaming SSR Suspense boundaries for missing fallback states causing UI layout thrashing (Variant #2)", | |
| "tool_scope": "inspect_suspense_boundary_flicker", | |
| "root_cause": "System attempted operation without invariant static validation through inspect_suspense_boundary_flicker." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_027", | |
| "title": "Analyzes streaming SSR Suspense boundaries for missing fallback states causing UI layout thrashing (Variant #3)", | |
| "tool_scope": "inspect_suspense_boundary_flicker", | |
| "root_cause": "System attempted operation without invariant static validation through inspect_suspense_boundary_flicker." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_028", | |
| "title": "Analyzes streaming SSR Suspense boundaries for missing fallback states causing UI layout thrashing (Variant #4)", | |
| "tool_scope": "inspect_suspense_boundary_flicker", | |
| "root_cause": "System attempted operation without invariant static validation through inspect_suspense_boundary_flicker." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_029", | |
| "title": "Automatically generates a hardened next (Variant #1)", | |
| "tool_scope": "synthesize_hardened_next_config", | |
| "root_cause": "System attempted operation without invariant static validation through synthesize_hardened_next_config." | |
| }, | |
| { | |
| "id": "nextjs15_react19_server_secret_leak_guard_inc_030", | |
| "title": "Automatically generates a hardened next (Variant #2)", | |
| "tool_scope": "synthesize_hardened_next_config", | |
| "root_cause": "System attempted operation without invariant static validation through synthesize_hardened_next_config." | |
| } | |
| ] | |
| HEURISTIC_RULES = [ | |
| [ | |
| "execute_detect_server_action_secret_leak_unverified()", | |
| "with enforce_detect_server_action_secret_leak_policy():" | |
| ], | |
| [ | |
| "execute_detect_server_action_secret_leak_unverified()", | |
| "with enforce_detect_server_action_secret_leak_policy():" | |
| ], | |
| [ | |
| "execute_detect_server_action_secret_leak_unverified()", | |
| "with enforce_detect_server_action_secret_leak_policy():" | |
| ], | |
| [ | |
| "execute_detect_server_action_secret_leak_unverified()", | |
| "with enforce_detect_server_action_secret_leak_policy():" | |
| ], | |
| [ | |
| "execute_enforce_client_server_boundary_isolation_unverified()", | |
| "with enforce_enforce_client_server_boundary_isolation_policy():" | |
| ], | |
| [ | |
| "execute_enforce_client_server_boundary_isolation_unverified()", | |
| "with enforce_enforce_client_server_boundary_isolation_policy():" | |
| ], | |
| [ | |
| "execute_enforce_client_server_boundary_isolation_unverified()", | |
| "with enforce_enforce_client_server_boundary_isolation_policy():" | |
| ], | |
| [ | |
| "execute_enforce_client_server_boundary_isolation_unverified()", | |
| "with enforce_enforce_client_server_boundary_isolation_policy():" | |
| ], | |
| [ | |
| "execute_intercept_async_hydration_waterfall_unverified()", | |
| "with enforce_intercept_async_hydration_waterfall_policy():" | |
| ], | |
| [ | |
| "execute_intercept_async_hydration_waterfall_unverified()", | |
| "with enforce_intercept_async_hydration_waterfall_policy():" | |
| ], | |
| [ | |
| "execute_intercept_async_hydration_waterfall_unverified()", | |
| "with enforce_intercept_async_hydration_waterfall_policy():" | |
| ], | |
| [ | |
| "execute_intercept_async_hydration_waterfall_unverified()", | |
| "with enforce_intercept_async_hydration_waterfall_policy():" | |
| ], | |
| [ | |
| "execute_audit_server_action_csrf_origin_header_unverified()", | |
| "with enforce_audit_server_action_csrf_origin_header_policy():" | |
| ], | |
| [ | |
| "execute_audit_server_action_csrf_origin_header_unverified()", | |
| "with enforce_audit_server_action_csrf_origin_header_policy():" | |
| ], | |
| [ | |
| "execute_audit_server_action_csrf_origin_header_unverified()", | |
| "with enforce_audit_server_action_csrf_origin_header_policy():" | |
| ], | |
| [ | |
| "execute_audit_server_action_csrf_origin_header_unverified()", | |
| "with enforce_audit_server_action_csrf_origin_header_policy():" | |
| ], | |
| [ | |
| "execute_detect_react19_action_state_race_condition_unverified()", | |
| "with enforce_detect_react19_action_state_race_condition_policy():" | |
| ], | |
| [ | |
| "execute_detect_react19_action_state_race_condition_unverified()", | |
| "with enforce_detect_react19_action_state_race_condition_policy():" | |
| ], | |
| [ | |
| "execute_detect_react19_action_state_race_condition_unverified()", | |
| "with enforce_detect_react19_action_state_race_condition_policy():" | |
| ], | |
| [ | |
| "execute_detect_react19_action_state_race_condition_unverified()", | |
| "with enforce_detect_react19_action_state_race_condition_policy():" | |
| ], | |
| [ | |
| "execute_sanitize_server_action_input_payload_unverified()", | |
| "with enforce_sanitize_server_action_input_payload_policy():" | |
| ], | |
| [ | |
| "execute_sanitize_server_action_input_payload_unverified()", | |
| "with enforce_sanitize_server_action_input_payload_policy():" | |
| ], | |
| [ | |
| "execute_sanitize_server_action_input_payload_unverified()", | |
| "with enforce_sanitize_server_action_input_payload_policy():" | |
| ], | |
| [ | |
| "execute_sanitize_server_action_input_payload_unverified()", | |
| "with enforce_sanitize_server_action_input_payload_policy():" | |
| ], | |
| [ | |
| "execute_inspect_suspense_boundary_flicker_unverified()", | |
| "with enforce_inspect_suspense_boundary_flicker_policy():" | |
| ], | |
| [ | |
| "execute_inspect_suspense_boundary_flicker_unverified()", | |
| "with enforce_inspect_suspense_boundary_flicker_policy():" | |
| ], | |
| [ | |
| "execute_inspect_suspense_boundary_flicker_unverified()", | |
| "with enforce_inspect_suspense_boundary_flicker_policy():" | |
| ], | |
| [ | |
| "execute_inspect_suspense_boundary_flicker_unverified()", | |
| "with enforce_inspect_suspense_boundary_flicker_policy():" | |
| ], | |
| [ | |
| "execute_synthesize_hardened_next_config_unverified()", | |
| "with enforce_synthesize_hardened_next_config_policy():" | |
| ], | |
| [ | |
| "execute_synthesize_hardened_next_config_unverified()", | |
| "with enforce_synthesize_hardened_next_config_policy():" | |
| ] | |
| ] | |
| def analyze_code_ast(code: str, tool_name: str) -> Dict[str, Any]: | |
| start_time = time.perf_counter() | |
| findings = [] | |
| # Strip comments to prevent false positives | |
| lines = [line.split('#')[0] for line in code.splitlines()] | |
| stripped_code = "\n".join(lines).lower() | |
| for buggy_pattern, fix in HEURISTIC_RULES: | |
| if buggy_pattern in stripped_code: | |
| matching_inc = next((i for i in KB_INCIDENTS if i["tool_scope"] == tool_name), KB_INCIDENTS[0]) | |
| findings.append({ | |
| "rule": f"EMGENA_GUARD_{tool_name.upper()}", | |
| "severity": "CRITICAL", | |
| "message": f"Detected unmitigated defect in scope {tool_name}", | |
| "incident_id": matching_inc["id"], | |
| "root_cause": matching_inc["root_cause"], | |
| "recommended_fix": fix | |
| }) | |
| latency_ms = (time.perf_counter() - start_time) * 1000.0 | |
| return { | |
| "status": "PASS" if not findings else "VIOLATION_DETECTED", | |
| "violations_count": len(findings), | |
| "tool_scope": tool_name, | |
| "latency_ms": round(latency_ms, 3), | |
| "findings": findings | |
| } | |
| def main(): | |
| if len(sys.argv) > 1 and sys.argv[1] == "--tools": | |
| print(json.dumps([ | |
| { | |
| "name": "detect_server_action_secret_leak", | |
| "description": "AST scans Server Actions for leakage of private environment variables into client-accessible closures.", | |
| "inputSchema": { | |
| "type": "object", | |
| "properties": { | |
| "code_content": { | |
| "type": "string", | |
| "description": "Source code or payload to statically analyze." | |
| } | |
| }, | |
| "required": [ | |
| "code_content" | |
| ] | |
| } | |
| }, | |
| { | |
| "name": "enforce_client_server_boundary_isolation", | |
| "description": "Detects accidental imports of server-only modules (db, fs, secrets) into 'use client' component trees.", | |
| "inputSchema": { | |
| "type": "object", | |
| "properties": { | |
| "code_content": { | |
| "type": "string", | |
| "description": "Source code or payload to statically analyze." | |
| } | |
| }, | |
| "required": [ | |
| "code_content" | |
| ] | |
| } | |
| }, | |
| { | |
| "name": "intercept_async_hydration_waterfall", | |
| "description": "Identifies unparallelized async data fetching in nested Server Components causing severe LCP degradation.", | |
| "inputSchema": { | |
| "type": "object", | |
| "properties": { | |
| "code_content": { | |
| "type": "string", | |
| "description": "Source code or payload to statically analyze." | |
| } | |
| }, | |
| "required": [ | |
| "code_content" | |
| ] | |
| } | |
| }, | |
| { | |
| "name": "audit_server_action_csrf_origin_header", | |
| "description": "Verifies that Server Actions enforce strict Host and Origin header checks against cross-site request forgery.", | |
| "inputSchema": { | |
| "type": "object", | |
| "properties": { | |
| "code_content": { | |
| "type": "string", | |
| "description": "Source code or payload to statically analyze." | |
| } | |
| }, | |
| "required": [ | |
| "code_content" | |
| ] | |
| } | |
| }, | |
| { | |
| "name": "detect_react19_action_state_race_condition", | |
| "description": "Flags unmanaged concurrent state mutations in useActionState and useOptimistic hooks.", | |
| "inputSchema": { | |
| "type": "object", | |
| "properties": { | |
| "code_content": { | |
| "type": "string", | |
| "description": "Source code or payload to statically analyze." | |
| } | |
| }, | |
| "required": [ | |
| "code_content" | |
| ] | |
| } | |
| }, | |
| { | |
| "name": "sanitize_server_action_input_payload", | |
| "description": "Injects Zod/Pydantic schema validation into Server Action parameters to prevent untyped prototype pollution.", | |
| "inputSchema": { | |
| "type": "object", | |
| "properties": { | |
| "code_content": { | |
| "type": "string", | |
| "description": "Source code or payload to statically analyze." | |
| } | |
| }, | |
| "required": [ | |
| "code_content" | |
| ] | |
| } | |
| }, | |
| { | |
| "name": "inspect_suspense_boundary_flicker", | |
| "description": "Analyzes streaming SSR Suspense boundaries for missing fallback states causing UI layout thrashing.", | |
| "inputSchema": { | |
| "type": "object", | |
| "properties": { | |
| "code_content": { | |
| "type": "string", | |
| "description": "Source code or payload to statically analyze." | |
| } | |
| }, | |
| "required": [ | |
| "code_content" | |
| ] | |
| } | |
| }, | |
| { | |
| "name": "synthesize_hardened_next_config", | |
| "description": "Automatically generates a hardened next.config.js with strict CSP headers, serverExternalPackages, and taint protection.", | |
| "inputSchema": { | |
| "type": "object", | |
| "properties": { | |
| "code_content": { | |
| "type": "string", | |
| "description": "Source code or payload to statically analyze." | |
| } | |
| }, | |
| "required": [ | |
| "code_content" | |
| ] | |
| } | |
| } | |
| ], indent=2)) | |
| return | |
| print(f"🛡️ Emgena MCP Guard 'nextjs15_react19_server_secret_leak_guard' active via stdio.") | |
| if __name__ == "__main__": | |
| main() | |