Page MenuHomePhabricator

RfC: Citoid service performance assessment for PDF parsing feature
Open, Stalled, Needs TriagePublic

Description

Citoid service performance assessment for PDF parsing feature

WMDE’s Technical Wishes is currently working on a new feature for the Citoid service. Users should be enabled to add URLs linking to PDF documents to create more meaningful citations. For some more background see the Epic T424982: Investigate feasibility of Citoid supporting PDF sources.

We currently already developed a first MVP version that we would like to deploy to iterate on further. See T427604 and the MVP patch 1301347. Before proceeding, we'd like to get feedback on the approach mainly regarding these topics:

The dependency we’re adding

  • Do you have any concerns about adding the pdf-parse package as additional dependency? We’re using this to extract the metadata from the PDF file. In a 2nd step we might also use it to extract content.

The operational impact

  • We need to load the PDFs into memory to extract its metadata, but want to keep the memory footprint low. So for the start we’ll cap PDF files at 10MB. Do you have any other concerns about the potential increase in server load from downloading and parsing PDFs in memory?

Precautions we’re already implementing

  • For now we’re only reading the property metadata of the PDFs. A second iteration might be to extract content from the first page to increase chances of creating a meaningful citation
  • The MVP currently does stop loading PDFs that are larger than 10MB.
  • The feature is hidden behind a feature flag the API does only allow PDFs when a certain get parameter is used

Conditional deployment plan

  • First deployment to test.wikipedia.org, we'll ask volunteers to test it out. Very low traffic expected. Timeline: October-November 2026
  • Second deployment to 1-2 pilot wikis. We will select 1 mid-sized and 1 large wikis (dewiki) to generate enough data to validate the benefit of the feature. Note that having a PDF handy is contextual and depends on the source being added as a reference, we expect ~ 200 average PDFs per day. Timeline: November-December 2026 (depending on outcome of first step)
  • Third global rollout. Timeline December 2026 - January 2027 (again depending on outcome of previous step)

Please let us know if you need anything else to help with this assessment or if you see any other things we should take into account for the MVP.

Thanks 🙏.

Event Timeline

Added the info that the service only works with pdfs when a specific parameter is passed with the request. This gives some protection that it's not directly exposed when we want to test it in production.

Please see update in the ticket explaining our deployment plan. Thanks!

Given PDFs are arbitrary binary input, we have application and infrastructure level security and reliability concerns that require consideration.
Application-side, we need a security review of the pdf-parse and backing pdfjs-dist libraries. This would also help determine the level of sandboxing necessary to consider a production deployment.
Infrastructure-side, we would want to isolate the PDF handling as much as possible. Ideally this would happen in a separate microservice that only does PDF handling, or at least in a separate citoid deployment, to mitigate potential vulnerabilities and resource exhaustion. Both solutions would also require a stronger sandbox than a standard container.

Given PDFs are arbitrary binary input, we have application and infrastructure level security and reliability concerns that require consideration.
Application-side, we need a security review of the pdf-parse and backing pdfjs-dist libraries. This would also help determine the level of sandboxing necessary to consider a production deployment.
Infrastructure-side, we would want to isolate the PDF handling as much as possible. Ideally this would happen in a separate microservice that only does PDF handling, or at least in a separate citoid deployment, to mitigate potential vulnerabilities and resource exhaustion. Both solutions would also require a stronger sandbox than a standard container.

Thank you very much for that assessment. I just filed a request for a security review of the two dependencies. See T431716: Application Security Review Request : Citoid-Service adding pdf-parse and backing pdfjs-dist NodeJS dependencies. Furthermore we're evaluating an alternative approach T431688: Look into alternatives to parse PDF metadata not using NodeJS, but since that one also is not fully clear we would like to continue with both options.

MLechvien-WMF changed the task status from Open to Stalled.Fri, Sep 4, 12:57 PM
MLechvien-WMF added a subscriber: ppelberg.

Hi, we can have another look at the design once the dependent security review is completed.

The deployment timeline in description should be revised; as this likely needs SRE support we will have to prioritize it against APP works for coming quarter.

cc @ppelberg

Thank you for the update @MLechvien-WMF. I've updated the timelines as requested. The deployment plan itself is the same just, just the dates have been adjusted. We're now aiming to finalis the work and deploy in Q2 (WMF FY). As I understand things, this depends on two pieces of work:

  1. The security review as you mentioned T431716: Application Security Review Request : Citoid-Service adding pdf-parse and backing pdfjs-dist NodeJS dependencies --> Security team
  2. Buildign and deploying the service that processes the PDFs in a secure sandbox environment --> SRE.

For the second item, we're working on defining a secure concept and will create a phabricator task for it soon. What I am unclear about is how we will collaborate on this item with SRE? Any information or guidance would be highly appreciated.

I will also sync with @ppelberg on prioritization and we'll get back to you as soon as possible.

Thanks a bunch!

For the second item, we're working on defining a secure concept and will create a phabricator task for it soon. What I am unclear about is how we will collaborate on this item with SRE? Any information or guidance would be highly appreciated.

There are ongoing works to provide a standard secure sandboxing solution which I'd advise to follow: T435044

Besides that, we can continue discussing the design on this task post security review, but you can read the production expectations in SCROLL process.