Korr

Security model

Docs index

Security is a design priority in Korr: the safe way is the default way, and unsafe shortcuts either do not exist or must be written explicitly.

Language-level protections

Risk What Korr does
Typos create new variables / read undefined ones Every name is resolved before the program runs; unknown names stop the program with a NameError.
Accidental reassignment const cannot be reassigned (checked at compile time).
Type-juggling bugs ("1" + 1, "abc" == 0) No implicit conversions; mixing types in + is a TypeError; == never converts.
Integer overflow 64-bit integers are checked; overflow raises OverflowError.
Out-of-bounds reads/writes Indexing is bounds-checked (IndexError); get() gives a safe default.
Runaway recursion / deep nesting Call depth is limited (2,500), then RecursionError; JSON nesting is limited (256).
Wrong data shapes Optional runtime-checked type annotations on variables, parameters, return values and struct fields.
Memory safety The interpreter is written in safe Rust (the only unsafe block in Korr’s own code is the Windows OS call for secure random bytes). The optional database and HTTPS features link well-known libraries, including SQLite (C) and ring (TLS crypto).
Regular-expression denial of service (ReDoS) The re module uses a linear-time engine: no pattern or input can make matching hang.

Web protections

Risk What Korr does
Cross-site scripting (XSS) html"..." templates escape every interpolated value; nested html values are not double-escaped; raw HTML needs an explicit html.raw(). json.encode escapes <, >, & so JSON can be embedded in <script>.
Path traversal app.static rejects .., encoded %2e%2e, backslashes, NUL bytes and hidden files (.env, .git), canonicalises paths and refuses anything outside the folder.
Header injection Responses with \r / \n in header names or values are refused.
Leaking internals Uncaught handler errors return a generic 500 page; details go to server logs only (opt-in KORR_DEBUG=1 for development).
Clickjacking / MIME sniffing Every response gets X-Content-Type-Options: nosniff, X-Frame-Options: SAMEORIGIN and Referrer-Policy: strict-origin-when-cross-origin (override per response if needed).
Oversized / slow requests 64 KB header limit, 100 headers max, 10 MB body limit (app.limit()), 15-second socket timeouts; chunked request bodies are rejected.
Cookie theft http.cookie and session cookies default to HttpOnly and SameSite=Lax; add secure: true on HTTPS.
Forged or edited sessions app.sessions signs the session cookie with HMAC-SHA256; a cookie with a wrong signature or a past expiry is ignored.
Cross-site request forgery (CSRF) With sessions on, every non-JSON POST, PUT, PATCH and DELETE must carry the session’s token (req.csrf_field in forms); others get 403.
Malicious upload names req.files.x.filename keeps only safe characters and the last path part (../../x.sh becomes x.sh); uploads count toward the body limit.
Mass assignment validate(data, rules) returns only the fields listed in the rules, so extra input (is_admin=true) is dropped.
Network exposure app.listen binds to 127.0.0.1 unless you pass "0.0.0.0".
Cross-site WebSocket hijacking app.ws accepts browser connections only from pages on the same host (the Origin header must match Host); other sites must be listed in origins. before hooks run before a connection is accepted.
Malformed WebSocket input Client frames must be masked, text must be valid UTF-8, messages are limited to 1 MB (max_message); anything else closes the connection with the protocol’s error code.
Slow clients Requests are read by separate threads (4 per worker) with a 15 second timeout, so a client that sends slowly holds up one reader, not the server.
Overload Requests wait for a free worker in a queue of at most 1,024; beyond that the server answers 503 instead of using more and more memory.
Brute force and abuse app.rate_limit({ requests, per, paths }) answers 429 per client address before your code runs; behind a proxy use app.trust_proxy(true).
Cross-origin reads Without app.cors, browsers keep other sites’ pages from reading your responses; app.cors allows only the listed origins and refuses "*" with cookies.

Database and network protections

Risk What Korr does
SQL injection db sends every value as a bound parameter (? or :name); values are never pasted into SQL text. Passing the wrong number of values is an error.
Man-in-the-middle on outgoing HTTPS http.get/post/fetch always verify TLS certificates (Mozilla roots); there is no switch to turn verification off.
Huge or slow upstream responses The HTTP client has a 30-second default timeout and a 50 MB response limit.
Secrets in source code os.load_env() reads .env files; real environment variables always take precedence. Keep .env out of version control.

Secrets and passwords

Need Use
Session IDs, CSRF tokens, API keys crypto.token() (OS randomness), never math.random()
Password storage crypto.hash_password() (PBKDF2-HMAC-SHA256, 600,000 iterations, random salt) and crypto.verify_password()
Signing data crypto.hmac_sha256(secret, data)
Comparing secrets crypto.equal(a, b) (constant time)
Configuration secrets environment variables via os.env()

System access

What Korr does not do for you (yet)

Supply chain

The core language uses no third-party crates. The default build adds a small, widely used set for the optional features: rusqlite (SQLite), postgres, mysql, regex, ureq (HTTPS via rustls) and mimalloc (the memory allocator). Cargo.lock pins exact versions; review updates like your own code, and build with --no-default-features (plus only the features you need) to shrink the dependency tree.

Korr packages run with your program’s permissions, like npm, Composer or pip packages. korr.lock pins each one to an exact commit, so code only changes when you run korr add again; review what you add.


Previous: Deployment Docs index Next: Building Korr from source