Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Access checks must fail closed
Grant access only on an explicit positive match so missing or unexpected values deny access.
Bad example
| 1 | const data = await response.json(); |
| 2 | // undefined !== 'DENY' is true -> access granted on missing/unexpected value |
| 3 | return res.status(200).json({ hasAccess: data?.decision !== 'DENY' }); |
Explanation (EN)
Access is derived from a negative comparison. If the field is missing, null, or returns an unexpected string, `value !== 'DENY'` evaluates to true and access is granted by accident — the check fails open.
Objašnjenje (HR)
Pristup se izvodi iz negativne usporedbe. Ako polje nedostaje, null je, ili vrati neočekivani string, `value !== 'DENY'` daje true i pristup se slučajno odobrava — provjera otkazuje 'otvoreno' (fail open).
Good example
| 1 | const data = await response.json(); |
| 2 | // only an explicit 'ALLOW' grants access; anything else denies |
| 3 | return res.status(200).json({ hasAccess: data?.decision === 'ALLOW' }); |
Explanation (EN)
Access requires an explicit positive value. Missing, null, or unrecognized responses all evaluate to false, so the check fails closed and denies access by default.
Objašnjenje (HR)
Pristup zahtijeva eksplicitnu pozitivnu vrijednost. Vrijednosti koje nedostaju, null su, ili nisu prepoznate, sve daju false, pa provjera otkazuje 'zatvoreno' (fail closed) i prema zadanom odbija pristup.
Notes (EN)
Apply the same fail-closed default to upstream errors and non-OK responses: treat them as 'no access' rather than letting them pass through.
Bilješke (HR)
Primijeni isti fail-closed zadani princip na greške i ne-OK odgovore s drugih servisa: tretiraj ih kao 'nema pristupa' umjesto da ih propustiš.