law, ethics, and compliance · lesson 5 of 8 · sources checked 2026-11-20
compliance by design
This lesson shows how to turn compliance rules into checks that run before each request and refuse it when a result is not known.
status of this lesson: documented in my test systemthis page is not legal advice.
purpose
A compliance rule in a policy text does not stop a request. A policy gate in the code stops it, and it must fail closed. Three values of such a design have no fixed value, so the design team sets each one with a method.
objectives
- Design a policy gate that runs its checks in a fixed order before each dispatch.
- Explain why a stored rate ceiling does not limit the load on a target.
- Describe an append-only log of authorized-use attestations, and when to ask the customer again.
- Set the k value, the opt-out time limit, and the scope of one authorized-use attestation with a method.
new terms
- do-not-scan list
- A list of targets that the system must never run against.
- target
- A site or API that an operator collects data from.
- exclusion list
- A list of site classes and sites that a collection scope excludes, for example sites with sensitive data.
- robots.txt
- A file at a site root that states crawl rules for automated clients (RFC 9309).
- benchmark platform
- My test system. It runs browsers and tools against test pages and records the result.
- observed load
- The count of arrivals at a target in a time window, measured where the load lands.
- attempt
- One try of one configuration against one target, with its own browser session.
- authorized-use attestation
- A logged statement by a customer that it is authorized to test a target.
- CAPTCHA
- A challenge that a human can pass and a program cannot pass easily.
how it works
Compliance by design puts each rule into the system as a check with a record. Each rule then has a place in the code, a test, and a log row. This design is a draft of my own. No attorney examined it.
the policy gate
The policy gate runs before each dispatch. It runs five checks in a fixed order. The first refusal stops the job:
- The do-not-scan list: targets that the system must never run against.
- The exclusion list: site classes and sites outside the scope. Examples are sites with sensitive data and sites in an excluded region.
- robots.txt: the system reads the file of the host. The path must not be in a disallow rule of the file.
- Rate and budget: the count of requests to the host today must be below its ceiling.
- The authentication check: a job with a login is out of scope.
Each refusal writes one log row with the job, the check, and the reason. A dispatch writes no refusal row.
A gate that fails closed refuses when it cannot get a result. For example, the robots.txt file of a host gives the status 503. The gate does not know the rules, so it refuses the job.
The standard for robots.txt gives the same rule. A crawler that cannot get the file because of a server error must assume complete disallow RFC Editor, source 1. The same standard states that its rules are not a form of access authorization. Thus a permitted path is not permission to collect. It is only one check of the gate.
a stored ceiling is not a limit
The benchmark platform, my test system, stores a rate ceiling for each target. But only one dispatch path reads that value, and no limiter for each target enforces it. Thus the observed load on its test pages was higher than the stored ceiling.
A second fault adds to the first. The ceiling counts runs, and one run makes more than one attempt. Each attempt sends one or more requests. Thus the load in requests is a multiple of the load in runs.
example A ceiling of 10 runs a day, with 4 attempts in each run, lets 40 attempts a day reach the target. Each attempt sends one or more requests.
The correction is a check of the rate at the host, in the policy gate, in the unit of the request. The system also logs the observed load, so that a person can compare it with the ceiling.
the authorized-use attestation
Some jobs run against a target of a customer. Before such a job, the customer gives an authorized-use attestation: a logged statement that it is authorized to test the target.
The log is append-only. A change of the terms of the service makes each old statement stale. The gate then asks the customer again before the next job.
example The terms change from version 2 to version 3. A statement under version 2 is then stale, and the next job waits for a new statement.
A statement that no check reads gives a false record of control. It is worse than no statement. Thus the gate reads the newest statement before each job for that target.
less data, and a boundary
data minimization keeps only the fields that are necessary for the purpose. You can delete each dataset as one unit, for example when a customer leaves.
A regulator gives similar measures for web scraping. The CNIL recommends precise collection criteria, the deletion of data that is not relevant, and a default list of excluded sites. It also recommends to exclude the sites that oppose scraping through robots.txt or a CAPTCHA CNIL, source 2.
The customer boundary separates two kinds of sites. A roster site is a public test site. The benchmark platform can run against it on a schedule, and its results can be public. A customer site gets a run only on a request of that customer. Its facts stay private, and no public page shows it.
three values with a method
Three values of the design have a method and no fixed value:
- The k value. List the fields that can identify a person, because they are personal data. Then each record must agree with at least k minus 1 other records on those fields. The risk of re-identification is then at most 1/k for each record. Set k from the risk that you accept.
- The opt-out time limit. An opt-out signal can come after a collection. Measure the time from a new opt-out signal to the deletion in your lab. Then set the limit inside the period that the law or the contract gives.
- The scope of one authorized-use attestation. One statement can cover a target, a job, or a request. Select the scope from the question that an audit asks.
example An audit asks which jobs ran under which statement. Then one statement for each target covers too much, and one statement for each job is correct.
the two sides
| automation side | detection side |
|---|---|
| The gate runs before each request. It checks the do-not-scan list, the exclusion list, robots.txt, the rate and budget, and the login. Each refusal goes to a log. | A defender can use the same kind of controls against enumeration of its own data. Examples are a limit on distinct keys in a time window, and a watermark record in the served data. |
design decisions
| option | gain | cost | when it is correct |
|---|---|---|---|
| The gate fails closed | An unknown result never sends a request. | A host with an unreachable robots.txt gets no jobs. | Always, for a collection system |
| The gate fails open | More jobs run. | An outage of one check removes that check. | Never for a compliance check |
| The rate check counts requests | The limit agrees with the load on the target. | The gate must know the requests of each run. | When one run can send more than one request |
| The rate check counts runs | Simple to count | The load can be a multiple of the ceiling. | Only when each run sends one request |
| One authorized-use attestation for each job | An audit can link each job to a statement. | More rows in the log | When jobs change scope often |
| One authorized-use attestation for each target | Fewer rows | An audit cannot link a job to a statement. | When the scope of a target never changes |
diagram
the policy gate runs five checks in order before each dispatch, and each refusal goes to the log
A table with two columns, roster site and customer site. The benchmark platform can run against a roster site on a schedule, and its results and facts can be public. A customer site gets a run only on a request, and its results and facts stay private.
| rule | roster site | customer site |
|---|---|---|
| Who starts a run | The schedule | A customer request only |
| Scheduled runs with no request | Permitted | Never |
| Where the results go | Shared results | The customer only |
| Public pages | Can show the site | Never show the site |
| Facts about the site | Public | Private |
code example
The first example is a policy gate. It runs five checks in a fixed order, and it writes one log row for each refusal. A check that fails with an error gives a refusal.
example All hosts, paths, and counts are synthetic.
Run an ordered list of checks before each dispatch, fail closed on an unknown or failed check, and write a log row for each refusal.
import { readFileSync } from "node:fs";
// Synthetic policy and jobs. Each host is a reserved example name.
type Job = { id: string; host: string; path: string; login: boolean };
type Robots = { state: "read" | "unreachable"; disallow: string[] };
type Policy = {
doNotScan: string[];
excluded: string[];
robots: Record<string, Robots>;
ceilingPerDay: number;
sentToday: Record<string, number>;
};
type Check = { name: string; refuse: (j: Job, p: Policy) => string | null };
// The order is fixed. The first refusal stops the job.
const CHECKS: Check[] = [
{ name: "do-not-scan", refuse: (j, p) => (p.doNotScan.includes(j.host) ? "host on the do-not-scan list" : null) },
{ name: "exclusion", refuse: (j, p) => (p.excluded.includes(j.host) ? "host on the exclusion list" : null) },
{
name: "robots",
refuse: (j, p) => {
const r = p.robots[j.host];
// No robots.txt result, or an unreachable file: fail closed.
if (r === undefined || r.state !== "read") return "robots.txt not known";
return r.disallow.some((d) => j.path.startsWith(d)) ? "robots.txt disallows the path" : null;
},
},
{ name: "rate", refuse: (j, p) => ((p.sentToday[j.host] ?? 0) >= p.ceilingPerDay ? "rate ceiling reached" : null) },
{ name: "login", refuse: (j) => (j.login ? "the job needs a login" : null) },
];
function gate(j: Job, p: Policy): { check: string; reason: string } | null {
for (const c of CHECKS) {
let reason: string | null = "the check failed"; // An error is a refusal, not a pass.
try { reason = c.refuse(j, p); } catch {}
if (reason !== null) return { check: c.name, reason };
}
return null;
}
// Argument 1: a JSON file { "policy": Policy, "jobs": Job[] }.
const input = JSON.parse(readFileSync(process.argv[2], "utf8"));
const policy: Policy = input.policy;
const log: string[] = [];
for (const job of input.jobs as Job[]) {
const refusal = gate(job, policy);
if (refusal === null) {
policy.sentToday[job.host] = (policy.sentToday[job.host] ?? 0) + 1;
console.log(`${job.id}: dispatch`);
} else {
console.log(`${job.id}: refuse (${refusal.check})`);
log.push(JSON.stringify({ job: job.id, host: job.host, ...refusal }));
}
}
console.log("refusal log:");
for (const row of log) console.log(row);output
One line for each job, dispatch or refuse with the check, then the rows of the refusal log.
j1: dispatch
j2: refuse (rate)
j3: refuse (robots)
j4: refuse (robots)
j5: refuse (do-not-scan)
j6: refuse (exclusion)
refusal log:
{"job":"j2","host":"news.example.com","check":"rate","reason":"rate ceiling reached"}
{"job":"j3","host":"news.example.com","check":"robots","reason":"robots.txt disallows the path"}
{"job":"j4","host":"store.example.com","check":"robots","reason":"robots.txt not known"}
{"job":"j5","host":"shop.example.net","check":"do-not-scan","reason":"host on the do-not-scan list"}
{"job":"j6","host":"clinic.example.org","check":"exclusion","reason":"host on the exclusion list"}I ran the code with the Node runtime and the flag --experimental-strip-types. The file has six synthetic jobs and a ceiling of 2 a day:
- Jobs j1 and j2 go to the same host, which has 1 request today. Job j1 gets the last request under the ceiling.
- Job j3 asks for a disallowed path.
- Job j4 goes to a host with an unreachable robots.txt file.
- Jobs j5 and j6 go to hosts on the two lists.
The second example is an append-only log of authorized-use attestations. Each row holds the hash of the row before it, so a change of an old row shows. The check asks again when the terms changed after the statement.
example All customers, hosts, and statements are synthetic.
Keep an append-only log of authorized-use attestations with a hash chain, and ask the customer again when the terms changed after the statement.
import { createHash } from "node:crypto";
import { readFileSync } from "node:fs";
// Synthetic statements. Each customer and host is invented.
type Statement = { customer: string; target: string; scope: string; terms: string; at: string; text: string };
type Row = Statement & { prev: string; hash: string };
const rows: Row[] = [];
// Append only: each row holds the hash of the row before it.
function append(s: Statement): Row {
const prev = rows.length ? rows[rows.length - 1].hash : "start";
const hash = createHash("sha256").update(prev + JSON.stringify(s)).digest("hex").slice(0, 12);
const row = { ...s, prev, hash };
rows.push(row);
return row;
}
// A changed or removed row breaks the chain from that row on.
function chainIntact(): boolean {
let prev = "start";
for (const r of rows) {
const { prev: p, hash, ...s } = r;
const want = createHash("sha256").update(prev + JSON.stringify(s)).digest("hex").slice(0, 12);
if (p !== prev || hash !== want) return false;
prev = hash;
}
return true;
}
// The newest statement for the customer and the target must use the current terms.
function check(customer: string, target: string, currentTerms: string): string {
const last = rows.filter((r) => r.customer === customer && r.target === target).at(-1);
if (!last) return "refuse: no statement";
if (last.terms !== currentTerms) return `ask again: statement under terms ${last.terms}`;
return `allow: statement ${last.hash}`;
}
// Argument 1: a JSON file { "statements": Statement[], "currentTerms": string }.
const input = JSON.parse(readFileSync(process.argv[2], "utf8"));
for (const s of input.statements as Statement[]) append(s);
console.log(`rows: ${rows.length}, chain intact: ${chainIntact()}`);
console.log(`c1 at portal.example.com: ${check("c1", "portal.example.com", input.currentTerms)}`);
console.log(`c2 at shop.example.org: ${check("c2", "shop.example.org", input.currentTerms)}`);
console.log(`c3 at app.example.net: ${check("c3", "app.example.net", input.currentTerms)}`);
rows[0].scope = "all paths"; // Change an old row in place.
console.log(`after a change of row 1, chain intact: ${chainIntact()}`);output
The row count and the chain state, one result for each customer and target, and the chain state after a change of an old row.
rows: 2, chain intact: true
c1 at portal.example.com: ask again: statement under terms v2
c2 at shop.example.org: allow: statement 9c59bbf12a50
c3 at app.example.net: refuse: no statement
after a change of row 1, chain intact: falseI ran the code in the same way, with two synthetic statements and the current terms "v3". Customer c1 gave its statement under the terms "v2". Customer c3 gave no statement. The hash in the output depends on the text of each statement. The file gives the two statements in this order:
{ "customer": "c1", "target": "portal.example.com", "scope": "/account", "terms": "v2", "at": "2026-01-05", "text": "I am authorized to test this target." }{ "customer": "c2", "target": "shop.example.org", "scope": "/shop", "terms": "v3", "at": "2026-02-10", "text": "I am authorized to test this target." }
data
load on a test page a day, against a stored rate ceiling of 24
status of this figure: measured by me
source: Benchmark platform, data: attempts and runs on each test page a day (my test system); period 2026-07-23 to 2026-11-01; sample of 67,700
data table
| series | item | value | unit |
|---|---|---|---|
| if the rate ceiling counts attempts | configured rate ceiling | 24 | attempts a day |
| if the rate ceiling counts attempts | average calendar day | 55 | attempts a day |
| if the rate ceiling counts attempts | sweep day, median of most pages, low end | 75 | attempts a day |
| if the rate ceiling counts attempts | sweep day, highest median | 120 | attempts a day |
| if the rate ceiling counts attempts | highest day, about 10 times rate ceiling | 240 | attempts a day |
| if the rate ceiling counts runs | configured rate ceiling | 24 | runs a day |
| if the rate ceiling counts runs | average calendar day | 11 | runs a day |
| if the rate ceiling counts runs | highest day, about 2 times rate ceiling | 48 | runs a day |
The chart compares the stored rate ceiling of the benchmark platform with the load a day on its test pages, in runs and in attempts. Thus the stored rate ceiling did not limit the load.
failure modes
| problem | cause | correction |
|---|---|---|
| The load on a target is higher than its rate ceiling. | The ceiling is a stored value. Only one dispatch path reads it, and no limiter for each target enforces it. | Check the rate at the host in the policy gate. Log the observed load. |
| The load is a multiple of the ceiling. | The ceiling counts runs, and each run sends more than one request. | Count the unit that reaches the target: the request. |
| A job runs when robots.txt is unreachable. | The gate fails open on an error. | Refuse each job with an unknown or failed check. |
| A job runs on old terms. | The gate does not compare the terms of the statement with the current terms. | Ask the customer again after each change of the terms. |
| A customer site shows on a public page. | The system treats each site as a roster site. | Keep a roster gate. Only roster sites get scheduled runs and public pages. |
| An audit cannot link a job to a statement. | One statement covers too much. | Select the scope of a statement from the question of the audit. |
check questions
The robots.txt file of a host gives the status 503. What does a policy gate that fails closed do with a job for that host?
- It dispatches the job, because the file gives no rule.
- It refuses the job and writes a log row, because the result is not known.
- It dispatches the job at a lower rate.
answer
b. It refuses the job and writes a log row, because the result is not known.
A gate that fails closed refuses when it cannot get a result. RFC 9309 also says that a crawler must assume complete disallow after a server error.
Explain why a stored rate ceiling does not limit the load on a target.
sample answer
A stored value does nothing until a check reads it before each dispatch. Also, a ceiling that counts runs lets each run send more than one request, so the load in requests is a multiple of the ceiling. Check the rate at the host, in the policy gate, in requests, and log the observed load.
Describe an append-only log of authorized-use attestations, and say when the gate asks the customer again.
sample answer
Each row holds the customer, the target, the scope, the version of the terms, the time, and the hash of the row before it. A change of an old row breaks the chain. The gate reads the newest statement before each job, and it asks the customer again when the terms changed after that statement.
An audit asks which jobs ran under which statement. Which scope of one authorized-use attestation is correct?
- One statement for each target
- One statement for each customer
- One statement for each job
answer
c. One statement for each job
Select the scope from the question of the audit. A statement for each target or each customer cannot link one job to one statement.
You set k to 5 for a dataset. What is the highest risk of re-identification for one record?
- 1/5
- 1/4
- 5 percent
answer
a. 1/5
Each record agrees with at least k minus 1 other records on the fields that can identify a person. Thus the risk is at most 1/k for each record.
exercise
exercise Do this task in your own lab, with synthetic data only. Do not send a request to a site.
- Save the first code example in an empty folder of your lab.
- Write a JSON file with a ceiling of 3 a day and no requests today.
- Add four jobs to the same synthetic host, with a permitted path.
- Give the host a robots.txt state of "read" and no disallowed path.
- Run the code with Node and the flag
--experimental-strip-types. - Change the robots.txt state of the host to "unreachable", and run the code again.
- Record the result of each job in each run, and the count of refusal rows.
sample answer
This model answer uses the synthetic file of the task only.
In the first run, the first three jobs get "dispatch". The fourth job gets "refuse (rate)", because the host is at the ceiling of 3. The log has one row.
In the second run, each of the four jobs gets "refuse (robots)", because the gate cannot read the rules. The log has four rows. The rate check never runs, because the robots.txt check comes first and stops each job.
sources
- RFC 9309: Robots Exclusion Protocol, RFC Editor, standard, read 2026-11-20
- Measures for data collection by web scraping, CNIL, regulator, read 2026-11-20
- My model of a policy gate before each dispatch, of the log of authorized-use attestations, and of the method for the three values, 2026-11 (not public).
- Benchmark platform, design (my test system): the draft compliance design and the customer boundary, with no attorney review, 2026-11 (not public).
- Benchmark platform, code (my test system): the stored rate ceiling with no limiter for each target, 2026-11 (not public).