Stop sending the stack trace to the browser - #716
Merged
Conversation
The web entry point's top-level catch built its error response as ActionResponse::error($e->getMessage(), $e->getTrace()), and the second argument is the response's data — which a JSON action serialises straight to the browser. So any JSON endpoint that threw answered with every frame's file, class and function, and the arguments each was called with wherever the platform is configured to keep them. In a password manager those arguments are the worst possible thing to put in an error page. The API entry point has only ever sent the message; this makes the web one match. Nothing is lost: processException() has already written the trace to the log, which is where it belongs. The test fails without the change — the response's data comes back as the trace array — and it checks the body for the application path as well, so a trace in any other shape would still be caught.
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.
The bug
The web entry point's top-level catch built its error response like this:
The second argument is the response's data, and
ActionResponse::jsonSerialize()puts it straight into the JSON body. So any JSON endpoint that threw answered the browser with the exception's full stack trace: every frame's file, class and function, and the arguments each frame was called with wherever the platform is configured to keep them.In a password manager, those arguments are the worst possible thing to put in an error page.
The API entry point has only ever sent the message — this makes the web one match.
Nothing is lost
processException($e)runs a line earlier and has already written the trace to the log, which is where it belongs.Testing
A test that drives a real JSON action into a failure and asserts the response carries the message, a 500, and no data. It fails without the change — the data comes back as the trace array — and it also checks the body for the application path, so a trace in any other shape would still be caught.
Found while covering the entry points (#715), which is also where its sibling was found:
Init.php:335callsini_set('session.gc_maxlifetime', …)after the session has already been started, so it always fails silently and the configured timeout never reaches PHP's own garbage collector. That one is a separate change.