-
Notifications
You must be signed in to change notification settings - Fork 19
Harden read path: base-URL host allowlist (SSRF) and error-body whitelisting #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jgalea
wants to merge
1
commit into
drewburchfield:main
Choose a base branch
from
jgalea:harden/read-path
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import { describe, it, expect, jest } from '@jest/globals'; | ||
|
|
||
| // Mock logger to reduce test output noise | ||
| jest.mock('../utils/logger.js', () => ({ | ||
| logger: { | ||
| info: jest.fn(), | ||
| error: jest.fn(), | ||
| debug: jest.fn(), | ||
| warn: jest.fn(), | ||
| }, | ||
| })); | ||
|
|
||
| import { HelpScoutDocsClient, safeDocsApiResponse } from '../utils/helpscout-docs-client.js'; | ||
|
|
||
| describe('HelpScoutDocsClient error-body whitelisting', () => { | ||
| it('safeDocsApiResponse keeps only code/error/message and truncates message', () => { | ||
| const result = safeDocsApiResponse({ | ||
| code: 'invalid', | ||
| error: 'bad input', | ||
| message: 'y'.repeat(500), | ||
| email: 'jane@bigcorp.com', | ||
| stack: 'secret stack', | ||
| }); | ||
|
|
||
| expect(result).toEqual({ | ||
| code: 'invalid', | ||
| error: 'bad input', | ||
| message: 'y'.repeat(200), | ||
| }); | ||
| expect(JSON.stringify(result)).not.toContain('jane@bigcorp.com'); | ||
| expect(JSON.stringify(result)).not.toContain('secret stack'); | ||
| }); | ||
|
|
||
| it('safeDocsApiResponse returns undefined for non-object bodies', () => { | ||
| expect(safeDocsApiResponse('plain string')).toBeUndefined(); | ||
| expect(safeDocsApiResponse(undefined)).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('does not propagate the verbatim 4xx body into the transformed error', () => { | ||
| const client = new HelpScoutDocsClient(); | ||
|
|
||
| const mockAxiosError = { | ||
| response: { | ||
| status: 400, | ||
| data: { | ||
| code: 'invalid_request', | ||
| message: 'Collection slug already exists', | ||
| submittedBy: 'jane@bigcorp.com', | ||
| }, | ||
| }, | ||
| config: { docsMetadata: { requestId: 'docs-400', startTime: Date.now() } }, | ||
| }; | ||
|
|
||
| const transformed = (client as any).transformError(mockAxiosError); | ||
|
|
||
| expect(transformed.code).toBe('INVALID_INPUT'); | ||
| expect(transformed.details.apiResponse).toEqual({ | ||
| code: 'invalid_request', | ||
| error: undefined, | ||
| message: 'Collection slug already exists', | ||
| }); | ||
| expect(JSON.stringify(transformed)).not.toContain('jane@bigcorp.com'); | ||
| }); | ||
|
|
||
| it('whitelists the 404 error body as well', () => { | ||
| const client = new HelpScoutDocsClient(); | ||
|
|
||
| const mockAxiosError = { | ||
| response: { | ||
| status: 404, | ||
| data: { code: 'not_found', message: 'No such article', secret: 'jane@bigcorp.com' }, | ||
| }, | ||
| config: { docsMetadata: { requestId: 'docs-404', startTime: Date.now() } }, | ||
| }; | ||
|
|
||
| const transformed = (client as any).transformError(mockAxiosError); | ||
|
|
||
| expect(transformed.code).toBe('NOT_FOUND'); | ||
| expect(JSON.stringify(transformed)).not.toContain('jane@bigcorp.com'); | ||
| }); | ||
| }); |
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Top-level error
messageinterpolates upstreamresponseData.messagewithout the 200-char truncation applied bysafeApiResponseThe PR adds
safeApiResponse()to whitelist and truncate fields from upstream Help Scout error bodies (cappingmessageto 200 chars indetails.apiResponse). However, both the 422 handler (line 464) and the general 4xx handler (line 479) also interpolateresponseData.messagedirectly into the top-levelmessagefield without any truncation. This means a 500-char upstream message is correctly truncated indetails.apiResponse.messagebut appears in full in the top-levelmessage. The test at line 471 only assertstransformed.details.apiResponse.messagehas length 200 — it never checkstransformed.message, which would be 529 chars. This defeats the stated PII-defense goal if the upstreammessagefield ever echoes user input.Prompt for agents
Was this helpful? React with 👍 or 👎 to provide feedback.