In this section

0.5 Autonomy and Authority in Response

Module 0

Introduction

Module 1's hunting agent was made read-only, and its containment tool moved to a response stage that did not exist yet. Module 5 builds that stage: an incident response agent that can isolate hosts, disable accounts and block senders, but only behind approvals, and that is attacked with evidence written to make it act.

Before it can be built, two questions need firm answers. Which actions are dangerous enough that a person must decide, and what exactly must that person's decision be bound to so that the agent, or an attacker steering it, cannot stretch it into something else?

This lesson answers both. It sorts response actions by what they break and whether they can be undone, then has an assistant build the gate every action passes through: a token that lets one exact action run once, within minutes, and a ledger that records every attempt.

The check attacks the gate the way Module 5's attacks will, by replaying approvals, substituting actions and altering tokens, and two shortcuts are measured against it.

System: who holds the authorityAgentproposes an actionAltered or replayedaction or tokenapprover: a personapprove()signs digest, expiry, nonceexecutor: your codeexecute()MAC, digest, expiry, nonceledgerEvery attemptexecuted or refusedtarget systemThe effectruns once12345data flowattacker pathboundary1proposed action2signed token3effect, once4ledger entry5refused

The agent can only propose. A person signs one exact action, the executor holds the secret that verifies the signature, and the ledger records every attempt.

1

Actions and What They Break

Blast radius and undo

Incident response is guided by NIST SP 800-61, whose third revision, published in April 2025 and superseding the 2012 revision, presents incident response recommendations as a community profile of the Cybersecurity Framework 2.0. Whatever framework an organization follows, response turns on actions taken under time pressure with incomplete evidence, and the decision of how much autonomy to give an agent comes down to two properties of each action.

Visual Studio Coderesponse-actions.md - sec410-lab
response-actions.md
response-actions.md
1# Response actions: what each one does and how it is undone23| action              | blast radius                    | undo               |4|---------------------|---------------------------------|--------------------|5| isolate_host        | one device and its user         | release_host       |6| disable_account     | one person, every app they use  | enable_account     |7| revoke_sessions     | one person, signed out          | none needed        |8| block_sender        | mail from one address, everyone | unblock_sender     |9| delete_mailbox_rule | one mailbox                     | none: export first |10| wipe_device         | one device, all its data        | none               |1112Approval: every action above. Two approvers: no undo.13Agent may propose any action; it may execute none without14an approval bound to that exact action.
mainMarkdownUTF-8Ln 1, Col 1
The actions an IR agent could be given, sorted by what they break and whether they can be undone.

The first property is blast radius: what stops working, and for whom, when the action runs. Isolating a host stops one person working. Disabling an account stops that person working everywhere, across every application that account reaches. Blocking a sender affects every recipient in the organization.

The second property is undo: whether the action can be reversed, and whether reversing it restores everything. Isolation is released; an account is re-enabled. Deleting a mailbox rule destroys the rule and the evidence it was, unless someone exported it first. Wiping a device cannot be undone at all.

The policy at the bottom of the file is where these properties become rules. Every action needs an approval, actions with no undo need two approvers, and the agent may propose any action but execute none on its own.

Organizations draw these lines differently: some pre-approve isolation of a workstation for specific high-confidence detections, because speed matters more than the cost of a wrong isolation. That is a legitimate choice, made in advance, by people, for a named class of action. What the gate in this lesson guarantees is that whatever the line is, the agent cannot cross it on its own.

Undo deserves a closer look than the table gives it. Releasing an isolated host restores its network; it does not restore the hours its user could not work, or the meeting they missed. Re-enabling an account restores access; it does not restore the trust of a person locked out on the strength of a false positive.

An action with an undo is cheaper to get wrong than one without, not free. That is why the decision about how much an agent may do on its own is made against the cost of a wrong action and the confidence of the evidence behind it, and why the same organization may let an agent isolate a workstation on one detection and not on another.

Requiring approval for everything has a cost of its own. An approver asked to confirm forty actions an hour stops reading them, and an approval that is clicked without reading is a flag with extra steps.

The policy should require approval where a person's judgment changes the outcome, and make each request carry enough to judge it quickly: the action, the evidence, the blast radius and the undo. Fewer, better requests are a security property, not a convenience.

2

What an Approval Must Bind

Not yes, but yes to this

The obvious design for an approval is a flag: the agent asks, a person clicks approve, and the agent proceeds. That design fails in ways that matter more for an agent than for a person.

An agent that holds a yes can apply it to whatever it does next. It can be told by injected evidence to isolate a different host, and the yes still holds. It can retry the action ten times. It can act an hour later, after the situation has changed.

An approval worth having is bound to four things. The exact action, including every argument, so that approval to isolate WS-07 cannot isolate WS-11. The approver, so the ledger says who decided. A time limit, so that an approval granted for the situation at 10:00 cannot be used at 14:00. And a single use, so that one decision causes one effect.

Binding these together needs a value that cannot be forged or altered without detection, which is what a message authentication code provides: a keyed hash that only a holder of the key can compute, over everything the token claims.

A MAC uses one shared key, so anything that can verify a token can also create one. That is acceptable when the gate and the approval service are the same trusted component, as they are in this exercise.

When the party that checks approvals should not be able to issue them, the token is signed instead, with a private key only the approval service holds and a public key the gate uses to verify. The binding is the same; only who can mint changes. Module 7 returns to the same distinction for the tokens that identify software.

The contract states exactly that.

Visual Studio Codeapprovals.py - sec410-lab
approvals.py
lab › foundations › approvals.py
⋯ 12 lines folded13    approve(action, approver, secret, now, ttl=300) -> token14        A token {'digest', 'approver', 'expires', 'nonce', 'mac'}: expires is now + ttl (seconds); nonce is a fresh15        random hex string; mac is the HMAC-SHA256, keyed with secret (bytes), of digest, approver, expires and nonce16        joined with '|'.1718    execute(action, token, secret, now, ledger, effect) -> {'result': 'executed' | 'refused', 'reason': str}19        Runs effect(action) only if the token's mac is valid, its digest is this action's digest, it has not expired,20        and its nonce has not been used before (look in the ledger). Appends one entry to the ledger for every call:21        {'digest', 'approver', 'nonce', 'result', 'reason'}.22"""⋯ 12 lines folded
mainPythonUTF-8Ln 1, Col 1
The contract: an approval is a token for one action, once, soon.

Run the check against the file as shipped, before any of the three functions exists.

$ python3 -m lab check f05
f05  0.5 Autonomy and Authority in Response: lab/foundations/approvals.py
FAIL  the functions are written
      lesson 0.5: write digest
FAIL

The check's later properties are attacks: the same token used twice, an approval for one host presented for another, a token used after it expired, a token whose approver was edited, and a token signed with a different key. A gate that passes all of them is the minimum Module 5 builds on.

Each attack corresponds to something that happens with real approval systems. Replay is a retry loop, or a captured request sent again. Substitution is an agent, a script or a person changing the target after the approval was granted. Expiry matters because approvals are copied into tickets and chat messages and found again days later.

Tampering is anyone with access to the token editing the field that matters to them. A foreign key is a token minted by a system that should not have been able to mint one. None of them requires breaking any cryptography; each one only requires a gate that forgot to check something.

Before the brief, here is the procedure the contract describes, drawn as the steps and decisions the code has to make.

Procedure: an approval bound to one actionThe agent proposes anaction: tool and argsDigest: SHA-256 of theaction as canonical JSONA person approves; token:digest, expiry, nonce, MACexecute(action, token)Every call adds a ledgerentry, refused or not.MAC valid?noRefuse: signatureyesDigest is this action?noRefuse: a differentactionyesBefore expiry?noRefuse: expiredyesNonce unused inthe ledger?noRefuse: already usedyesRun the effect, oncestepdecisionnotestops or failsbranch ends

A person approves an exact action, not a tool; execute checks the signature, the action, the expiry and the nonce in that order, and records every attempt.

Keep it open while reading the draft: each decision in the diagram should appear as a condition in the code, and each side branch as a case the check can test.

3

Session: The Brief

Assume the token is in hostile hands

The brief points at the contract and states the threat model in one sentence.

SEC410 lab, lesson 0.52026-11-18
approvals.pyPY

Write the three functions in approvals.py to the contract in its docstring. This is the gate in front of containment actions, so treat every token as something an attacker may have copied, altered or replayed. Standard library only. Compare MACs in constant time.

approvals.pyCode · PY · 67 linesDownload
Reply to Claude…Opus 5.5
Recorded unedited in assistant-records/m00/0.5-brief.md

Treating every token as something an attacker may have copied, altered or replayed shapes the draft in ways the contract does not spell out. It means a malformed token must fail cleanly rather than crash the gate. It means the order of checks must not let a cheap check leak information about an expensive one.

And it is why the brief names constant-time comparison: comparing a MAC character by character and stopping at the first difference takes measurably longer the more characters match, which in some settings lets an attacker guess a valid MAC one character at a time. Python's standard library provides a comparison that does not stop early.

The brief also keeps the design's central fact out of the assistant's hands: who holds the key. The contract passes the secret into each function, so the code never decides where it comes from. In a deployment that choice is the whole security of the system.

If the agent's process can read the key, the agent can mint its own approvals, and every check in this lesson is decoration. The key belongs to the approval service, the service belongs to people, and the agent only ever sees tokens.

4

The Draft

A digest, a MAC, four checks

The reply was the file. Here is the code below the docstring.

Visual Studio Codeapprovals.py - sec410-lab
approvals.py
lab › foundations › approvals.py
23import hashlib24import hmac25import json26import secrets272829def digest(action):30    canonical = json.dumps(action, sort_keys=True, separators=(',', ':'))31    return hashlib.sha256(canonical.encode('utf-8')).hexdigest()323334def _mac(secret, d, approver, expires, nonce):35    message = '|'.join([d, approver, str(expires), nonce]).encode('utf-8')36    return hmac.new(secret, message, hashlib.sha256).hexdigest()373839def approve(action, approver, secret, now, ttl=300):40    d = digest(action)41    expires = now + ttl42    nonce = secrets.token_hex(16)43    return {'digest': d, 'approver': approver, 'expires': expires, 'nonce': nonce,44            'mac': _mac(secret, d, approver, expires, nonce)}454647def execute(action, token, secret, now, ledger, effect):48    d = digest(action)49    entry = {'digest': d, 'approver': token.get('approver'), 'nonce': token.get('nonce')}50    try:51        expected = _mac(secret, token['digest'], token['approver'], token['expires'], token['nonce'])52    except (KeyError, TypeError):53        expected = None54    if expected is None or not hmac.compare_digest(expected, str(token.get('mac', ''))):55        reason = 'approval signature is not valid'56    elif token['digest'] != d:57        reason = 'approval is for a different action'58    elif now > token['expires']:59        reason = 'approval has expired'60    elif any(e.get('nonce') == token['nonce'] and e.get('result') == 'executed' for e in ledger):61        reason = 'approval has already been used'62    else:63        effect(action)64        ledger.append(dict(entry, result='executed', reason='approved by ' + token['approver']))65        return {'result': 'executed', 'reason': 'approved by ' + token['approver']}66    ledger.append(dict(entry, result='refused', reason=reason))67    return {'result': 'refused', 'reason': reason}
mainPythonUTF-8Ln 1, Col 1
The draft: canonical digest, HMAC over everything the token claims, four checks before the effect.

The digest serializes the action with sorted keys and no whitespace, so the same action always produces the same bytes, then hashes them. Approval computes the digest, sets the expiry, draws a nonce from the operating system's secure random source, and computes the MAC over all four values joined by a separator.

Execution recomputes the MAC from the token's own fields and compares it in constant time; any missing or wrong-typed field fails here. Then it checks, in order, that the token is for this action, that it has not expired, and that its nonce has not already executed. Only then does the effect run, and every path appends to the ledger.

The order is worth reading. The signature is checked first, so no other field of the token is trusted until the token is known to be genuine; an attacker who edits the expiry learns only that the signature failed. The use check reads the ledger for an executed entry with the same nonce, so a token that was refused earlier, for example presented too late, does not count as used.

Canonical JSON is simple here and has edges worth knowing. Sorting keys and removing whitespace makes key order and formatting irrelevant, which the check tests. It does not settle everything two serializers can disagree on: how a floating-point number is written, how non-ASCII text is escaped, whether a number arrives as an integer or a string.

The digest is only stable if the action is built the same way when it is proposed and when it is executed, and the simplest way to guarantee that is to pass the proposed action itself, unchanged, through to execution, rather than letting anything rebuild it.

5

The Check, and the Screen

Every attack refused

Run the check against the draft, copied into the lab's foundations folder.

$ cp records/approvals-0.5.py lab/foundations/approvals.py
$ python3 -m lab check f05
f05  0.5 Autonomy and Authority in Response: lab/foundations/approvals.py
ok    the digest ignores key order and changes with the arguments
      e5d6421562e156bb...
ok    each approval carries a fresh nonce
ok    the approved action runs, once
      approved action: executed, approved by r.ahmed
ok    a used approval is refused
      same token again: refused, approval has already been used
ok    an approval cannot run a different action
      WS-07 approval for WS-11: refused, approval is for a different action
ok    an expired approval is refused
      after expiry: refused, approval has expired
ok    an altered approval is refused
      approver altered: refused, approval signature is not valid
ok    an approval signed with another key is refused
      signed with another key: refused, approval signature is not valid
ok    every attempt is in the ledger
      6 entries
PASS

The approved action ran once. The replay, the substitution, the expired token, the altered approver and the foreign key were each refused with a reason, and all six attempts are in the ledger.

The refusals are as useful as the success. A gate that refuses an approval for a different action has caught an agent, or something steering it, trying to act outside what a person decided, and that is worth an alert, not only a line in a log.

A run of replayed tokens is a retry loop or an attack; a token signed with the wrong key is a system that should not exist. Module 5 turns the ledger's refusals into detections, the same way Module 1 treated a refused tool call.

Here is what an approver would be shown, and what approval produces.

$ cp records/approvals-0.5.py lab/foundations/approvals.py
$ python3 screen.py
PROPOSED ACTION
{
  "tool": "isolate_host",
  "args": {
    "host": "WS-07",
    "reason": "Word launched encoded PowerShell"
  }
}
digest   a9b75d0a65c50f994441f2f0f9a754c478dd164a76485f04ea8373492a1d97af
approved by r.ahmed  expires in 300 seconds  nonce f95e213a2205...
mac      0948f97e0657125ba49c3912b535a7221a3c0f98b32248de24907b3ffa31837f

The approver sees the action in full, every argument, and the digest that the token will carry. The token holds no secret: the MAC proves it was issued by whoever holds the key, without revealing the key. Anyone can read a token, and nobody without the key can make or change one.

The screen's nonce and MAC differ on every run, which is correct: two approvals of the same action are two decisions, each usable once. In Module 5 the key lives with the approval service, not with the agent, which is the point: the agent can carry tokens and present them, but it cannot mint one.

What the screen shows is as important as what the token binds. An approver asked to confirm isolate host can only rubber-stamp. One shown the host, the reason, the evidence behind the reason and the undo can decide. Module 1's report, with every finding traced to its rows, is what makes a screen like this worth reading.

Time is the one input the exercise simplifies. The check passes the current time in as a number so that expiry can be tested exactly; a real gate reads its own clock, and the gate's clock is the one that counts.

If the approval service and the gate run on different machines, their clocks drift, and an approval can arrive already expired or last longer than intended. Five minutes is short enough to bound a mistake and long enough to absorb ordinary drift, which is why short expiries are measured in minutes rather than seconds.

6

An Approval That Only Says Yes, Measured

Not bound to the action

The first shortcut keeps the signature and drops the check that the token is for this action. The token is genuine; it just does not say what for.

Visual Studio Codeapprovals.py (Working Tree) - sec410-lab
approvals.py (Working Tree)
Source Control › Changes › lab/foundations/approvals.py
55          reason = 'approval signature is not valid'-     elif token['digest'] != d:-         reason = 'approval is for a different action'56      elif now > token['expires']:
main*1 file changed
The shortcut: an approval that says yes, without saying to what.

Run the check against it and read the substitution line.

$ cp records/approvals-unbound.py lab/foundations/approvals.py
$ python3 -m lab check f05 | grep -A1 "different action"
FAIL  an approval cannot run a different action
      WS-07 approval for WS-11: executed, approved by r.ahmed
$ python3 -m lab check f05 | tail -n 1
FAIL

An approval granted to isolate WS-07 isolated WS-11. The gate checked that the token was genuine, unexpired and unused, and all three were true, so it ran the effect. In an agent this is not a contrived attack.

The agent proposes one action, receives approval, and then, because the evidence it reads next tells it to, or because it reconsidered, executes a different one under the same approval. Every log says the action was approved. The person who approved it never saw it.

That is the worst property of this failure: it corrupts the record as well as the action. An investigation afterwards finds an approval in the ledger, signed by a named person, and reasonably concludes that person decided to isolate WS-11.

The approver is blamed for a decision they did not make, and the real cause, an agent that substituted its target, is invisible in the evidence. Binding the approval to the action protects the approver as much as the estate.

7

An Approval That Lasts, Measured

Not bound to one use

The second shortcut keeps the binding and drops the single-use check. The approval is for the right action and still in time; it can simply be used again.

Visual Studio Codeapprovals.py (Working Tree) - sec410-lab
approvals.py (Working Tree)
Source Control › Changes › lab/foundations/approvals.py
59          reason = 'approval has expired'-     elif any(e.get('nonce') == token['nonce'] and e.get('result') == 'executed' for e in ledger):-         reason = 'approval has already been used'60      else:
main*1 file changed
The shortcut: an approval that can be used again until it expires.

Run the check against it and read the replay line.

$ cp records/approvals-reuse.py lab/foundations/approvals.py
$ python3 -m lab check f05 | grep -A1 "used approval"
FAIL  a used approval is refused
      same token again: executed, approved by r.ahmed
$ python3 -m lab check f05 | tail -n 1
FAIL

One decision ran the action twice. The check confirms it: the second presentation of the same token, ten seconds after the first, executed again, and the gate recorded both as approved by the same person.

For isolation that may be harmless, but for most actions it is not: a second disable after the account was deliberately re-enabled, a second block after the sender was cleared, a second deletion of something recreated in the meantime. Agents retry.

A loop that does not know whether its first call succeeded calls again, and an approval that can be reused turns every retry into a new action nobody approved. The nonce makes the approval a ticket rather than a pass.

Single use and idempotency solve neighboring problems and are worth keeping apart. An idempotent action can be repeated without changing the result, so a retry is harmless; single use stops a repeat being allowed at all.

The safest gates have both: the effect is written so that applying it twice changes nothing, and the approval is spent the first time it opens the gate. Neither alone is enough, because not every effect can be made idempotent, and a single-use token does not help an agent that crashed between the effect and the ledger entry and cannot tell whether it acted.

8

From the Gate to Module 5

What the review leaves open

The session record keeps what the draft held, the two shortcuts and what they let through, and what is still open for Module 5.

Visual Studio Code0.5-session.md - sec410-lab
0.5-session.md
records › 0.5-session.md
1# Session 0.5: approvals bound to one action23Assistant: Claude Opus 5.5 (claude-opus-5-5), the SEC410 build session, 2026-11-1845## Held6- Digest over canonical JSON: sorted keys, no whitespace.7- HMAC covers digest, approver, expiry and nonce; compared in8  constant time; a malformed token fails the same check.9- Checks run before the effect: signature, action, expiry, use.10- Every call writes one ledger entry, refused or not.11- check f05: PASS.1213## Measured14- Without the digest check, a WS-07 approval isolated WS-11.15- Without the nonce check, one approval ran the action twice.1617## For Module 518- The ledger is a Python list: anyone holding it can edit it.19- One approver, one key, no record of who proposed the action.20- Nothing stops an approver approving without reading.
mainMarkdownUTF-8Ln 12, Col 1

The open items are the parts of an approval system that sit around the gate, and none of them can be fixed inside the three functions this lesson wrote. The ledger is a list in memory, so whoever holds it can rewrite history; a real one is append-only storage the agent cannot write to directly.

There is one approver and one key, and nothing records which agent proposed the action, so a compromised approver or a leaked key defeats everything. And nothing makes an approver read before approving. Module 5 builds the agent, the approval service and the ledger as separate parts, and attacks the joins between them with evidence designed to make the agent propose the wrong thing.

Underneath all three items is separation of duties, the oldest control in this lesson. The party that proposes an action should not be the party that approves it, and neither should be able to rewrite the record of what happened.

An agent is a new kind of party, fast, tireless and steerable by the text it reads, and the separation matters more for it, not less. Module 5's design starts from that rule and checks every component against it.

Do

Practice

Approvals bound to one action
the lab

Brief your assistant with the contract and the threat model, check the draft, reproduce both shortcuts, then write the response actions table for an environment you know.

Visual Studio Code0.5.md - sec410-lab
0.5.md
practice › 0.5.md
1# Practice 0.5: approvals bound to one action23## Done when4- [ ] lab/foundations/approvals.py meets its docstring's contract5- [ ] python -m lab check f05 prints PASS6- [ ] both shortcuts reproduced; what each let through recorded7- [ ] response-actions.md written for your own environment:8      blast radius and undo for each action you would give an agent9- [ ] records/0.5-<assistant>.md: brief, draft, runs, review1011## Constraints12- The secret never appears in a token, a log or the ledger.13- Every refusal says why, and is recorded.1415## Stretch16- Require two different approvers for actions with no undo.
mainMarkdownUTF-8Ln 3, Col 1

Response actions differ in blast radius and in whether they can be undone, and those two properties decide how much autonomy an agent may have. An approval must be bound to the exact action, the approver, a time limit and a single use, and a MAC over all four makes it unforgeable.

Without the binding, an approval for one host isolated another; without single use, one decision acted twice. The agent may carry approvals; only the approval service can make them.