diff --git a/examples/todo-app/pages/index.tsx b/examples/todo-app/pages/index.tsx
index 7bc5bb2b..03e2dd6e 100644
--- a/examples/todo-app/pages/index.tsx
+++ b/examples/todo-app/pages/index.tsx
@@ -1,5 +1,5 @@
/** @jsx h */
-import { h, HandlerContext, Suspense, useData } from "../deps.ts";
+import { h, HandlerContext, PageConfig, Suspense, useData } from "../deps.ts";
import { getDatabase, Todo } from "../utils/database.ts";
export default function TodoListPage() {
@@ -48,3 +48,5 @@ export const handler = {
return Response.redirect(ctx.req.url, 303);
},
};
+
+export const config: PageConfig = { csp: true };
diff --git a/runtime.ts b/runtime.ts
index fd307424..b35eb535 100644
--- a/runtime.ts
+++ b/runtime.ts
@@ -4,3 +4,4 @@ export * from "./src/runtime/suspense.ts";
export * from "./src/runtime/utils.ts";
export * from "./src/runtime/hooks.ts";
export * from "./src/runtime/head.ts";
+export * from "./src/runtime/csp.ts";
diff --git a/src/runtime/csp.ts b/src/runtime/csp.ts
new file mode 100644
index 00000000..9955b054
--- /dev/null
+++ b/src/runtime/csp.ts
@@ -0,0 +1,139 @@
+import { createContext, useContext } from "./deps.ts";
+
+export const SELF = "'self'";
+export const UNSAFE_INLINE = "'unsafe-inline'";
+export const UNSAFE_EVAL = "'unsafe-eval'";
+export const UNSAFE_HASHES = "'unsafe-hashes'";
+export const NONE = "'none'";
+export const STRICT_DYNAMIC = "'strict-dynamic'";
+
+export function nonce(val: string) {
+ return `'nonce-${val}'`;
+}
+
+export interface ContentSecurityPolicy {
+ directives: ContentSecurityPolicyDirectives;
+ reportOnly: boolean;
+}
+
+export interface ContentSecurityPolicyDirectives {
+ // Fetch directives
+ /**
+ * Defines the valid sources for web workers and nested browsing contexts
+ * loaded using elements such as and