Content-Security-Policy builder
Your task
Build a Content-Security-Policy header string from a directives mapping (directive name to list of source values), enforcing two rules. (1) Within each directive's source list, deduplicate while preserving first-seen order. (2) If a directive's sources contain "'none'", that directive must collapse to exactly "'none'" (any other sources are dropped). Emit directives in the dict's iteration order, each as 'name source1 source2', joined by '; '. Skip directives with an empty source list entirely. Return the final header string.
Examples
build_csp(directives: dict) -> strExample 1
Input
build_csp({"default-src": ["'self'"], "img-src": ["'self'", "data:", "'self'"]})Output
"default-src 'self'; img-src 'self' data:"