diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 71a55d6d59187f135e1bea8399c84385cd4d0974..fe603bb3510b35566d702714d84a2ba664dbb69e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -57,8 +57,7 @@ scanbuild: CONFIG_OPTS: '-Dprofile=Devel -Dunit_tests=enabled' script: - flatpak-builder --user --disable-rofiles-fuse --stop-at=${FLATPAK_MODULE} flatpak_app ${MANIFEST_PATH} - - flatpak build flatpak_app bash -c "source /usr/lib/sdk/llvm12/enable.sh; meson --prefix=/app ${CONFIG_OPTS} _build; ninja -C _build scan-build" - - if [[ -n "$(ls -A _build/meson-logs/scanbuild/)" ]]; then echo "Scan build log found, assuming defects exist"; exit 1; fi + - flatpak build flatpak_app bash -c "source /usr/lib/sdk/llvm12/enable.sh; meson --prefix=/app ${CONFIG_OPTS} _build; SCANBUILD=$(pwd)/.run-scan-build ninja -C _build scan-build" artifacts: when: on_failure paths: diff --git a/.run-scan-build b/.run-scan-build new file mode 100755 index 0000000000000000000000000000000000000000..ea778b932a3999e7d517b068d590d5ee2319929c --- /dev/null +++ b/.run-scan-build @@ -0,0 +1,5 @@ +#!/bin/sh + +set -e + +scan-build -v --status-bugs -disable-checker unix.Malloc "$@" diff --git a/HACKING.md b/HACKING.md index 545d7c960efbf0a2aaf3a27864077ae991f4c8ec..8a050769f5a2991ebe8b73785bc008f464844cab 100644 --- a/HACKING.md +++ b/HACKING.md @@ -167,6 +167,19 @@ more `WebKitWebExtension`s (web process extensions). Meanwhile, each `WebKitWebView` will have one or more `WebKitWebPage`s. Only one page will be active in a view at a given time: the other pages are for process swaps. +# Security + +When injecting untrusted data into web content, you need to properly encode the +data for the relevant context in order to prevent XSS vulnerabilities. For +example: page titles could be malicious, URLs could be malicious, web app IDs +could be malicious, etc. You must carefully read and understand the [OWASP +XSS Prevention rules](https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html) +or you will mess up. `lib/ephy-output-encoding.h` contains functions to help +with this. + +When working with JavaScript, pay particular attention to Rule #8 "Prevent DOM- +based XSS" as it is tricky and requires care throughout your JavaScript. + # Debugging To enable debugging use the configure option `-Ddeveloper_mode=true`. diff --git a/embed/ephy-about-handler.c b/embed/ephy-about-handler.c index 4c794f52605e8f824de2310e892914cdea181d4c..ee169e40a633d78270069c2a7deeb2e9760cefb9 100644 --- a/embed/ephy-about-handler.c +++ b/embed/ephy-about-handler.c @@ -27,6 +27,7 @@ #include "ephy-file-helpers.h" #include "ephy-flatpak-utils.h" #include "ephy-history-service.h" +#include "ephy-output-encoding.h" #include "ephy-prefs.h" #include "ephy-settings.h" #include "ephy-smaps.h" @@ -263,19 +264,37 @@ handle_applications_finished_cb (EphyAboutHandler *handler, for (p = applications; p; p = p->next) { EphyWebApplication *app = (EphyWebApplication *)p->data; + g_autofree char *html_encoded_id = NULL; + g_autofree char *encoded_icon_url = NULL; + g_autofree char *encoded_name = NULL; + g_autofree char *encoded_url = NULL; + g_autofree char *js_encoded_id = NULL; + g_autofree char *encoded_install_date = NULL; if (ephy_web_application_is_system (app)) continue; + /* Most of these fields are untrusted. The web app suggests its own title, + * which gets used in the app ID and icon URL. The main URL could contain + * anything. Install date is the only trusted field here in that it's + * constructed by Epiphany, but it's a freeform string and we're encoding + * everything else here anyway, so might as well encode this too. + */ + html_encoded_id = ephy_encode_for_html_attribute (app->id); + encoded_icon_url = ephy_encode_for_html_attribute (app->icon_url); + encoded_name = ephy_encode_for_html_entity (app->name); + encoded_url = ephy_encode_for_html_entity (app->url); + js_encoded_id = ephy_encode_for_javascript (app->id); + encoded_install_date = ephy_encode_for_html_entity (app->install_date); g_string_append_printf (data_str, "