I have a web application, which has a search form. The user entered his query string into the input field and submitted the form using the submit button. Next, the Result page shows the search result.
The result page has an "endless scrolling" feature. This means, when reaching the end of the page, now results are loaded. So I have to send the 2nd query to the search engine with the same query string.
Currently, I see the following options:
1.) Using session-Parameter:
The first search request (coming from the search form) stores all search parameters, including the user's query string, in a session storage and the "endless scroll"-javascript function simply calls the "search"- URL without any additional GET-Parameter
Pro: no direct XSS problems (?)
Contra: the users mostly have to explicit reset his search/remove querystring from session parameter by doing an action.
2.) Echoing the query string in result page:
During the generation of the search result page, the user's query string is rendered into the webpage. For example in a hidden field or as a javascript parameter. So javascript can fetch this query string and use this as a query parameter or submit the form using ajax.
Pro: when re-entering the page, no old search data is loaded from the session store - it's more transparent for the user. No "reset-session-search-parameter" mechanism is needed
Contra: probably it's vulnerable for XSS, even when HTML is encoded... (?)
My questions: a.) Are these correct assumptions of pro and contra? b.) Who would you solve that problem?