Conversation
Contributor
Greptile SummaryThis PR improves Sentry error reporting by adding a Key changes:
Confidence Score: 3/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Sentry error captured] --> B{beforeSend hook}
B --> C[sanitizeEvent]
C --> D[sanitize breadcrumbs.data]
C --> E[sanitize contexts]
C --> F[sanitize extra]
C --> G[sanitize stackframe vars]
C --> H[❌ event.request NOT sanitized]
H --> I[Authorization / Cookie headers leak]
D & E & F & G --> J[Return sanitized event → Sentry]
subgraph identify.ts
K[Session restored / user login] --> L[identify - sentry.setUser + posthog.identify]
M[Logout] --> N[resetIdentity - sentry.setUser null + posthog.reset]
end
Prompt To Fix All With AIThis is a comment left during a code review.
Path: packages/browseros-agent/packages/shared/src/sentry/sanitize.ts
Line: 59-87
Comment:
**`event.request` not sanitized — headers/cookies can still leak**
`sanitizeEvent` scrubs `breadcrumbs`, `contexts`, `extra`, and stackframe vars, but never touches `event.request`. On the server (`@sentry/bun`) with `sendDefaultPii: true`, Sentry automatically captures the full inbound HTTP request under `event.request`, including a `headers` map that can contain `Authorization: Bearer <token>` and `Cookie: …` values. Those keys would be caught by `isSensitiveKey`, but only if the `request` field is actually passed through `sanitize()`.
Add the missing section:
```ts
if (e.request) {
e.request = sanitize(e.request)
}
```
Place it alongside the existing `e.contexts` / `e.extra` blocks so headers and cookies are scrubbed before the event is sent.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: packages/browseros-agent/apps/agent/lib/sentry/sanitize.ts
Line: 1-77
Comment:
**Duplicate `sanitize.ts` — agent should use the shared version**
This file is an almost-exact copy of `packages/shared/src/sentry/sanitize.ts`, which was added in the same PR and is now exported via the `package.json` export map (`./sentry/sanitize`). Maintaining two near-identical copies increases the risk of them drifting out of sync (e.g., if a new sensitive pattern is added to the shared version but forgotten here).
The agent's `sentry.ts` could simply import from the shared package instead:
```ts
import { sanitizeEvent } from '@browseros/shared/sentry/sanitize'
```
This lets the agent's `lib/sentry/sanitize.ts` file be removed entirely.
**Rule Used:** Remove unused/dead code rather than leaving it in ... ([source](https://app.greptile.com/review/custom-context?memory=9b045db4-2630-428c-95b7-ccf048d34547))
**Learnt From**
[browseros-ai/BrowserOS-agent#126](https://github.com/browseros-ai/BrowserOS-agent/pull/126)
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "feat: added analytics for logged in user..." | Re-trigger Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces improved user identity tracking across analytics and error reporting, and adds robust sanitization of sensitive data in Sentry events for both agent and server applications. It ensures that user identification is consistently set or cleared on login/logout, and that sensitive information (like API keys and tokens) is redacted from error reports before they are sent.
User Identity Management and Analytics:
Added new
identifyandresetIdentityfunctions inidentify.tsto synchronize user identity across analytics (PostHog) and error tracking (Sentry). These are now called on login, logout, and session changes to keep user context accurate. (packages/browseros-agent/apps/agent/lib/analytics/identify.ts,packages/browseros-agent/apps/agent/lib/auth/AuthProvider.tsx,packages/browseros-agent/apps/agent/entrypoints/app/login/LogoutPage.tsx) [1] [2] [3] [4] [5]On the server side, user identity is now set in Sentry using
Sentry.setUserwith thebrowserosIdfor better traceability of errors. (packages/browseros-agent/apps/server/src/main.ts)Sensitive Data Sanitization in Sentry Events:
sanitizeEventutility in@browseros/shared/sentry/sanitizethat recursively redacts sensitive fields (like tokens, passwords, secrets) from Sentry event payloads. This utility is now used in both agent and server SentrybeforeSendhooks to prevent accidental leakage of credentials in error reports. (packages/browseros-agent/packages/shared/src/sentry/sanitize.ts,packages/browseros-agent/apps/agent/lib/sentry/sanitize.ts,packages/browseros-agent/apps/agent/lib/sentry/sentry.ts,packages/browseros-agent/apps/server/src/lib/sentry.ts,packages/browseros-agent/packages/shared/package.json) [1] [2] [3] [4] [5] [6] [7]Other Improvements:
baseUrlin Sentry context, further reducing risk of leaking sensitive URL components. (packages/browseros-agent/apps/server/src/api/routes/chat.ts)These changes significantly improve both user privacy and the quality of analytics and error reporting across the BrowserOS agent and server.