Skip to content

Conversation

@chrisd8088
Copy link
Member

The version of the JQuery library we use for the https://git-lfs.com home page was released in 2016 and is the subject of a few security reports, so although our use of JQuery is limited, we update it to the latest version. We also simplify our JavaScript code which performs a basic attempt at client OS detection.

First, we update our version of JQuery from is 1.12.4 to 3.7.1. The older version is the subject of a number of security issues, including:

Next, we remove our use of the session.min.js JavaScript library, which appears to be from the codejoust/session.js project. Our version seems to match the code in the session.js file following PR codejoust/session.js#41, with minification applied manually. Regardless, as that project has not received updates in the last four years, and we only use a very small fraction of its functionality, we replace it with a few lines of CoffeeScript to perform a basic form of OS detection using the same technique as the codejoust/session.js library, namely a search for the specific strings Mac or Linux in the navigator.platform variable.

This variable's use is deprecated in current MDN JavaScript documentation; however, it remains the most straightforward
way of performing the basic and limited OS detection we require. In future we may choose to replace this with another approach, such as the User-Agent Client Hints API, but this is not yet supported by some major Web clients such as Firefox at the present time.

Both the legacy version of the codejoust/session.js library and the most recent update to that library (from 2019) pass the navigator object to the library's session_fetch() function, which calls the library'ssearch() function to set the os variable we check, passing an internal data.os array containing the possible OS types and their identifying strings. The search() function then tests for a match with one of these array elements, and in the case of the two checks we perform (for MacOS and Linux) this is just a search for a given substring (Mac or Linux) in the string returned by navigator.platform.

Thus we can just perform these simple checks ourselves, which will suffice for our purposes, and avoid the need to use a legacy JS library entirely. Our replacement CoffeeScript compiles to the following JavaScript:

$(function() {
    var platform;
    platform = window.navigator.platform;
    if ((platform.indexOf('Mac')) !== -1) {
        return $('.js-mac').removeClass('visually-hidden');
    } else if ((platform.indexOf('Linux')) !== -1) {
        return $('.js-linux').removeClass('visually-hidden');
    } else {
        return $('.js-windows').removeClass('visually-hidden');
    }
});

Finally, we can adjust the file permissions on one static file to remove its unnecessary executable file permissions.

In commit f9bbd2d a then-current version
of the JavaScript library from https://github.com/codejoust/session.js
(in minified form) was added to the Git LFS home page in order to help
provide detection of the user's operating system and thus suggest the
appropriate release package of Git LFS to download.

This JS library is no longer up-to-date, and the upstream project
does not appear to be actively maintained.  It also provides a lot
of additional client detection capabilities which the Git LFS home page
does not require.

We can simplify our home page to instead perform a basic form of
OS detection using the same technique as the session.js library,
namely a search for the specific strings "Mac" or "Linux" in the
navigator.platform variable.  While this variable's use is deprecated
in current JavaScript documentation, it remains the most straightforward
way of performing the basic and limited OS detection we require.
See, for reference:

https://developer.mozilla.org/en-US/docs/Web/API/Navigator/platform
https://developer.chrome.com/en/docs/privacy-sandbox/user-agent/

In future we may choose to replace this with another approach,
such as the User-Agent Client Hints API, but this is not yet supported
by some major Web clients:

https://developer.mozilla.org/en-US/docs/Web/API/WorkerNavigator/userAgentData

Both the legacy version of the session.js library and the most
recent update to that library (from 2019) pass the "navigator" object
to the library's session_fetch() function, which calls the library's
search() function to set the "os" variable we check, passing an internal
"data.os" array containing the possible OS types and their identifying
strings.  The search() function then tests for a match with one of these
array elements, and in the case of the two checks we perform (for MacOS
and Linux) this is just a search for a given string ("Mac" or "Linux")
in the string returned by navigator.platform.

Thus we can just perform these simple checks ourselves, which will
suffice for our purposes, and avoid the need to use a legacy JS library
entirely.
We can remove the executable file permissions from a static file
which does not contain a command-line script or program.
@chrisd8088 chrisd8088 requested a review from a team October 25, 2023 04:15
@chrisd8088 chrisd8088 merged commit c334d4e into main Oct 25, 2023
@chrisd8088 chrisd8088 deleted the update-jquery branch October 25, 2023 16:08
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.

3 participants