Skip to content
Getting startedSecurity

What is DaloyJS?

Meet the TypeScript REST framework that limits incoming requests, keeps production errors private, and can refuse a new route the moment its author forgets authentication.

Devlin Duldulaosoftware engineer & published book author3 min read

DaloyJS is a secure-by-default TypeScript framework for building REST APIs. Say I ask a coding agent to add a bookstore endpoint that returns a customer’s order history. It can write the handler, fetch the orders, and give me a passing test in one sitting. My first review question is simple. What happens if a stranger asks for those orders?

There are two parts to the answer. DaloyJS puts limits on incoming requests as soon as I create an app. For customer data, I also turn on its application-wide authentication policy. That choice changes what happens the next time someone adds a route and forgets who should be allowed to call it.

What you get from a plain app

A new DaloyJS app has a 1 MiB request body limit and a 30-second request timeout. If a caller sends an oversized JSON body to an endpoint that reads JSON, the framework can return 413 before the handler processes it. Its parser also rejects object keys that could be used for prototype pollution. Those checks are already there when the first handler lands. Security guide

The defaults cover what leaves the server, too. Security headers are applied automatically. If a database call throws an unexpected error in production, the client gets a problem response with the internal detail redacted. The customer needs to know the request failed. The name of my database host is my problem.

Make a forgotten authentication check fail immediately

In a bookstore, publishing the catalog is intentional. Publishing order histories would be a breach. For an API like that, I set the opt-in requireAuth: true policy when constructing the app. Every new route then needs an authentication hook in scope or an explicit public: true declaration. DaloyJS enforces that rule during registration, even on a developer’s laptop. Route registration guard

Try this small test in a Node starter with @daloyjs/core installed. The assertion passes when DaloyJS refuses the route:

ts
import assert from "node:assert/strict";
import { App } from "@daloyjs/core";

const app = new App({ requireAuth: true });

assert.throws(
  () => app.get("/orders", {
    responses: { 200: { description: "Customer orders" } },
  }, () => ({ status: 200 as const, body: [] })),
  /refused route GET \/orders/,
);

For the real orders route, I’d register jwk() to verify access tokens from my identity provider, including their issuer and the audience for this API. Then I’d have the database query select orders belonging to the verified customer. A valid login tells me who is asking. The customer ID in that query determines whose orders leave the building. Authentication guide

Put two customers in the test

Give Alice one order and Ben another. Call the endpoint without credentials and expect a 401. Then call it with Alice’s token and check the entire result contains only Alice’s order. A test that merely finds Alice’s order in the response also passes if the handler accidentally returns Ben’s. That’s a remarkably cheerful green check for a privacy bug. Testing guide

The Node starter gives you a public catalog to experiment with, request IDs, and rate limiting. Its route definitions also generate OpenAPI documentation, and the same framework runs on Node, Bun, Deno, and Cloudflare Workers. What makes me reach for DaloyJS is that I can put an access rule in the app today and have it enforced on a route an agent writes tomorrow. Build your first API