# Security Guidelines for C++ Developer UI (Monitoring Pages)
This document describes security requirements for C++ developers writing monitoring pages (Developer UI) in YDB. These pages are generated at runtime using `HTML(str) { ... }` macros and served by the built-in HTTP monitoring server.
Example of the pull request with CSRF protection and nonce handling in HTTP responses: [#36981](https://github.com/ydb-platform/ydb/pull/36981).
---
## 1. Content Security Policy (CSP) and `nonce`
> **What the PR actually enforces.** PR [#36981](https://github.com/ydb-platform/ydb/pull/36981) sets exactly one CSP directive on monitoring responses:
>
> ```http
> Content-Security-Policy: script-src 'nonce-AbCd…=='
> ```
>
> There is **no** `style-src`, `font-src`, `connect-src`, `frame-src`, `img-src`, or `default-src` in the emitted header. So today only `
)___";
```
**✅ CORRECT — generate a nonce per response, attach it to the response event, and use it in `";
}
}
```
For pages served via `TEvHttpInfoRes` (local mon, not forwarded through tablets), the same `res->Nonce = nonce` assignment applies — see `Notify(...)` in [`tablet_monitoring_proxy.cpp`](../ydb/core/tablet/tablet_monitoring_proxy.cpp). Do **not** reuse a nonce across responses — generate a fresh one each time `OnRenderAppHtmlPage` is invoked.
The nonce is preserved when the response is forwarded across nodes: [`TEvRemoteHttpInfoRes::SerializeToArcadiaStream`](../ydb/library/actors/core/mon.cpp) packs it alongside the HTML, so the same pattern works for remote tablet monitoring.
### Rule: NEVER weaken the `script-src` CSP
Do not add `'unsafe-inline'`, `'unsafe-eval'`, or external domains to `script-src`. If a script doesn't work without `'unsafe-inline'`, rewrite it to use a nonce (see the rule above).
**❌ FORBIDDEN — weakening `script-src`:**
```cpp
response << "Content-Security-Policy: script-src 'unsafe-inline'\r\n";
response << "Content-Security-Policy: script-src 'self' https://cdn.example.com\r\n";
```
### Rule: Avoid new inline styles even though CSP does not block them today
There is no `style-src` directive in the CSP header set by PR [#36981](https://github.com/ydb-platform/ydb/pull/36981), so inline styles (`style="..."` attributes and inline `";
```
**✅ PREFER — put styles into a static CSS file served from the same origin:**
```cpp
// In ydb/core/viewer/.../monitoring.css (served from /static/):
// .mon-warning { color: red; margin: 5px; }
// .mon-table th { text-align: center; }
str << "