Skip to content

Commit

Permalink
Do not expose host in internal API error messages (elastic#172645)
Browse files Browse the repository at this point in the history
## Summary

Only expose the `path` instead of the full `url` in the internal route
handler error messages
  • Loading branch information
pgayvallet authored Dec 6, 2023
1 parent 11451b4 commit 9f3f22a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ describe('restrictInternal post-auth handler', () => {
name: 'my-server-name',
restrictInternalApis: true,
});

it('returns a bad request if called without internal origin header for internal API', () => {
const handler = createRestrictInternalRoutesPostAuthHandler(config as HttpConfig);
const request = createForgeRequest('internal');
Expand All @@ -310,8 +311,8 @@ describe('restrictInternal post-auth handler', () => {
const result = handler(request, responseFactory, toolkit);

expect(toolkit.next).not.toHaveBeenCalled();
expect(responseFactory.badRequest.mock.calls[0][0]?.body).toMatch(
/uri \[.*\/internal\/some-path\] with method \[get\] exists but is not available with the current configuration/
expect(responseFactory.badRequest.mock.calls[0][0]?.body).toMatchInlineSnapshot(
`"uri [/internal/some-path] with method [get] exists but is not available with the current configuration"`
);
expect(result).toBe('badRequest');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const createRestrictInternalRoutesPostAuthHandler = (
if (isRestrictionEnabled && isInternalRoute && !request.isInternalApiRequest) {
// throw 400
return response.badRequest({
body: `uri [${request.url}] with method [${request.route.method}] exists but is not available with the current configuration`,
body: `uri [${request.url.pathname}] with method [${request.route.method}] exists but is not available with the current configuration`,
});
}
return toolkit.next();
Expand Down

0 comments on commit 9f3f22a

Please sign in to comment.