Flow custom misuse types
This contract covers Castles Flow builds that include detection API schema migration 27 (custom_misuse). Older builds answer these paths with 403 or 404.
A custom misuse type is a named traffic class, for example RDP for TCP to port 3389. Every managed object and threshold set gets it as a Host Detection row, with the same thresholds a built-in type has. Without thresholds, a type is not detected.
Methods and access
Section titled “Methods and access”Call the HTTPS origin of your Flow installation with its current human session. Access works the same as for threshold sets: reads need detection_defaults.read, changes need detection_defaults.write. Browser write requests have to come from the installation’s configured origin. A missing or expired session gets 401. Insufficient permission or an untrusted origin gets 403.
| Method | Purpose |
|---|---|
GET /api/v1/detection/custom-misuse |
All types with their use. |
POST /api/v1/detection/custom-misuse |
Create a type; the server assigns its id. |
PUT /api/v1/detection/custom-misuse/{id} |
Replace name, state and conditions; the id never changes. |
DELETE /api/v1/detection/custom-misuse/{id} |
Delete a type that no threshold uses. |
Type fields
Section titled “Type fields”| Field | Value |
|---|---|
id |
c_ followed by lowercase letters, digits and underscores, at most 40 characters. Built from the name on creation (RDP becomes c_rdp, a taken id gets _2, _3, …). Built-in types never start with c_. |
name |
1 to 64 characters without control characters, unique without regard to case. |
enabled |
false keeps the type and its thresholds but stops its detection. Default true. |
proto |
IP protocol numbers 0 to 255, at least one, at most 64. TCP is 6, UDP 17, ICMP 1. |
dst_ports, src_ports |
Inclusive [from, to] pairs, 1 to 65535; a single port is [p, p]. At most 64 items each. An empty array means any port. Ports need protocols with ports only (6, 17, 33, 132). |
tcp_flags |
null or {"mask": m, "value": v}, bytes 0 to 255: a sample matches when flags AND mask = value. mask is not 0, value has no bit outside mask, and proto is exactly [6]. SYN without ACK is {"mask": 18, "value": 2}. |
pkt_len |
Optional null or inclusive [min, max], 1 to 65535: the sampled frame length for sFlow, the average packet size of a NetFlow or IPFIX record. |
used_by |
Read only. objects and sets with an active rule for the type (see below). |
updated_at, updated_by |
Read only. Last change, RFC 3339 time and login. |
Conditions combine with AND. Inside a list, any item matches. The server sorts protocols, drops repeats and merges overlapping or adjacent port ranges. The response may therefore be written differently from the request, but it matches the same traffic.
List types
Section titled “List types”Example request and HTTP 200 response:
const response = await fetch('/api/v1/detection/custom-misuse', { credentials: 'same-origin' });if (!response.ok) throw new Error(String(response.status));const { items } = await response.json();{ "items": [ { "id": "c_rdp", "name": "RDP", "enabled": true, "proto": [6], "dst_ports": [[3389, 3389]], "src_ports": [], "tcp_flags": null, "pkt_len": null, "used_by": {"objects": 2, "sets": 1}, "updated_at": "2026-10-07T09:12:44.512Z", "updated_by": "operator" } ]}Create and change a type
Section titled “Create and change a type”POST takes name, enabled, proto, dst_ports, src_ports, tcp_flags and, optionally, pkt_len. It answers 201 with the type. An installation holds 64 types at most.
const response = await fetch('/api/v1/detection/custom-misuse', { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: 'RDP', enabled: true, proto: [6], dst_ports: [[3389, 3389]], src_ports: [], tcp_flags: null })});PUT /api/v1/detection/custom-misuse/c_rdp takes the same body and answers 200 with the type. An absent pkt_len keeps the stored range; null removes it. Changing conditions or state reloads detection. Open incidents of the type carry on under the new conditions.
Delete a type
Section titled “Delete a type”DELETE answers 204, unless the type is in use. It is in use while an object’s own Host Detection rules, a threshold set, or both have an active rule for it, meaning enabled and with a positive packet or bit trigger. In that case the answer is 409 and nothing changes:
{"error": "custom_misuse_in_use", "used_by": {"objects": 2, "sets": 1}}Switch those rules off or clear their triggers first. The delete then removes any remaining inactive rules of the type from objects, sets and the global defaults in the same transaction. A later type that reuses the id starts with no thresholds.
Errors
Section titled “Errors”Validation errors return 400 with a short reason:
{"error": "invalid_custom_misuse", "reason": "ports_need_tcp_udp"}| Reason | Cause |
|---|---|
invalid_body |
The body is not a JSON object. |
invalid_name, name_exists |
Empty, too long or control characters; the name is taken. |
invalid_enabled |
Not a boolean. |
invalid_proto, proto_empty, too_many_proto |
A value outside 0 to 255; no protocol; more than 64. |
invalid_ports, invalid_port_range, too_many_ports |
Not an array of pairs; a port outside 1 to 65535 or from above to; more than 64 items. |
ports_need_tcp_udp |
Ports with a protocol that has no ports. |
invalid_tcp_flags, tcp_flags_need_tcp |
Mask 0, a value bit outside the mask or another field; protocols other than TCP. |
invalid_pkt_len |
Not a pair within 1 to 65535 with min not above max. |
too_many_types |
64 types already exist. |
An unknown id returns 404 {"error": "not_found"}. A change that is saved but has not reached detection yet returns 500 {"error": "saved_not_delivered"}. The service retries delivery by itself.
Thresholds
Section titled “Thresholds”A type’s id is a key of host_detection in three places: the thresholds of a managed object (PUT /api/v1/detection/mo/{id}), a threshold set (/api/v1/detection/sets) and the global defaults (PUT /api/v1/detection/defaults). The rule format is the built-in one:
{ "host_detection": { "c_rdp": {"enabled": true, "trigger_pps": 5000, "trigger_bps": 0, "high_pps": 20000, "high_bps": 0} }}No rule, or a rule with both triggers at 0, means the type is not detected for that object. A c_ key that does not name a stored type returns 400. The global defaults store custom rules, but global detection does not evaluate custom types. They only apply inside managed objects.
Detection
Section titled “Detection”Every five second bucket, the canonical detector counts all enabled custom types in one bounded read of raw flow samples from managed object prefixes. Per destination address, it sums packets and bytes of matching samples, multiplied by their sampling rate. Host thresholds, high severity, fast flood, smartmode and carpet detection behave as they do for built-in types. Late rows are recounted for tracked hosts within the recount window, though a carpet of a custom type keeps its first counts. Raw samples follow the installation’s retention, so a custom type’s incident chart is only available within that window.
Incidents, reports and the alert workspace carry the type id in misuse and attack_type. The alert journal message and notifications show the type name. For names anywhere else, look them up with the list method.