Skip to content

🛡️ Sentinel: API Hardening and Telemetry Sanitization - #260

Merged
alehar9320 merged 5 commits into
mainfrom
sentinel/api-hardening-900021383698555327
Jun 6, 2026
Merged

alehar9320 merged 5 commits into
mainfrom
sentinel/api-hardening-900021383698555327

Conversation

@alehar9320

@alehar9320 alehar9320 commented Jun 6, 2026 •

Copy link
Copy Markdown
Owner

Severity: Medium
Impact: Improves defense-in-depth against clickjacking and content sniffing, prevents potential logic errors from malformed storage data, and mitigates risks of leaking sensitive data via telemetry logs.

This change hardens the portfolio's API infrastructure by implementing stricter security headers and improving the resilience of the rate-limiting mechanism. It also introduces a standardized way to sanitize Zod validation errors before logging them to telemetry, ensuring that potentially sensitive user input is never leaked into server-side logs.


PR created automatically by Jules for task 900021383698555327 started by @alehar9320

Summary by CodeRabbit

  • Security

    • Strengthened API response headers with a stricter Content Security Policy and strict content-type protection across endpoints and streams
  • Bug Fixes

    • Made rate limiting more robust by defensively handling malformed counters
    • Sanitized telemetry by redacting sensitive validation fields before logging
  • Tests

    • Added/updated tests to cover headers, rate-limit recovery, and sanitized validation telemetry
  • Documentation

    • Added a changelog entry (2026-05-25) describing these security and telemetry improvements

- Harden API security headers (CSP, X-Content-Type-Options) in chat API.
- Implement Number.isNaN() validation for rate-limiting counter.
- Sanitize Zod telemetry by redacting 'received' and 'value' keys in chat API and GitHub releases utility.
- Update Sentinel journal.

Co-authored-by: alehar9320 <5390430+alehar9320@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 6, 2026 •

Copy link
Copy Markdown
Contributor

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
me 9138826 Commit Preview URL

Branch Preview URL
Jun 06 2026, 12:15 PM

@coderabbitai

coderabbitai Bot commented Jun 6, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 665b981b-7a1f-49e8-9220-b648d12714c5

📥 Commits

Reviewing files that changed from the base of the PR and between 92861bb and 9138826.

📒 Files selected for processing (4)
  • src/__tests__/chat-api.test.ts
  • src/__tests__/github-releases.test.ts
  • src/pages/api/chat.ts
  • src/utils/github-releases.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/utils/github-releases.ts
  • src/pages/api/chat.ts

📝 Walkthrough

Walkthrough

Security headers (CSP, X-Content-Type-Options) are added to API and SSE responses. Rate-limit counter parsing defends against NaN values. Zod validation errors are sanitized in chat API and GitHub releases by redacting telemetry fields (received, value) before logging. Changelog documents the changes.

Changes

API Hardening and Telemetry Sanitization

Layer / File(s) Summary
API security header hardening
src/pages/api/chat.ts, src/__tests__/chat-api.test.ts
JSON error response headers and SSE streaming response headers are extended with X-Content-Type-Options: nosniff and a restrictive Content-Security-Policy; tests assert the headers.
Rate-limit counter defensive parsing
src/pages/api/chat.ts, src/__tests__/chat-api.test.ts
Rate-limit counter parsing now guards against NaN using a reset-to-zero flow; added test verifies malformed stored counter resets and persists as '1' while allowing the request.
Zod validation telemetry sanitization
src/pages/api/chat.ts, src/utils/github-releases.ts, src/__tests__/chat-api.test.ts, src/__tests__/github-releases.test.ts
Zod validation error logging is sanitized by cloning issues and removing received and value fields before emitting logs; tests assert the sensitive fields are absent in logged telemetry.
Changelog entry
.Jules/sentinel.md
New entry (2026-05-25) documents security header hardening, rate-limit NaN handling, and telemetry sanitization.

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

size/L

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately summarizes the main changes: API hardening with security headers and telemetry sanitization through redaction of sensitive fields. It directly reflects the core objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sentinel/api-hardening-900021383698555327

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Jun 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@codecov

codecov Bot commented Jun 6, 2026 •

Copy link
Copy Markdown

Bundle Report

Changes will increase total bundle size by 78 bytes (0.01%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
molecular-mars-esm 520.4kB 78 bytes (0.01%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: molecular-mars-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
_astro/page.D4bdSMmI.js (New) 264.73kB 264.73kB 100.0% 🚀
_astro/PostHog.astro_astro_type_script_index_0_lang.AcBHKRL-.js (New) 188.58kB 188.58kB 100.0% 🚀
_astro/github-releases.LJ-rdpuO.js (New) 63.52kB 63.52kB 100.0% 🚀
_astro/whats-new.astro_astro_type_script_index_0_lang.D1aNun93.js (New) 2.85kB 2.85kB 100.0% 🚀
_astro/Footer.astro_astro_type_script_index_0_lang.C1JGpZaD.js (New) 718 bytes 718 bytes 100.0% 🚀
_astro/page.ngazjnFP.js (Deleted) -264.73kB 0 bytes -100.0% 🗑️
_astro/PostHog.astro_astro_type_script_index_0_lang.m4ZJ589t.js (Deleted) -188.58kB 0 bytes -100.0% 🗑️
_astro/github-releases.CJNeQMYR.js (Deleted) -63.44kB 0 bytes -100.0% 🗑️
_astro/whats-new.astro_astro_type_script_index_0_lang.xRvWchek.js (Deleted) -2.85kB 0 bytes -100.0% 🗑️
_astro/Footer.astro_astro_type_script_index_0_lang.BeK_Fkpn.js (Deleted) -718 bytes 0 bytes -100.0% 🗑️

Files in _astro/github-releases.LJ-rdpuO.js:

  • ./src/utils/github-releases.ts → Total Size: 4.06kB

@coderabbitai coderabbitai Bot added the size/L label Jun 6, 2026
@mergify mergify Bot removed the size/L label Jun 6, 2026
- Harden API security headers (CSP, X-Content-Type-Options) in chat API.
- Implement Number.isNaN() validation for rate-limiting counter resilience.
- Sanitize Zod telemetry by redacting 'received' and 'value' keys in chat API and GitHub releases utility.
- Expand unit tests to ensure 100% diff coverage for security logic.
- Update Sentinel journal.

Co-authored-by: alehar9320 <5390430+alehar9320@users.noreply.github.com>
@alehar9320
alehar9320 temporarily deployed to sentinel/api-hardening-900021383698555327 - astro-cloudflare-personal-website-web-service PR #260 June 6, 2026 09:03 — with Render Destroyed
@alehar9320
alehar9320 temporarily deployed to sentinel/api-hardening-900021383698555327 - astro-cloudflare-personal-website-web-service PR #260 June 6, 2026 12:13 — with Render Destroyed
@coderabbitai coderabbitai Bot added the size/L label Jun 6, 2026
@mergify mergify Bot removed the size/L label Jun 6, 2026
@alehar9320
alehar9320 merged commit 7381a6c into main Jun 6, 2026
14 checks passed
@alehar9320
alehar9320 deleted the sentinel/api-hardening-900021383698555327 branch June 6, 2026 19:04

This branch was successfully deployed

No deployments
sentinel/api-hardening-900021383698555327 - astro-cloudflare-personal-website-web-service PR #260 — 91388267 Deployed Jun 6, 2026 by alehar9320
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant