Repository navigation
JSPWIKI-1323 Ignore a preferences cookie that is not a JSON object - #577
Open
arturobernalg wants to merge 2 commits into
Open
arturobernalg wants to merge 2 commits into
arturobernalg wants to merge 2 commits into
Conversation
The cookie is client data. A value that is not JSON, or not a JSON object, made Gson throw inside the page header, so the page was sent without its stylesheets and scripts, and the script that replaces the cookie never ran. Such a cookie is now ignored and the default preferences are used.
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.
JSPWIKI-1323: a malformed
JSPWikiUserPrefscookie makes the page lose its stylesheets and scripts.Preferences.parseJSONPreferencesread the cookie withnew Gson().fromJson( value, Map.class )and no error handling. A value that is not JSON, or is not a JSON object, made Gson throw inside the page header. The page was then sent with its header, content and footer but without the links to the stylesheets and without any script tag, and because no script ran, the script that replaces the cookie (Wiki.jscompares the version stored in it) never ran either. Such a cookie, and one that cannot be decoded, is now ignored and the default preferences are used. The method is package private now so that it can be tested; it was private.Measured with the WAR on Tomcat 10.1, requesting
Wiki.jspfor the page Main:{not-json[1,2]123"text"The 5 tests of the new
PreferencesTest: 2 of them fail on master (JsonSyntaxException) and all pass here.I do not know how a real user ends up with such a cookie: I built these values by hand and did not try a cookie written by an older version. Not run: the whole test suite.
https://issues.apache.org/jira/browse/JSPWIKI-1323 (related to JSPWIKI-168)