Skip to content

FIX: Sanitize externally visible API errors#2237

Open
hannahwestra25 wants to merge 6 commits into
microsoft:mainfrom
hannahwestra25:hannahwestra25-sanitize-api-error-responses
Open

FIX: Sanitize externally visible API errors#2237
hannahwestra25 wants to merge 6 commits into
microsoft:mainfrom
hannahwestra25:hannahwestra25-sanitize-api-error-responses

Conversation

@hannahwestra25

@hannahwestra25 hannahwestra25 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Description

Backend and runtime exceptions can contain credentials, internal paths, provider details, and private endpoints. This change replaces unexpected diagnostics in API and rendered UI responses with stable public messages while retaining detailed server-side logging.

Safe validation now uses ClientRequestError instead of broad ValueError, preserving actionable 4xx messages without exposing constructor or SDK failures. Public blocked-content messages remain visible. Error outcome reasons, retry diagnostics, and nested endpoint fields are sanitized only in external projections; persisted diagnostic data is unchanged.

Tests and Documentation

Added focused backend and frontend leakage regressions for secrets, internal paths, provider details, blocked responses, and safe validation errors. Ran targeted pytest suites, Ruff, Jest, TypeScript type-check, and ESLint. Documentation changes were not applicable.

hannahwestra25 and others added 2 commits July 20, 2026 16:49
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 2040f373-2101-4e34-a067-70c15ac7211e
Distinguish public registry validation from constructor failures, sanitize error outcome reasons, and retain blocked-content messages.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 2040f373-2101-4e34-a067-70c15ac7211e
Comment thread pyrit/backend/mappers/attack_mappers.py Outdated

logger = logging.getLogger(__name__)

_ATTACK_ERROR_MESSAGE = "Attack execution failed. Check server logs for details."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

But users can't see the server logs. I think we've been going the opposite direction so far because people want to know what went wrong. Of course, that's not an argument to not hide secrets.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good call, removed the "check server logs" bit. the 1CS policy (“Applications MUST NOT expose sensitive application data to end-users through error messages,” and cryptographic errors reported remotely “must be reported only in generic terms.”) requires this but also as a follow up item we could have more structured error categories to give a little bit more of an actionable error

Update frontend expectations for generic runtime and server errors and apply Ruff formatting required by pre-commit.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 2040f373-2101-4e34-a067-70c15ac7211e
Resolve target identity validation using canonical hashes while preserving a client-safe mismatch response.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 2040f373-2101-4e34-a067-70c15ac7211e
Keep public failure messages generic without directing users to operator-only logs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 2040f373-2101-4e34-a067-70c15ac7211e
Assert the generic client-safe 500 response instead of raw backend details.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 2040f373-2101-4e34-a067-70c15ac7211e
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