Skip to content

JSPWIKI-1323 Ignore a preferences cookie that is not a JSON object - #577

Open
arturobernalg wants to merge 2 commits into
apache:masterfrom
arturobernalg:bug/JSPWIKI-1323
Open

arturobernalg wants to merge 2 commits into
apache:masterfrom
arturobernalg:bug/JSPWIKI-1323

Conversation

@arturobernalg

Copy link
Copy Markdown
Member

JSPWIKI-1323: a malformed JSPWikiUserPrefs cookie makes the page lose its stylesheets and scripts.

Preferences.parseJSONPreferences read the cookie with new 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.js compares 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.jsp for the page Main:

Cookie master this branch
none 9966 bytes, 4 script tags 9966 bytes, 4 script tags
{not-json 3954 bytes, 0 script tags 9966 bytes, 4 script tags
[1,2] 3954 bytes, 0 script tags 9966 bytes, 4 script tags
123 3954 bytes, 0 script tags 9966 bytes, 4 script tags
"text" 3954 bytes, 0 script tags 9966 bytes, 4 script tags

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)

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.
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.

1 participant