Page MenuHomePhabricator

(MS 7) Security Readiness Review For Wikidata Query Builder
Closed, ResolvedPublic

Description

Project Information

Description of the tool/project: Client-only tool that builds SPARQL queries for Wikidata query service (https://query.wikidata.org). Users who do not know SPARQL can not make use of the powerful Wikidata Query Service and with that the full power of Wikidata. The Query Builder is changing that by providing an interactive form-like interface. It allows users to click-together a query visually. The Query Builder then generates the SPARQL code for this visual query for them. The existing Wikidata Query Service backend is used to execute the query and visualize the result. The tool only acts as a frontend and does not have its own backend nor state.

Description of how the tool will be used at WMF: We intend to deploy it as a subpage of the existing Wikidata Query Service at query.wikidata.org and link it from there. The tool will be used by re-users of Wikidata's data and editors to build SPARQL queries.

Dependencies

Has this project been reviewed before?
No (only regular code-review in the team)

Working test environment
Either:

Post-deployment

Wikidata team at WMDE.

Details

Author Affiliation
Wikimedia Deutschland

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript
amy_rc renamed this task from Security Readiness Review For Wikidata Query Builder to (MS 7) Security Readiness Review For Wikidata Query Builder.Jan 22 2021, 12:03 PM

We will have a code-freeze in the next two weeks and would appreciate a security review.

@Lydia_Pintscher - We've tentatively scheduled this review for our 4th quarter, which began April 1st and will continue until June 30th, 2021. We should have this review completed by the end of this quarter at the latest. Please feel free to let us know if you have any additional questions or feel free to review our current security readiness reviews SOP.

Thank you!
If there is anything we should do on our side to help make it go faster please let me know.

sbassett added a project: user-sbassett.
sbassett moved this task from Q1:2021 Review Queue to In Progress on the secscrum board.
sbassett moved this task from Backlog to In Progress on the user-sbassett board.

Security Review Summary - TT264822 - 2021-06-25
Last commit reviewed: 2d65299a44

Summary

Overall, the current Query Builder code looks fairly secure with certain issues outlined below. I would currently rate the overall risk as: Medium. See a public-facing summary of the WMF's risk management policy here: T249039#6309061 (sadly, the full version is still protected under officewiki.)

Vulnerable Packages - Production

None: as verified with auditjs, snyk and npm audit. Still, I'd note that these dependencies add an additional 584,927 lines of code to Query Builder's codebase, thus dramatically increasing complexity and potential future risk. And with dev dependencies, that figure becomes 9,678,194 lines of code. Risk: Low.

Vulnerable Packages - Development

npm audit (though curiously not snyk or auditjs) found a massive number of development dependency vulnerabilites: 5,551 to be exact. They break down as 1 low, 303 moderate and 5,247 high from 2,875 scanned packages. Allegedly, npm audit fix can be used to automatically upgrade the vast majority to secure versions, while 35 require manual review. While development dependency vulnerabilities typically pose a substantially smaller risk than those found within production dependencies, the risk is not zero, especially for development tools used to build production artifacts like vue-cli-service. Just scanning the results, I'd note that a large volume of these appear to be for the @vue/cli-service, @vue/cli-plugin-unit-jest and netlify-cli dependencies, so bumping those to more recent versions (if feasible) would likely substantially reduce this risk. For now, given the sheer volume of vulnerabilities, and the fact these are for somewhat-critical development tools, particularly vue-cli-service, this will be rated as a High Risk.

Outdated Packages
As reported via npm outdated:
(no explicit vulnerabilities reported, simply noting for completeness' sake.)
Risk: None.

PackageCurrentWantedLatest
PackageCurrentWantedLatest
@types/jest24.9.124.9.126.0.23
@types/lodash4.14.1684.14.1704.14.170
@types/node14.14.2814.17.415.12.4
@typescript-eslint/eslint-plugin2.34.02.34.04.28.0
@typescript-eslint/parser2.34.02.34.04.28.0
@vue/cli-plugin-babel4.5.114.5.134.5.13
@vue/cli-plugin-eslint4.5.114.5.134.5.13
@vue/cli-plugin-typescript4.5.114.5.134.5.13
@vue/cli-plugin-unit-jest4.5.114.5.134.5.13
@vue/cli-plugin-vuex4.5.114.5.134.5.13
@vue/cli-service4.5.114.5.134.5.13
@vue/eslint-config-typescript5.1.05.1.07.0.0
@vue/test-utils1.1.31.2.11.2.1
@wmde/wikit-tokens2.0.0-alpha.122.0.0-alpha.121.1.2
@wmde/wikit-vue-components2.0.0-alpha.122.0.0-alpha.121.1.2
core-js3.8.33.15.13.15.1
cypress6.3.06.9.17.6.0
eslint7.20.07.29.07.29.0
eslint-config-wikimedia0.17.00.17.00.20.0
eslint-plugin-chai-friendly0.6.00.6.00.7.1
eslint-plugin-cypress2.11.22.11.32.11.3
eslint-plugin-vue6.2.26.2.27.12.1
geckodriver1.22.11.22.32.0.0
jest-axe4.1.04.1.05.0.1
netlify-cli2.71.02.71.03.38.10
ress3.0.03.0.04.0.0
sass1.32.71.35.11.35.1
sass-loader8.0.28.0.212.1.0
sparqljs3.2.03.4.23.4.2
start-server-and-test1.12.01.12.51.12.5
stylelint13.10.013.13.113.13.1
stylelint-config-standard20.0.020.0.022.0.0
typescript3.9.93.9.104.3.4
vue2.6.122.6.142.6.14
vue-banana-i18n1.3.01.4.01.4.0
vue-template-compiler2.6.122.6.142.6.14

Security Headers
Similar to query.wikidata.org, the toolforge.com test site is missing a handful of desired security headers per this automated report. I understand that the lack of an enforcing CSP and x-frame-options are likely due to various global policies and stalled implementations across all Wikimedia projects, though I'd note there are overriding options for this specific project, if it is to be run as a Nodejs app within production. Risk: Low, given extenuating circumstances.

DoS Vectors (including ReDoS)
I wasn't able to perform any exhaustive performance-testing for this application, but did not see anything within the code that seemed out of the ordinary for Wikimedia typescript/javascript apps that would indicate a cause for concern. Still, as this app is intended to be deployed under wikidata.org at some point, I would recommend a performance review from the Performance-Team prior to deployment (I did not see a Phab task for such a review after a quick search). Risk: None, pending a formal performance review.

Build/Test steps
Currently, the code uses vue-cli-services to build its dist artifacts, which by default uses certain webpack dependencies. Given the complexity and known code quality issues of webpack, this will be categorized as a Medium Risk. I's also note that any webpack-generated dist artifacts should be posted to gerrit for CR with at least one member of the AppSec contingent of the Security-Team (@Reedy, @Mstyles, @sbassett) added to the review.

General Security Issues
I didn't find much here, based upon a cursory, manual review of the /src directory. Some automated scanners (njsscan, semgrep) picked up a few things - uses of v-html and Math.random() (which isn't cryptographically-secure of course), all of which seemed to be false positives, though I've included a raw report of these issues as a protected paste here: P16733. Risk: Low.

Policy Compliance
Just noting for completeness' sake that the privacy policy referenced under the query-builder-test.toolforge.org test site will need to be updated to a valid Wikimedia privacy policy when the tool is eventually hosted under query.wikidata.org. This has a current risk of None.

sbassett moved this task from In Progress to Waiting on the user-sbassett board.

Created T285761: Add proper security headers to Query Builder for headers.

Does T276366: Wikidata Query Builder: replace vue-cli with vite and webpack with rollup mitigate the medium security risk in packaging? If so, we can prioritize it.

Regarding performance review, I want to mention this will be on wikidata.org but a separate, statically served site (basically something like https://security.wikimedia.org/) and won't have any interaction with mediawiki (beside being in the same high level DNS domain). Do we still need to get performance review for it?

Sounds good. The defaults for service-template-node would likely be a good baseline to model.

Does T276366: Wikidata Query Builder: replace vue-cli with vite and webpack with rollup mitigate the medium security risk in packaging? If so, we can prioritize it.

Yes! I believe rollup has become somewhat agreed-upon as a less risky alternative to webpack.

Regarding performance review, I want to mention this will be on wikidata.org but a separate, statically served site (basically something like https://security.wikimedia.org/) and won't have any interaction with mediawiki (beside being in the same high level DNS domain). Do we still need to get performance review for it?

Ok, I just meant that it's something that would be hosted under a production TLD, as stated: "We intend to deploy it as a subpage of the existing Wikidata Query Service at query.wikidata.org". A perf review is never required for any production deployment, AIUI, but is strongly recommended in many cases. Again, I'd recommend asking the Performance-Team if they feel it would be a good idea to perform such a review for this codebase, largely as a way to surface any potential DoS-related issues.

We migrated to vite/rollup and here is the build patch for review: https://gerrit.wikimedia.org/r/c/wikidata/query-builder/deploy/+/708629

I'm about to create a performance review ticket now.

We migrated to vite/rollup and here is the build patch for review: https://gerrit.wikimedia.org/r/c/wikidata/query-builder/deploy/+/708629

I'm about to create a performance review ticket now.

This is done. And given that we now migrated to vite/rollup, does that improve the security risk? If so, can this be reflated somewhere? :D

This is done. And given that we now migrated to vite/rollup, does that improve the security risk? If so, can this be reflated somewhere? :D

That is the hope, yes, though both of those are still technically in security review this quarter (T284341, T284338)

Just to record it, as checked just now, with the current HEAD of the master branch, npm audit finds 0 vulnerabilities.

image.png (111×578 px, 10 KB)

/me is really happy that we have made the migration to vite/rollup :)

Just to record it, as checked just now, with the current HEAD of the master branch, npm audit finds 0 vulnerabilities.

I arrived at the same result. Given that webpack/dev npm dependecies were the most substantial risks found during my security audit, I am now fine assigning an overall low risk for Wikidata Query Builder, which is automatically accepted.

sbassett moved this task from Waiting to Our Part Is Done on the secscrum board.
sbassett moved this task from Waiting to Done on the user-sbassett board.