Skip to content

Building 70 Projects ranging from beginner to advanced so anyone can β€” learn from, build upon, use as a reference, or even copy directly. Owned by my cybersecurity company πŸ‘‡

fix(not-sandboxed): restore security headers on the routes a browser renders

CarterPerez-dev2b702064e0bb
diff --git a/PROJECTS/beginner/prompt-injection-firewall/infra/docker/vite.prod b/PROJECTS/beginner/prompt-injection-firewall/infra/docker/vite.prod
index 1260460f..aa37addb 100644
--- a/PROJECTS/beginner/prompt-injection-firewall/infra/docker/vite.prod
+++ b/PROJECTS/beginner/prompt-injection-firewall/infra/docker/vite.prod
@@ -43,6 +43,7 @@ RUN rm -rf /usr/share/nginx/html/* && \
COPY --from=builder /app/dist /usr/share/nginx/html
COPY --chown=nginx:nginx infra/nginx/nginx.prod.conf /etc/nginx/nginx.conf
+COPY --chown=nginx:nginx infra/nginx/security-headers.conf /etc/nginx/security-headers.conf
COPY --chown=nginx:nginx infra/nginx/prod.nginx /etc/nginx/conf.d/default.conf
RUN chown -R nginx:nginx /usr/share/nginx/html && \
diff --git a/PROJECTS/beginner/prompt-injection-firewall/infra/nginx/prod.nginx b/PROJECTS/beginner/prompt-injection-firewall/infra/nginx/prod.nginx
index ba1b4188..5faaa0f1 100644
--- a/PROJECTS/beginner/prompt-injection-firewall/infra/nginx/prod.nginx
+++ b/PROJECTS/beginner/prompt-injection-firewall/infra/nginx/prod.nginx
@@ -16,15 +16,12 @@ server {
access_log /var/log/nginx/access.log main_timed buffer=32k flush=5s;
error_log /var/log/nginx/error.log warn;
- add_header X-Frame-Options "SAMEORIGIN" always;
- add_header X-Content-Type-Options "nosniff" always;
- add_header X-XSS-Protection "1; mode=block" always;
- add_header Referrer-Policy "strict-origin-when-cross-origin" always;
- add_header Permissions-Policy "geolocation=(), microphone=(), camera=()" always;
+ include /etc/nginx/security-headers.conf;
location /health {
access_log off;
return 200 "healthy\n";
+ include /etc/nginx/security-headers.conf;
add_header Content-Type text/plain;
}
@@ -54,6 +51,7 @@ server {
location /assets/ {
expires 1y;
+ include /etc/nginx/security-headers.conf;
add_header Cache-Control "public, immutable";
access_log off;
try_files $uri =404;
@@ -61,11 +59,13 @@ server {
location ~* \.(jpg|jpeg|png|gif|ico|svg|webp|avif|woff|woff2|ttf|eot|otf)$ {
expires 1y;
+ include /etc/nginx/security-headers.conf;
add_header Cache-Control "public, immutable";
access_log off;
}
location / {
+ include /etc/nginx/security-headers.conf;
add_header Cache-Control "no-cache, must-revalidate";
try_files $uri $uri/ /index.html;
}
diff --git a/PROJECTS/beginner/prompt-injection-firewall/infra/nginx/security-headers.conf b/PROJECTS/beginner/prompt-injection-firewall/infra/nginx/security-headers.conf
new file mode 100644
index 00000000..b4ff3a87
--- /dev/null
+++ b/PROJECTS/beginner/prompt-injection-firewall/infra/nginx/security-headers.conf
@@ -0,0 +1,20 @@
+# =============================================================================
+# AngelaMos | 2026
+# security-headers.conf
+# =============================================================================
+# nginx inherits add_header from an outer level ONLY IF the current level
+# declares none of its own. Four locations here set their own Cache-Control,
+# which silently dropped every server-level security header on exactly the
+# routes a browser renders: HTML pages, JS, CSS, fonts. The JSON API kept
+# them, because it declares no add_header of its own. Exactly backwards.
+#
+# Including this in every location that sets any header of its own is the
+# only construction that cannot silently regress: adding a Cache-Control to
+# a new location without the include is a visible omission, not an invisible
+# side effect.
+
+add_header X-Frame-Options "SAMEORIGIN" always;
+add_header X-Content-Type-Options "nosniff" always;
+add_header X-XSS-Protection "1; mode=block" always;
+add_header Referrer-Policy "strict-origin-when-cross-origin" always;
+add_header Permissions-Policy "geolocation=(), microphone=(), camera=()" always;