MMOframework
Why AI Playground Libraries Developers Agency
FR EN
Build a project live
Index
# Secure development | | | |---|---| | Reference | ISMS-A8.25-SDL (my.oviepro's ISMS, `docs/isms/politiques/developpement-securise.md` makes it binding) | | Owner | technical lead (TO COMPLETE: name) | | Version | 0.1 | | Date | 2026-11-11 | | State | draft — to be approved | | Next review | yearly, at each new OWASP Top 10, and after any security finding in a library | | Controls | ISO/IEC 27001:2022 A.8.25, A.8.26, A.8.27, A.8.28, A.8.29, A.8.30, A.5.8 (numbers only: the standard's text is not quoted) | | Ticket | #46 of my.oviepro's `iso-27001` board | How code is written, reviewed and shipped in the MMO framework, its libraries and the projects built on it (my.oviepro, hydra-agency.com, survie-ordinaire.fr). It writes down what the hub already does (`{hubFolder}/AGENTS.md`, the `mmo-change-tracking` and `mmo-release-bugs` skills, `php tools/mmo.php verify`) and adds the security rules on top. A rule here is checked in review: a change that breaks one is sent back. ## 1. The cycle (A.8.25, A.5.8) | Step | What | Security part | Evidence | |---|---|---|---| | 1. Ticket | every change starts from a ticket on a board (`boards/*.json`) | its **Impact sécurité / données** section (below) says what data, rights, secrets or external services it touches; « aucun » is an answer, a blank is not | the ticket | | 2. Design | for a change rated *yes* on impact: which principle of §3 applies, where the check sits (server side), what is logged | a risk the change adds goes to the project's risk register (my.oviepro: `docs/isms/risques.md`) | ticket discussion | | 3. Code | the rules of §4, the neighbours' style (`AGENTS.md` rule 6) | no secret, no production data, no bypass of a central guard | diff | | 4. Test | one test per security behaviour added or fixed (a right refused, an input rejected, a value escaped), beside the library's tests (`docs/Testing.md`) | the test replays the attack, not only the happy path | `tests/` | | 5. Verify | `php tools/mmo.php verify --lib=` passes: lint, phpstan (no new baseline entry, no `@phpstan-ignore`), tests | later: SAST and secret detection in the same command (tickets #42, #44) | its output in the ticket | | 6. Review | someone other than the author ticks the review checklist (`checklists/*.json`) | the reviewer reads the Impact section and the diff of every file it names | the ticks, who and when | | 7. Release | a tagged version whose checklist is fully ticked, deployed by mmo.admin (`libs/admin/docs/deploy.md`) | dependency audit (ticket #43); DAST before a major version (ticket #44) | the deployment journal | ### The « Impact sécurité / données » section of a ticket ```markdown **Impact sécurité / données** : données touchées (aucune · personnelles · santé) ; droits ou périmètre changés (oui/non : lesquels) ; secret, clé ou configuration sensible (oui/non) ; service externe nouveau (oui/non : lequel, ce qu'il reçoit) ; journalisation (ce qui est tracé) ; risque nouveau ou changé (le registre des risques du projet). ``` ## 2. A project's security requirements (A.8.26) Each project writes them before a major version, in a document of its own and, for what the code reads, in `configs/security.json` (planned: idle timeout, MFA required per role, retention per collection, classification of the project's own collections). The minimum, for any project on the framework: - the data it holds and their classification (`public`, `interne`, `personnel`, `sante`); - who can do what: roles and scopes (mmo.oauth), the perimeter a user is limited to; - authentication: password policy (`MMO\oauth\Crypt`), MFA for privileged roles, session lifetime; - what is logged, and kept how long; - the external services it calls and what each receives; - availability: how long it can be down (`docs/isms/continuite.md` for my.oviepro). ## 3. Architecture principles (A.8.27) 1. **Deny by default.** A route, a collection or a file is reachable only with a scope or a role that grants it (`AccessController::isUserAllowed()`, `checkCommitScopes()`, the `rightsScope` / `privateCollections` of the project's `AccessController` configuration). A new route with no right check is a bug. 2. **Least privilege.** Roles grant the narrowest scopes; `admin` and `sudo` are not given to make something work; a tool or a token gets the rights of its task only (a read-only GitHub token for reading). 3. **Server side decides.** The browser (mmo.client) only shows; every check — rights, perimeter, validation, status transitions — is made again on the server. A hidden button is not access control. 4. **Defence in depth.** Each layer assumes the one before can fail: validated input *and* escaped output, rights on the route *and* on the entity (`checkCommitScopes`), HTTPS *and* HSTS (`\MMO\core\server\securityHeaders()`), a CSP (ticket #27) on top of escaping. 5. **Central guards, not local fixes.** A security rule lives once, in the library that owns the layer (core for escaping, validation and headers; oauth for rights; edms for files), and every project gets it. Never work around a central guard in a project: fix it in the library, configurable with a default that changes nothing for the other projects unless the default itself is the hole (then say so). 6. **Fail closed.** An error in a check refuses (403, 401, an exception), it never lets through. A missing configuration refuses to start rather than running unprotected (e.g. no TLS to a remote database, ticket #33). 7. **Separate environments.** Development and test run on test data (`TEST CLAUDE` records, `claudetest_` databases) or anonymised copies (ticket #31), never on a production copy in clear. 8. **Secrets out of the code.** In the git-ignored files made for them: `configs/local.json`, `*.credentials.json`, `deploy.ssh.config`, a target's `shared/` (`libs/admin/docs/deploy.md`); never in `configs/config.json`, a test, a ticket or a prompt. 9. **Traceability.** Who wrote what is logged with its author (`LogQuery`), secrets masked (`LogQuery::HIDDEN`); an action made in someone's name keeps its actor (`sudo.switchAccount`). ## 4. Coding rules, by OWASP Top 10 (2021) risk (A.8.28) | Risk | Rule | MMO API to use | Do not | |---|---|---|---| | **A01 Broken access control** | check the right on every route and every write; check the perimeter (company, groups) on every read of a record and every download of a file; test each route with an account that must be refused | `AccessController::isUserAllowed()`, `checkCommitScopes()`, `\MMO\oauth\entityScopeID()`; mmo.edms tag rights (ticket #22) | rely on the menu or the client to hide a page; trust an `id` from the request without loading it through the user's perimeter | | **A02 Cryptographic failures** | HTTPS only; passwords with `password_hash` (bcrypt); random with `random_bytes()` / `random_int()` (JS: `crypto.getRandomValues`); keys made by `\MMO\oauth\writeKeys()`, never versioned | `MMO\oauth\Crypt`, `\MMO\oauth\writeKeys()`, `securityHeaders()` (HSTS) | MD5/SHA-1 for security; `Math.random()` or `mt_rand()` for a secret (finding 8 of `libs/client/docs/SECURITY_REVIEW.md`); home-made crypto | | **A03 Injection — shell** | build commands from escaped arguments only | `\MMO\core\shell\escape()` (single quotes since 2026-09, `docs/reviews/2026-09-code-review.md`), `MMO\core\server\Process` | concatenate a value, even between double quotes, into a command line | | **A03 Injection — NoSQL** | never pass a filter from the request to the database as it came; refuse keys starting with `$` from the client; cast ids and values to their type | the repository's typed queries (`aRepository`); ticket #29 for the central refusal of `$` operators | `$collection->find($request['filter'])` | | **A03 Injection — paths** | resolve a file under its folder and check it stays there | `\MMO\filename('{alias}/...')`, the `realpath` check of `MailController::findTemplate()` (the model to copy) | `__DIR__ . '/' . $request['file']`; accept `..` or an absolute path | | **A03 Injection — HTML (XSS)** | escape on output by default; markup only from trusted code, marked as such | server: `HtmlPrinter` with `escape`, `htmlspecialchars(…, ENT_QUOTES \| ENT_SUBSTITUTE)`; client: a string child is a text node (`MMO.core.dom.createElement`), `MMO.core.dom.html()` marks markup (mmo.client 3.1.0); a nonce on inline scripts (`\MMO\core\server\nonceAttribute()`) | `{=…}` interpolation of user data in a `.jhs` (it goes to the HTML sink: finding 2), `bind-html` on a field shown to another user, `` on untrusted text (finding 4) until they are fixed | | **A04 Insecure design** | the Impact section of the ticket; a status change (validate, archive) has its own scope (`entityScopeID($entity, '-change')`) and is validated on the server | entity validation (`docs/Entity.md`, `docs/Schema.md`) | enforce a workflow only in the UI | | **A05 Security misconfiguration** | security headers on every response; `display_errors` off in production; no debug route in production; `.gitattributes` `export-ignore` for what must not ship | `securityHeaders()`, `IS_DEV` / the project's dev config, mmo.admin's deny-list and `harden-check` (ticket #36) | a `test.php` or a demo in a deployed web root (finding 6) | | **A06 Vulnerable components** | vendored code listed with its version and licence; audited at each build; a high finding open more than 30 days is a non-conformity | `composer audit`, `npm audit`, the vendor inventory (ticket #43, `docs/isms/exigences-legales.md` §3) | add a dependency without a ticket; load a script from a CDN without Subresource Integrity | | **A07 Identification and authentication failures** | the login failure limit stays on (`AccessController::$maxLoginFailures`); reset answers the same whether the account exists or not; MFA for privileged roles (ticket #17) | mmo.oauth | a login, reset or token route of your own beside mmo.oauth's | | **A08 Software and data integrity failures** | data migrations as versioned patches (`db/patches/`) or release scripts; risky data work under `data-guard` (`docs/data-guard.md` of my.oviepro); unserialize only trusted data | mmo.admin `migrate`, `php admin.php data-guard` | `unserialize()` of request data; a hand-run `mongosh` update in production without a ticket | | **A09 Logging and monitoring failures** | log security events (login failures, refusals, switches of account, exports, reads of health data) with their author; never log a secret | `LogQuery`, `LogQuery::HIDDEN`, the `FAILED LOGIN` / `REFUSED LOGIN` lines; tickets #24, #25, #28, #41 | `error_log(print_r($request, true))` with a password or a token in it | | **A10 SSRF** | fetch only URLs the code builds from a fixed base; no URL taken from the user; mmo.pdf renders without remote resources (ticket #49) | `MMO\core\server\Curl` with a constant base (`CpamDirectory::DIRECTORY` is the pattern) | `file_get_contents($request['url'])` | Plus, for this framework: - **Mass assignment**: an entity's writable properties are those its schema allows; a request never sets `roles`, `owner`, `status` or a perimeter it is not entitled to (`checkCommitScopes`). - **Uploads**: through mmo.edms only (size, detected MIME type `FileManager::detectMime()`, tag rights; antivirus planned, ticket #34); never served from the web root. - **The client's address**: `\MMO\core\server\clientIP()` (and `ip()`), never `X-Forwarded-For` read by hand. It is the connection's (`REMOTE_ADDR`); the forwarding headers count only from a proxy that `MMO\core\Application`'s `trustedProxies` lists (addresses or CIDR ranges, none by default), the client being the right-most address of `X-Forwarded-For` no trusted proxy added. A server behind a reverse proxy or a load balancer lists it, else its logs show the proxy's address (my.oviepro-deploy #411). The same list decides whether `X-Forwarded-Proto` counts for `\MMO\core\server\isHttps()` (cookies `Secure`, HSTS): a site served over https by a proxy that does not list it sends them as over http (my.oviepro-deploy #422). - **E-mail**: through `\MMO\core\server\Mail` and its templates (`MailController::findTemplate()`), never with a recipient or a template name taken unchecked from the request. ## 5. Security tests (A.8.29) - Unit and functional tests in each library (`docs/Testing.md`): for each right, one test with an account that is allowed and one that is refused; for each validated input, one hostile value. - Before each release: `verify` on every changed library; secret detection (ticket #42); dependency audit (ticket #43). - Before each major version: static analysis with security rules and a ZAP baseline scan of the local instance (ticket #44); results attached to the release checklist. - Yearly: an external penetration test (A.5.35). ## 6. External contributors and AI agents (A.8.30) The same cycle, with no exception: ticket, Impact section, `verify`, tests, review by a person of the team who is not the author. In addition: - no secret and no production data in what they are given or can read (anonymised copies or test data only); - an AI agent works under a named person, who answers for it; it does not commit, push, deploy or change a remote setting without that person's explicit yes; it never prints or copies a secret it reads; - each agent's work leaves its report on the ticket (`**Claude — résultat**`, the `mmo-release-bugs` skill); - an external contributor signs the confidentiality agreement and gets the narrowest repository rights (`docs/isms/code-source.md` §5 of my.oviepro). ## 7. Known open findings Findings already found and not yet fixed are tracked where they were found: `libs/client/docs/SECURITY_REVIEW.md` (findings 1 to 15), `docs/reviews/2026-09-code-review.md`, and the `iso-27001` board of my.oviepro (tickets #17 to #49). A new finding gets a ticket on the board of every project the library concerns (the `mmo-change-tracking` skill).