DEV Community

Cover image for I put the DPDP Act's ₹250 crore rule into Node.js code (dpdp-kit 0.3.0)
YOGESH BANSAL
YOGESH BANSAL

Posted on

I put the DPDP Act's ₹250 crore rule into Node.js code (dpdp-kit 0.3.0)

The biggest penalty in India's Digital Personal Data Protection Act isn't about consent. It's ₹250 crore, for not taking reasonable security safeguards (Section 8(5), Schedule item 1).

Rule 6 of the DPDP Rules lists the minimum safeguards, (a) to (g). In most teams they live in a policy document. dpdp-kit 0.3.0 puts the parts that belong in code into code, and gives the rest a place in your config where CI can check them.

npm i dpdp-kit
Enter fullscreen mode Exit fullscreen mode

Not legal advice. dpdp-kit helps you put compliance into practice; it doesn't make an app compliant on its own.

What Rule 6 asks for

Rule 6(1) Asks for dpdp-kit 0.3.0
(a) Encryption, obfuscation, masking, virtual tokens dpdp-kit/protect
(b) Access control security.accessControl, as evidence
(c) Logs, monitoring and review of access the access log and review()
(d) Continued processing, e.g. backups security.backups, as evidence
(e) Keep those logs for a year prune() never deletes anything newer
(f) Security clauses in processor contracts contract on each processor
(g) Technical and organisational measures security.measures, as evidence

1. The access log

Rule 6(1)(c) asks for "visibility on the accessing of such personal data, through appropriate logs, monitoring and review". So record who, whose, why and what:

await dpdp.access.log({
  actor: "support:priya",
  subjectId: userId,
  purpose: "account",
  fields: ["users.phone", "orders"],
  reason: "ticket 4411",
});
Enter fullscreen mode Exit fullscreen mode

Fields are checked against your data map. A field read for a purpose it isn't held for is recorded as outOfPurpose, or refused outright with access: { outOfPurpose: "throw" } (the attempt is still logged). Or log whole routes:

import { logAccess } from "dpdp-kit/express"; // also hono, fastify, and nestjs (accessLogGuard)

app.get("/admin/users/:id", logAccess(dpdp, {
  purpose: "account",
  fields: ["users"],
  actor: (req) => req.staff?.id,
  subject: (req) => req.params.id,
}), handler);
Enter fullscreen mode Exit fullscreen mode

2. Review it every day

const { findings } = await dpdp.access.review();
Enter fullscreen mode Exit fullscreen mode
  • out-of-purpose: fields read for a purpose they aren't held for
  • no-consent: data used for a consent purpose when the person hadn't consented at that moment (checked against the hash-chained consent history)
  • bulk-access: one actor reaching more than 100 people within an hour (both adjustable, and batch jobs can be exempted)

prune() keeps at least a year of logs, as Rule 6(1)(e) requires, and deletes older ones in batches.

3. Encryption, tokens and masking

import { createEncryptor, createTokenizer, maskAadhaar } from "dpdp-kit/protect";

const enc = createEncryptor({ keys: { k1: process.env.DPDP_KEY_1! }, current: "k1" });
const stored = enc.encrypt(aadhaar, `users.aadhaar:${user.id}`);

const tokens = createTokenizer({ key: process.env.DPDP_TOKEN_KEY! });
tokens.token(email); // same email, same token: look rows up without storing the email

maskAadhaar("1234 5678 9012"); // "XXXX XXXX 9012"
Enter fullscreen mode Exit fullscreen mode

AES-256-GCM with a random IV per value, tamper detection, an optional context that binds a value to its row (a copied value won't decrypt elsewhere), and key rotation (needsRotation() tells you what to re-encrypt).

4. One command for the whole of Rule 6

npx dpdp-kit safeguards
Enter fullscreen mode Exit fullscreen mode

It prints (a) to (g) with what your config records and what's missing. The audit also warns about Aadhaar, PAN, bank or health fields without protect, processors without a contract, and missing safeguards. --strict fails CI on gaps.

Also in 0.3.0

  • Guards for Express, Hono, Fastify and NestJS, for consent and for access logging.
  • Events: dpdp.on("consent.withdrawn", …) and seven others, for alerts and analytics. Listeners run after the change is saved and can't break it.
  • Erasure that fits your schema: a per-field erase setting for NOT NULL and UNIQUE columns, and audit --schema checks each one against the column, so a mistake fails CI now instead of the erasure a year from now.
  • dpdp.daily(): erasure, log pruning, access review and overdue rights requests in one call, with startDaily() to schedule it.

How it's tested

162 tests: guards in real Express 5, Hono and NestJS apps over HTTP, and a real Postgres 16 server through node-postgres, with three retention runners racing for the same tasks (none ran twice) and 30 simultaneous consent writes for one person (the hash chain held). CI runs on Node 20.19, 22 and 24, plus a Postgres service.

Upgrading from 0.2

Add the new dpdp_access_log table (export { accessLog } from "dpdp-kit/drizzle", or ACCESS_LOG_DDL). If you run audit --strict, add a security block and processor contracts first. The full notes are in the CHANGELOG.

Next

0.4 lands tomorrow with Prisma, MongoDB and Mongoose support, breach records with the Rule 7 deadlines, and example apps. If your team uses Prisma or Mongoose, I'd love to hear what you need.

The CI check is also on the GitHub Marketplace as DPDP Kit Audit.

Top comments (0)