{"id":50454142,"url":"https://github.com/mizcausevic-dev/wasm-policy-gateway","last_synced_at":"2026-06-01T01:05:41.577Z","repository":{"id":357460615,"uuid":"1236287089","full_name":"mizcausevic-dev/wasm-policy-gateway","owner":"mizcausevic-dev","description":"Edge policy gateway: pure-Rust geo + rate-limit + A/B routing engine, compiled to WASI (wasm32-wasip1, ~128KB). Runs in Wasmtime, Fastly Compute, Cloudflare Workers via WASM components. Deterministic, fuzzable, portable.","archived":false,"fork":false,"pushed_at":"2026-05-12T21:42:41.000Z","size":30,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-12T23:04:17.322Z","etag":null,"topics":["ab-testing","cloudflare-workers","edge","platform-engineering","policy-engine","rate-limiting","rust","wasi","wasm","wasmtime","webassembly"],"latest_commit_sha":null,"homepage":"https://github.com/mizcausevic-dev/wasm-policy-gateway","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mizcausevic-dev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-12T05:44:03.000Z","updated_at":"2026-05-12T21:42:45.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/mizcausevic-dev/wasm-policy-gateway","commit_stats":null,"previous_names":["mizcausevic-dev/wasm-policy-gateway"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/mizcausevic-dev/wasm-policy-gateway","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizcausevic-dev%2Fwasm-policy-gateway","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizcausevic-dev%2Fwasm-policy-gateway/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizcausevic-dev%2Fwasm-policy-gateway/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizcausevic-dev%2Fwasm-policy-gateway/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mizcausevic-dev","download_url":"https://codeload.github.com/mizcausevic-dev/wasm-policy-gateway/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizcausevic-dev%2Fwasm-policy-gateway/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33755379,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-31T02:00:06.040Z","response_time":95,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ab-testing","cloudflare-workers","edge","platform-engineering","policy-engine","rate-limiting","rust","wasi","wasm","wasmtime","webassembly"],"created_at":"2026-06-01T01:05:41.505Z","updated_at":"2026-06-01T01:05:41.563Z","avatar_url":"https://github.com/mizcausevic-dev.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# wasm-policy-gateway\n\nA pure-Rust edge policy engine — geo gating, rate limiting, A/B routing — that compiles to **WASI (wasm32-wasip1)** and runs identically on a server, in [Wasmtime](https://wasmtime.dev), or as a worker module in any environment that hosts WASI components.\n\n128 KB optimized WASM. Deterministic input → output. No I/O inside the engine, so it's trivially fuzzable, reproducible, and portable.\n\n## What it does\n\nGiven a JSON `EvaluationRequest` (config + input), returns a JSON `PolicyDecision`. The pipeline:\n\n1. **Geo gate** — deny if the request's country is on the configured block list.\n2. **Rate limit** — deny if the request's bucket is out of tokens.\n3. **A/B routing** — redirect if the request's bucket matches a configured A/B rule.\n4. Default → **allow** (with token decrement).\n\nFirst gate to fire decides the outcome.\n\n## Quickstart\n\n```bash\n# Build the WASI binary\ncargo build --release --target wasm32-wasip1\n\n# Run it through wasmtime\nwasmtime run target/wasm32-wasip1/release/policy-gateway.wasm \u003c examples/allow.json\n```\n\nOutput:\n\n```json\n{\"decision\":\"allow\",\"policy_id\":\"demo-policy-001\",\"redirect_to\":null,\"rate_tokens_after\":99,\"reasons\":[\"allow_default\"]}\n```\n\nTry the other examples:\n\n```bash\n$ wasmtime run target/wasm32-wasip1/release/policy-gateway.wasm \u003c examples/deny-geo.json\n{\"decision\":\"deny\",\"policy_id\":\"demo-policy-001\",\"redirect_to\":null,\"rate_tokens_after\":null,\"reasons\":[\"geo_blocked:KP\"]}\n\n$ wasmtime run target/wasm32-wasip1/release/policy-gateway.wasm \u003c examples/redirect-ab.json\n{\"decision\":\"redirect\",\"policy_id\":\"demo-policy-001\",\"redirect_to\":\"https://canary.example.com\",\"rate_tokens_after\":49,\"reasons\":[\"ab_redirect:experimental\"]}\n```\n\n## Library usage (native)\n\n```rust\nuse policy_gateway::{evaluate_json, PolicyConfig, PolicyInput};\n\nlet cfg = PolicyConfig {\n    policy_id: \"demo-2026-05\".into(),\n    blocked_countries: vec![\"KP\".into()],\n    ab_redirects: vec![],\n};\nlet input = PolicyInput {\n    country: Some(\"US\".into()),\n    rate_bucket: Some(\"free\".into()),\n    rate_tokens_remaining: 100,\n    ab_bucket: None,\n    original_url: None,\n};\nlet decision = cfg.evaluate(\u0026input);\nprintln!(\"{:?}\", decision);\n```\n\nBoth `cfg.evaluate(\u0026input)` (typed) and `evaluate_json(\u0026raw)` (string-in, string-out) are exposed.\n\n## Why WASI?\n\nEdge runtimes increasingly accept WASI modules (Wasmtime, Fastly Compute@Edge, Cloudflare Workers via the WASM components story). Writing the engine once in Rust and shipping the same `.wasm` artifact to all of them eliminates the rewrite-per-environment tax. The 128 KB binary is small enough to ship in a request's cold-start budget.\n\n## Build artifact\n\n| Profile | Size |\n|---|---|\n| release `wasm32-wasip1` | ~128 KB |\n| release native | ~600 KB |\n\nRelease WASM is `opt-level = \"s\"`, `lto = true`, `codegen-units = 1`, `strip = true`.\n\n## Development\n\n```bash\ncargo fmt --check\ncargo clippy --all-targets -- -D warnings\ncargo test --release\ncargo build --release --target wasm32-wasip1\n```\n\nTests are pure Rust — they don't require Wasmtime. They exercise the policy pipeline natively.\n\n## License\n\nAGPL-3.0.\n\n---\n\n**Connect:** [LinkedIn](https://www.linkedin.com/in/mirzacausevic/) · [Kinetic Gain](https://kineticgain.com) · [Medium](https://medium.com/@mizcausevic/) · [Skills](https://mizcausevic.com/skills/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmizcausevic-dev%2Fwasm-policy-gateway","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmizcausevic-dev%2Fwasm-policy-gateway","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmizcausevic-dev%2Fwasm-policy-gateway/lists"}