Skip to content

πŸ›‘οΈ Sentinel: Harden auth comparison and filter Telegram secrets#45

Open
SuvenSeo wants to merge 1 commit into
masterfrom
sentinel-security-hardening-6580909326544627956
Open

πŸ›‘οΈ Sentinel: Harden auth comparison and filter Telegram secrets#45
SuvenSeo wants to merge 1 commit into
masterfrom
sentinel-security-hardening-6580909326544627956

Conversation

@SuvenSeo

Copy link
Copy Markdown
Owner

🚨 Severity: MEDIUM/HIGH
πŸ’‘ Vulnerability:

  1. safeEqual was susceptible to timing side-channel attacks as it leaked the secret length via a preliminary length check and potentially via timingSafeEqual's requirement for matching lengths.
  2. Incoming Telegram messages lacked sensitive content filtering, unlike the web chat, allowing secrets (API keys, passwords) to be persisted in episodic memory.

🎯 Impact:

  1. An attacker could potentially brute-force secrets by observing timing differences or error states related to input length.
  2. Secrets sent via Telegram would be stored in the database and exposed to the AI model, increasing the risk of credential leakage.

πŸ”§ Fix:

  1. Refactored safeEqual to hash both inputs using SHA-256 before performing a constant-time comparison. This ensures uniform length and timing regardless of original input length.
  2. Integrated hasSensitiveContent check into the Telegram handleMessage flow, rejecting messages with secrets before they are logged or processed.

βœ… Verification:

  • Created frontend/tests/security.test.js which verifies safeEqual handles various input scenarios (matching, mismatching, different lengths) and that hasSensitiveContent correctly identifies common secret patterns.
  • Ran full project test suite (npm test), all 42 tests passed.
  • Manually verified file content and imports.

PR created automatically by Jules for task 6580909326544627956 started by @SuvenSeo

- Move `safeEqual` to `frontend/src/lib/security/crypto.js` and harden against timing side-channel attacks by hashing inputs with SHA-256 before comparison.
- Add sensitive content filtering to incoming Telegram messages in `messageHandler.js` to prevent secret persistence.
- Add security verification test suite in `frontend/tests/security.test.js`.
- Update Sentinel security journal with findings and prevention strategies.

Co-authored-by: SuvenSeo <263689617+SuvenSeo@users.noreply.github.com>
@vercel

vercel Bot commented May 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
seo-os-agent Ready Ready Preview, Comment May 29, 2026 8:17pm

@google-labs-jules

Copy link
Copy Markdown

πŸ‘‹ 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens authentication secret comparison and adds Telegram sensitive-content rejection to reduce timing-oracle and credential-persistence risks.

Changes:

  • Moves safeEqual to a new security crypto helper that hashes inputs before timingSafeEqual.
  • Adds Telegram message rejection for sensitive-looking content before normal message persistence/processing.
  • Adds security-focused tests and a Sentinel audit note.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
frontend/src/lib/security/crypto.js Adds the new hashed safeEqual helper.
frontend/src/lib/middleware/auth.js Imports safeEqual from the new crypto module.
frontend/src/app/api/auth/session/route.js Updates session auth to use the new safeEqual import.
frontend/src/app/api/telegram/webhook/route.js Updates Telegram webhook secret validation import.
frontend/src/lib/handlers/messageHandler.js Adds Telegram sensitive-content rejection before main handling.
frontend/tests/security.test.js Adds tests for safeEqual and sensitive-content detection.
.jules/sentinel.md Adds an audit log entry describing the hardening work.

πŸ’‘ Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +5 to +6
const { safeEqual } = require('../src/lib/security/crypto');
const { hasSensitiveContent } = require('../src/lib/security/sensitiveContent');

// ── Main Message Handler ──────────────────────────────────────────────────────
export async function handleMessage(chatId, text, messageId) {
if (hasSensitiveContent(text)) {
Comment on lines +4 to +6
* Constant-time comparison for secrets.
* To prevent leaking the length of the secret via timing, hash both inputs
* with SHA-256 before constant-time comparison.
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.

2 participants