Security design¶
← README · Architecture · Roadmap · Releases
What Paperless Unified Search protects, what it trusts and which risks remain. SECURITY.md says how to report a vulnerability and how to verify a release, and argues why the repository and its releases are safe.
What you can expect¶
- Only administrators of Nextcloud can see and change the settings of the app. Users change only their own choices of Always search my Paperless documents and Notify me about new documents in their personal settings, and only while the administrators let them. Every request passes Nextcloud's login and its CSRF check, and saving and Disconnect ask for the password when it wasn't confirmed in the last 30 minutes.
- The Paperless API token is stored in Nextcloud's credentials manager and goes only to the Paperless server it was saved for: no response, page or message of the app contains it, and a URL with another scheme, host or port needs the token entered again (decision 0003).
occ paperless_unified_search:setuptakes the token only from its standard input or from an environment variable, never from an argument, which the history of the shell and the list of processes would show to other users of the server; no output of occ contains it.- The API token of a superuser of Paperless, which Create the search account and save and
occ paperless_unified_search:setup --create-accounttake to set up the read-only search account, serves these requests alone: it is never stored, logged, answered or part of a message, its requests go only to the Paperless URL of the form and follow no redirect, and each change in Paperless only adds the search account to permissions (decision 0012). - A stored token that can't be decrypted, as after a move of Nextcloud with another secret in
config.php, counts as none: the settings ask for it again, and the search shows no Paperless documents instead of failing. - Nextcloud's protection against addresses of the local network stays on. Paperless runs in my local network lifts it only for the requests of this app to the Paperless URL of the settings, which then follow no redirect, never for another app or another address, and only an administrator who confirmed the password can select it (decision 0004).
- A Paperless document appears in the results of a user only when that user can open a file of the archive account, or, with Paperless Sync's ownership Each user, those they own in Paperless (
per-user) or Each user, those they own or may view in Paperless (per-user-shared), of the user of Nextcloud whom its rules give the document's owner in Paperless; the copies ofper-user-sharedfor the users who may only view a document stand for nothing (decision 0013) whose name carries its marker[P<ID>]: their own if they are that account or that user, or one that the account or the user shared with them, which counts only while they may only read it. A file that only carries the marker in its name stands for no document. Selecting the result opens that file in Nextcloud. - A user whom Paperless Sync lets see only the documents with some tags, by a line of its setting Tags that a user may see (the lazy value
user_tagsofpaperless_sync), meets only the documents whose tags in Paperless hold one of theirs: in the search and the smart picker, on the dashboard, in the notifications and in Try a search. The search asks Paperless for those documents alone and checks the fieldtagsof every document that comes back, so neither a share of the archive that shows the user more nor a file of theirs renamed after another document shows them anything else. Their own copies, which Paperless Sync writes while the archive account is its target user, stand for the documents with their tags alone, and a file of an owner with tags stands for nobody's search for a document without one of them. While Paperless lists none of their tags, or doesn't send its tags, such a user meets no document (decision 0015). - A search for the documents similar to one, such as
like:[P412], answers only a user who may see that document by the same rule as a result: a file of it that the user can open, and, for a user with tags, one of their tags. Documents similar to one tell something about its content, such as that a hidden document is most like the user's payslips, so for anyone else the search finds nothing and asks Paperless for no similar documents. This check covers the search and the smart picker; a saved searchlike:<ID>of Notify me about new documents,occ paperless_unified_search:searchand Try a search don't make it yet. - Search terms reach Paperless only when the user switches on Search connected services, picks Paperless documents in the smart picker, chose Always search my Paperless documents in the personal settings, saved them for Notify me about new documents there, when an administrator has marked Paperless as trusted, or when a client of the user, such as a script, asks for this search by its ID through Nextcloud's OCS search API. They travel from server to server, never from the browser to Paperless.
- In the smart picker of Talk, Text, Deck and Mail, a term reaches Paperless only after the user chose Paperless documents in it, a choice as explicit as switching on Search connected services. The picker searches through the same search provider, with the same rules of who sees which document.
- The link that the smart picker inserts is the link of the synchronized file in Nextcloud, and the app resolves no link itself: Nextcloud renders it with the permissions of whoever reads it, as the preview of the file for a reader who can open it and as the bare link for anyone else.
- The app asks Paperless only for the fields that a result shows: the ID, the title, the date, the correspondent, the type, the tags and the owner of a document, and the excerpt around the term, and for the names of the correspondents, the types and the tags of the documents that the user can open. With Paperless Sync's ownership
per-userorper-user-shared, it also reads the list of the users of Paperless (/api/users/), of which it keeps only each ID and username. The whole OCR text, the notes and the permissions of the documents never reach Nextcloud. - Nextcloud's distributed cache keeps the names of correspondents, types and tags for ten minutes, by the server, the token and the ID, for all users, as they come with the token of the app, and with
per-userorper-user-sharedthe IDs and usernames of the users of Paperless for ten minutes as well, by the server and the token, until a save of the settings orocc paperless_unified_search:checkasks for them anew; a result shows a name only for a document whose file the user can open. - The dashboard widget New in Paperless follows the rule of the search: it shows a user only the newest documents whose file the user can open, of the archive account or, with
per-userorper-user-shared, of the owner's user. Nextcloud's distributed cache keeps up to the newest 100 documents, a page of 25 each, and the newest 25 of a user of Paperless for a minute for all users, as they come with the token of the app, with their IDs, titles, owners, the moments that Paperless added them and the IDs of their correspondents, types and tags, never their text. - The notifications about new documents follow the rule of the search as well: a user hears about a document, and gets its title and a link to its file, only when the user can open its file, of the archive account or, with
per-userorper-user-shared, of the owner's user, as the notification goes out. Whoever saved the same search and can't open the file hears nothing (decision 0011). - The saved searches of a user are stored with their account, up to 10 of up to 500 characters each, only while the user asks for them, and Nextcloud deletes them with the account. A background job sends them to Paperless, with the token of the app, which the personal settings say above the field: saving them is the consent of the user. Saving also sends each new one to Paperless once, for a page of one document with its ID alone, to check that Paperless can read it; the answer says only whether it can, never what or how much the search finds, and a search for the documents similar to one is saved without asking whether Paperless has that document. They reach neither the log, which names only the users whose searches Paperless refused, nor the history of the problems of the search, and nobody but the user and the administrators of Nextcloud can read them, the latter with
occ user:setting. - Requests to Paperless go through Nextcloud's HTTP client, which checks TLS certificates.
- Try a search in the settings shows an administrator which Paperless documents a user finds for a term and why the others don't show to them, by their IDs, titles and tags alone: no content, no excerpt, no file and no account that owns one. Like every route of the settings, only administrators can call it, and the audit log of the app Auditing / Logging (
admin_audit) records which administrator tried a search as which user, whatever the log level, as does the log of Nextcloud at level info, without the term. - A failed search is logged with the kind of error only, without the term, the URL or the token. The history of the administration settings shows it with its message as well, as it shows a request that only its second try answered; the message loses the token, the term in any case, also of letters beyond ASCII such as
Äandä, and the query of every URL first. - What a user types can't fill the history of the problems of the search: a query or a page that Paperless refuses, as one still being typed, finds nothing and writes nothing, and the problems of one kind write the history at most once in 30 seconds (decision 0006).
What is protected¶
| Asset | Where it lives | Protection |
|---|---|---|
| The Paperless API token | Nextcloud's credentials manager | Stored only there; the settings carry only whether a token is configured; saving without a new token keeps the stored one, but only for the server it was saved for |
| The search terms of the users | Sent to Paperless | Only when the user asks for it, in the search or through the API, or an administrator trusts Paperless; never logged by the app; removed from the messages of the history of the diagnostics, as is the query of every URL |
| Documents in Paperless | Paperless | Read through a dedicated account with read access only, which every test of the connection checks: the settings, occ and the overview warn about the token of a superuser or an admin, or of an account that may add, change or delete documents, or add or change users or change groups, which lets it grant itself that; shown only through a file that the user can read, of the archive account or, with Paperless Sync's ownership per-user or per-user-shared, of the user whom its rules give the document's owner; Try a search shows administrators the IDs, titles and tags of the documents that a user finds, nothing more, and logs who looked as whom |
| The configuration | Nextcloud's app configuration | Changed only by administrators who confirmed their password in the last 30 minutes, after a test of the connection |
| The services of the local network | Behind the firewall of Nextcloud | Nextcloud refuses their addresses to every request; the app asks for an exception only for the Paperless URL of the settings, when an administrator selected Paperless runs in my local network, and follows no redirect then |
Trust boundaries¶
- Browser → app. The routes of the settings page pass Nextcloud's login, its CSRF check and the check of the administrator, and saving and Disconnect its password confirmation. The URL must use
httporhttps, name a host, an IPv4 address or an IPv6 address in brackets, and carry no credentials, query or fragment; an internationalized name is stored in punycode. A blank token keeps the stored one only for a URL with the scheme, host and port of the stored URL; the archive account must exist and is stored as Nextcloud spells its ID. - Nextcloud's search → app. The term and the cursor of a page come from the user, through the unified search or the smart picker: the cursor must be one that the app handed out for the same user and question, sealed with a key of the instance, and any other finds nothing (decision 0016); a search pages through the first 10,000 hits; a page holds at most 50 results, and one search asks Paperless for at most 4 pages of 25 hits, or 20 while it has found no result yet (decision 0017).
- App → Paperless. Nextcloud's HTTP client refuses addresses of the local network unless Paperless runs in my local network is selected; then the request reaches the Paperless URL of the settings and follows no redirect. The request names the fields of the documents to send, so that the OCR text stays in Paperless. Every answer is untrusted input. It must be JSON with a list of results; a document without a numeric ID is left out; titles, dates and the names of correspondents, types and tags are used only when they are text, and a date is formatted only when it is a day that exists, as is the moment that Paperless added a document; the excerpt loses the tags of Paperless before its entities become characters again, is cut to 180 characters, and, with the rest of the line below the title, gets a space after every
<that would start a tag, so that this line holds no HTML tag whatever the document says. The answer of/api/ui_settings/decides only the warnings about the account of the token: one other than HTTP 200 with JSON that names the user and its permissions leaves them unknown, and the test of the connection passes as before. - App → files of Nextcloud. The file locator searches only the folders of the searching user, with Nextcloud's permissions, and takes only files, never folders, and only those that the archive account owns, with the exact marker of a document in their name, or, when Paperless Sync gives each user the documents that they own, those of the user whom it gives the owner of the document in Paperless. The marker in a name is chosen by whoever names the file and proves nothing by itself; the files of the archive account and of each owner reach other users only through their shares. The owner of a document and the usernames of Paperless are untrusted answers as well: only a whole number names an owner, and only a user with a number and a text names a username.
Threats and countermeasures¶
| Threat | Countermeasure | Evidence |
|---|---|---|
| Another site uses the session of an administrator | Nextcloud checks the CSRF token of every request; no route of the administration settings opts out of it or of the check of the administrator | testNoSettingsActionOptsOutOfTheChecksOfNextcloud in tests/Unit/Controller/SettingsControllerRoutesTest.php |
| Another site or another user turns on Always search my Paperless documents for a user, so that every search term of theirs goes to Paperless | The route of the personal settings keeps Nextcloud's login and CSRF checks and opts out only of the check of the administrator; it stores the choice of the signed-in user alone, never of another one, and refuses it with 403 while the administrators don't let users choose | testTheRouteOptsOutOfNoOtherCheckOfNextcloud and testTheRouteStoresTheChoiceOfTheSignedInUser in tests/Unit/Controller/PersonalSettingsControllerRoutesTest.php, testTheChoiceIsRefusedWhileUsersMayNotChoose in tests/Unit/Controller/PersonalSettingsControllerTest.php, and the end-to-end tests, which expect 401 without a login and 403 while users may not choose |
| A user learns through notifications what a document holds that they may not open, by saving searches for its words | A notification goes out only for a document whose file of the archive account the user can open, read-only, at that moment, as in the search; for any other, the saved search of the user makes no difference | NewDocumentAlertsTest, tests/e2e/run.sh |
| Another site or another user changes the saved searches of a user | The route keeps Nextcloud's login and CSRF checks and stores only the choice of the user who signed in, within 10 searches of 500 characters | PersonalSettingsControllerRoutesTest, PersonalSettingsControllerTest |
| A route loses the check of the administrator or of the CSRF token | A test fails as soon as the controller or a route of it opts out of a check of Nextcloud, by an attribute such as NoAdminRequired, PublicPage or NoCSRFRequired or by an annotation; the end-to-end tests send every request of the settings as a user who isn't an administrator and without a login, and expect 403 and 401 with the settings unchanged |
testNoSettingsActionOptsOutOfTheChecksOfNextcloud, testEveryActionOfTheControllerIsARouteOfThisTest, tests/e2e/run.sh |
| An administrator, or whoever takes over their session, learns more of the documents of a user than Try a search should show | Only administrators can call the route, which passes the CSRF check; its answer names each document by its ID, its title, its tags and its verdict alone, never its content, an excerpt, the path of a file or the account that owns one; the audit log of admin_audit, whatever the log level, and the log of Nextcloud at level info record which administrator tried a search as which user, without the term |
testTheAnswerHoldsTheIdsAndTitlesOnly, testLogsWhoTriedASearchAsWhomWithoutTheTerm and testTellsTheAuditLogWhoTriedASearchAsWhomWithoutTheTerm in tests/Unit/Controller/TrySearchTest.php, testNoSettingsActionOptsOutOfTheChecksOfNextcloud, and the end-to-end tests, which expect 403 for a user who isn't an administrator and 401 without a login, and an answer of IDs, titles, tags and verdicts alone |
| An administrator session points the URL at another server to collect the token | A blank token keeps the stored one only for the same scheme, host and port; for another server, saving stops before any request leaves Nextcloud and asks for the token. Saving asks for the password when it wasn't confirmed in the last 30 minutes | testABlankTokenNeverSendsTheStoredOneToAnotherServer in tests/Unit/Service/ConfigServiceTest.php, testSaveWithoutATokenNeverSendsTheStoredOneToAnotherServer in tests/Unit/Controller/SettingsControllerTest.php, testChangingTheConnectionAsksForThePassword, and the refused save of the end-to-end tests, which no request of the mock follows |
| An administrator session points the app at a service inside the network (server-side request forgery) | Nextcloud refuses addresses of the local network to every request unless Paperless runs in my local network is selected, and then only to the requests of this app to the Paperless URL of the settings, which follow no redirect; allow_local_remote_servers stays off. The stored token goes only to the server it was saved for, so a host inside the network receives it only when it is entered again, and saving asks for the password |
testSaveAllowsTheLocalNetworkForThisPaperlessOnlyWhenAsked and testSaveNamesTheSwitchWhenNextcloudRefusesALocalAddress in tests/Unit/Controller/SettingsControllerTest.php, testSearchAllowsTheLocalNetworkAsTheSettingsSay, and the end-to-end tests, which run without allow_local_remote_servers and expect a save without the switch to fail before any request reaches the mock |
| A token that can't be decrypted takes down the settings or the search | The token counts as none, one warning without it goes to the log, and the settings ask for it again | testATokenThatCannotBeDecryptedCountsAsNoneAndIsLoggedOnce, testTheFormAsksForTheTokenAgainWhenTheStoredOneCannotBeDecrypted, testAStoredTokenThatCannotBeDecryptedShowsNoDocumentsInsteadOfFailing |
| The API token leaks through the command line of occ | setup has no argument or option that takes the token: it reads the token from the standard input or from an environment variable, and its messages leave it out, also the error that -v shows |
testTakesTheTokenFromNoArgument and testShowsTheErrorWithoutTheTokenWhenAskedTo in tests/Unit/Command/SetupTest.php, and the end-to-end tests, which set the app up through occ and find the token in none of its output |
| The token of a superuser, entered to create the search account, stays in Nextcloud or takes more than the set-up | PHP leaves the parameter out of stack traces, no answer, message, log or setting holds it, even where an error of a request repeats it, and the settings keep only the token of the new account, which may only view; the requests follow no redirect and allow the local network only as the form does; nothing changes in Paperless while the URL or the archive account is invalid, a token of another account is refused, a user of the name stays as it is, every permission only adds the account, and a set-up that fails halfway removes the user and the workflow again | testTheTokenOfTheSuperuserReachesNoLogNoAnswerAndNoSetting and testSettingsThatCantBeSavedChangeNothingInPaperless in tests/Unit/Controller/CreateAccountTest.php, tests/Unit/Service/SearchAccountSetupTest.php, testNamesWhatFailedAndSavesNothing in tests/Unit/Command/SetupCreateAccountTest.php, and the contract tests against real Paperless-ngx 2.20 and 3.x |
| The API token reaches the browser | The token stays in the credentials manager; the settings carry only whether one is configured | testPublicConfigNeverContainsToken in tests/Unit/Service/ConfigServiceTest.php |
| The token of a superuser, or of an account that may change documents, leaks, as from a backup of Nextcloud, and whoever has it changes or deletes documents in Paperless | Every test of the connection asks /api/ui_settings/ what the account of the token may do, and the settings, occ and the overview warn about a superuser, an admin, every permission to add, change or delete documents and those to add or change users or change groups, which let the account grant itself that, with what to change; the warning never refuses the token, so that no set-up breaks with an update. Paperless says it only to an account that may view its UI settings, as the documentation recommends (decision 0010) |
testTheAnswerOfPaperlessNamesTheWarnings in tests/Unit/Model/TokenWarningTest.php, testSaveNamesTheWarningsAboutTheAccountOfTheToken in tests/Unit/Controller/SettingsControllerTest.php, testWarnsAboutWhatTheAccountOfTheTokenMayDo in tests/Unit/Command/CheckTest.php, the warnings of occ and the overview in the end-to-end tests, and the contract tests against real Paperless-ngx 2.20 and 3.x |
| A malformed or hostile answer of Paperless | The answer is checked for its shape; documents without a usable ID are left out; a failing search returns no results instead of an error | testAWrongAnswerOfPaperlessFails, testDocumentsWithoutAUsableIdAreLeftOut, testAFailedSearchIsLoggedWithoutItsDetails |
| A link of the smart picker shows a document to a reader who may not open its file | The inserted link is the link of the file in Nextcloud; the app resolves no link, and Nextcloud's own provider of file links shows the preview only to a reader who can open the file | testLeavesTheLinkOfAResultToTheProviderOfFileLinks in tests/Unit/Reference/PaperlessReferenceProviderTest.php, and the end-to-end tests, which resolve the link as the archive account, as a user without access and as a user the file was shared with |
| Text of a document runs as script in the search | Paperless escapes the text of a document inside the markup of its excerpt, so <script> becomes <script> once the entities are characters again: the line below the title gets a space after every < before a letter, /, ! or ?, where a tag would start, and holds no tag, also for a client that would draw it as HTML; Nextcloud's search shows titles and that line as text anyway |
testTitleAndSublineComeFromTheDocument and testAMeasuredAnswerOfPaperlessGivesItsSubline in tests/Unit/Search/PaperlessSearchProviderTest.php, with an answer of a real Paperless-ngx 3.3.0 to a document that says <script>alert(1)</script> (tests/Unit/fixtures/), and the search dialog of the end-to-end tests, which shows the tags and entities of an excerpt of Paperless as text |
| The names of correspondents, types or tags fail or slow down the search | The names come with one request per kind, one try within 3 seconds, and none for the other kinds after a request without answer; a failure leaves the names out, writes nothing into the history of the diagnostics, a list that Paperless refuses to the token isn't asked for again for ten minutes, or until a save of the settings, and a list that doesn't answer, as one slower than the timeout, isn't asked for again for a minute, so that the searches of every keystroke don't wait 3 seconds for it each | testALookupOfNamesWithoutAnswerLeavesOutTheNames, testAListThatPaperlessRefusesIsNotAskedForAgain in tests/Unit/Search/PaperlessSearchProviderTest.php, testAListWithoutAnswerIsNotAskedForAgainForAMinute, testForgettingEndsTheRestOfTheListsAtOnce and the rest of tests/Unit/Service/PaperlessNamesTest.php, testALookupWithoutAnswerGetsNoSecondTry in tests/Unit/Service/PaperlessApiServiceTest.php |
| A user names a file with the marker of a document that they may not see | Only files that the archive account owns stand for documents, and users receive them only through its shares; without an archive account the search shows no documents and doesn't ask Paperless. When Paperless Sync gives each user the documents that they own, a file of a user counts too, but only for the documents whose owner in Paperless the rules of Paperless Sync give that user, so a file renamed after a document of another owner, or of none, counts for nothing (decision 0013) | testAUsersOwnFileStandsOnlyForTheDocumentsOfTheirOwner and testTheFileOfAnOwnerCountsForOthersOnlyWhenTheyMayOnlyReadIt in tests/Unit/Service/NextcloudFileLocatorTest.php, testFindsTheOwnFilesOfTheUserOfTheOwnerOfEachDocument, testIgnoresFilesThatTheArchiveAccountDoesNotOwn, testAFileOfAnotherAccountShowsNoDocument, testWithoutAnArchiveAccountPaperlessIsNotAsked, and the forged file of the end-to-end tests |
| A user whom Paperless Sync lets see only the documents with some tags reaches others, through a share of the archive made by hand, a file of theirs renamed after another document, or a filter that Paperless ignores | The tags of Paperless decide, not a file: the search, the dashboard, the notifications and Try a search check the tags that Paperless sends with each document against the line of the user, after asking Paperless with tags__id__in; the names become IDs from /api/tags/, and without them the user meets no document (decision 0015) |
testAUserWithTagsFindsOnlyTheDocumentsWithOneOfThem in tests/Unit/Search/PaperlessSearchProviderTest.php, testAUserWithTagsSeesOnlyTheDocumentsWithOneOfThem and testATagThatPaperlessDoesNotHaveShowsNoDocument in tests/Unit/Service/UserTagsTest.php, testTheFilesOfAnOwnerWithTagsStandOnlyForTheirDocumentsWithOneOfThem in tests/Unit/Service/DocumentOwnersTest.php, testAUserWithTagsGetsTheNewestDocumentsWithOneOfThem, testAUserWithTagsHearsOnlyAboutTheDocumentsWithOneOfThem, testNamesTheDocumentsWithoutTheTagsOfAUserWithTags, and the user with a tag of the end-to-end tests |
A user learns something about a document that they may not see by searching for the documents similar to it with like:<ID> |
Before it asks Paperless for similar documents, the search asks for the document of the term with its owner and tags and looks for its file among those of the user, as for a hit; without one, or outside the tags of a user with tags, it finds nothing and writes nothing into the history of the problems of the search | testASearchForDocumentsLikeOneWithoutAFileFindsNothing, testAUserWithTagsFindsDocumentsLikeOneOnlyWithOneOfTheirTags and testAFailedLookupOfTheFileOfTheSourceFailsTheSearchAsSuch in tests/Unit/Search/PaperlessSearchProviderTest.php, and the end-to-end tests, in which e2e-other finds nothing for like:[P610], whose file the archive account keeps to itself |
| A user who may write into a folder of the archive account, through a share with write permission, gives a file there the marker of a document that they may not see | For a user other than the archive account, a file counts only when the user may neither change it nor add files to its folder of the archive account, as the permissions of Nextcloud for that user say, and a file that the user may write through one share counts through none, also not through another share that reaches it read-only. A file shared on its own counts by the name that the archive account gave it, not by the name of the share, which every recipient may change; the settings, occ paperless_unified_search:check and the overview list the shares of the archive and warn about each that allows changes (decision 0009) |
testAFileThatTheUserMayWriteStandsForNoDocument, testAFileThatTheUserMayOnlyReadStandsForItsDocument, testAFileThatTheUserMayWriteThroughAnotherShareStandsForNoDocument, testAFileSharedOnItsOwnCountsByTheNameThatTheArchiveGaveIt in tests/Unit/Service/NextcloudFileLocatorTest.php, testWarnsOfEachShareThatAllowsChanges in tests/Unit/Service/ArchiveSharesTest.php, and the end-to-end tests, in which e2e-writer names a file of a share with write permission, inside a folder shared with it read-only, after document 999, finds nothing, and occ and the overview warn about the share |
| A user of Paperless with a name like that of another user of Nextcloud, or two users of Paperless for one user of Nextcloud, make the files of the wrong user count | The search follows the rules of Paperless Sync and guesses nothing: the table of Paperless Sync, or else only the user of Nextcloud with the same ID, whatever its case, only in its group, and nobody for a user of Nextcloud whom two users of Paperless claim, by their names or by the table. A list of users that Paperless refuses or doesn't answer leaves the files of the archive account alone | tests/Unit/Service/DocumentOwnersTest.php, and the end-to-end tests, in which e2e-writer finds its own file of its document 999 with Paperless Sync's per-user mode, and e2e-other's file renamed after it counts for nobody |
| A slow Paperless blocks the search | A connection timeout of 3 seconds and a timeout of 10 seconds for every request, a second try only for a request that failed within 3.5 seconds, before it had a connection, and never for one that waited for a Paperless that hangs, for an address that Nextcloud refuses or for an answer of Paperless, and no further page of Paperless once a search has taken 3 seconds (decision 0006) | lib/Service/PaperlessApiService.php, testARequestThatFailsWithinTheTimeToConnectGetsASecondTry, testARequestThatFailsAfterTheTimeToConnectGetsNoSecondTry, testAnAddressThatNextcloudRefusesGetsNoSecondTry, testAnAnswerOfPaperlessGetsNoSecondTry, testASlowPaperlessIsAskedForNoFurtherPageAfterThreeSeconds |
| An outage of Paperless, or a Paperless that hangs, uses up the PHP workers of Nextcloud, since every search after a pause of typing waits for it, also every search of Nextcloud while Paperless is in every search | After a request without answer, a timeout, a refused or failed connection or a name that doesn't resolve, the searches of every user rest for 30 seconds: they find nothing without asking Paperless, by a mark for the URL of Paperless in Nextcloud's distributed cache. An answer of Paperless, whatever its status, a failure without a wait, as of the certificate, and a failure of the files start no rest, a test of the connection that Paperless answers ends it, and a cache that fails keeps none (decision 0018) | lib/Service/SearchRest.php, testASearchWithoutAnswerRestsTheSearchesForThirtySeconds, testAFailureThatCostsNoWaitMakesNoRest, testAFailureOfTheFilesMakesNoRest and testARestingSearchAsksNothingAndSaysSoInTheDebugLog in tests/Unit/Search/PaperlessSearchProviderTest.php, tests/Unit/Service/SearchRestTest.php, testATestOfTheConnectionThatPaperlessAnswersEndsTheRestOfTheSearch in tests/Unit/Service/PaperlessApiServiceTest.php |
| A user fills the history of the diagnostics with false failures, to push real problems out of it, or makes Nextcloud write its configuration on every request | A query that Paperless refuses with HTTP 400 for its field query, such as an advanced query still being typed or one longer than 4096 characters, and a page past the last one with HTTP 404 find nothing and leave the history untouched; the problems of one kind write it at most once in 30 seconds and only count in Nextcloud's distributed cache in between |
testASearchThatPaperlessRejectsLeavesTheHistoryUntouched, testAnswersThatFailStillGoIntoTheHistory in tests/Unit/Search/PaperlessSearchProviderTest.php, testFailuresWithinThirtySecondsWriteTheHistoryOnce and testAPaperlessThatFailsEveryOtherRequestWritesOnceInThirtySeconds in tests/Unit/Service/SearchDiagnosticsTest.php, and the end-to-end tests, which search with an unfinished query and with a cursor that the app didn't hand out, which asks Paperless nothing, before they count exactly the one failure and the one retry that they caused; testASearchThatPaperlessRejectsLeavesTheHistoryUntouched covers the page past the last one with HTTP 404 |
| A search on Paperless 2 lists every document | The simple mode of the search, the parameter text, goes only to Paperless 3 or later, as the headers X-Version and X-Api-Version of its answer name it; Paperless 2 ignores the parameter and would list all documents |
testOnlyPaperless3GetsTheTermInItsSimpleMode, testOnlyPaperless3AndLaterSearchInASimpleMode |
| A user makes Paperless and the file cache work through every hit | One search asks Paperless for at most 4 pages of 25 hits, or 20 while it has found no result yet, each with one search of the file cache, and none after 3 seconds; a cursor past the first 10,000 hits asks nothing | testASearchAsksPaperlessForAtMostTwentyPages, testASearchThatSpendsItsBudgetWithoutAResultForANextPageIsComplete, testACursorPastTheEndAsksPaperlessNothing in tests/Unit/Search/PaperlessSearchProviderTest.php, tests/Unit/Search/PaperlessPagerTest.php |
| A user learns from the answers of the search about documents that they may not open | A page of results is followed by another only for a result that the user may open, and an answer without one is complete, however many documents of others match; the cursor of the next page is encrypted and authenticated with a key of the instance and bound to the user, the term and the date filter, so it can be neither read nor made, and a cursor that the app didn't hand out asks Paperless nothing (decision 0016) | testAnAnswerWithoutResultsTellsNothingOfTheHitsThatTheUserCannotOpen, testHitsThatTheUserCannotOpenMakeNoNextPage, testACursorThatTheAppDidNotHandOutAsksPaperlessNothing, testACursorOfAnotherSearchAsksPaperlessNothing in tests/Unit/Search/PaperlessSearchProviderTest.php, tests/Unit/Search/SearchCursorsTest.php |
| An administrator learns the search terms of the users or the token from the history of the diagnostics | Every stored message loses the token wherever it stands and the term as a word of its own, in any case, also of letters beyond ASCII such as Ä and ä by the simple case folding of Unicode, which leaves STRASSE for straße, and the query and fragment of every URL, and only administrators can open the settings or clear the history |
testAFailureIsRecordedWithoutTheTokenTheTermAndTheQuery in tests/Unit/Service/SearchDiagnosticsTest.php, also for Ärger and ärger, the test of properties testNoTokenAndNoTermAsAWordSurviveInAnyCase in tests/Unit/Service/SearchDiagnosticsPropertiesTest.php on 500 random terms of a fixed seed, testARetryLeavesOutTheTokenAndTheTerm and testARetryOfTheSimpleModeLeavesOutTheTerm in tests/Unit/Service/PaperlessApiServiceTest.php, testAFailedSearchLeavesOutTheTokenAndTheTerm, testARequestThatOnlyItsSecondTryAnswersGoesIntoTheHistory, and the end-to-end tests, which make Paperless fail and break off a connection, and find neither the terms nor the token on the page of the settings |
The Docker end-to-end tests run the real search endpoint of every supported Nextcloud version against a mock of the Paperless API, with users who may and may not read a file, a file that only carries the marker, a share of the archive account and one with write permission (tests/e2e/README.md).
Residual risks¶
- A link of the smart picker carries the ID of the file in Nextcloud. A reader who can't open the file sees that number, but neither its name nor its content.
- An administrator can learn with Try a search which document titles a user can see, for any term and any user. The answer holds the titles and tags alone, and the audit log names the administrator and the user, if the app Auditing / Logging is enabled (otherwise only the log of Nextcloud does, at level info or lower); an administrator of Nextcloud can see far more anyway, for example by signing in as the user. A hoster who doesn't want this should not make the operators of an instance its administrators.
- The marker
[P<ID>]ties a file of the archive account to a document, and the search judges the permissions of the searching user. Whoever may write into a folder of the archive account, through a share with write permission or a public link that allows uploads, finds none of the documents in it, also not through another share that reaches the same file read-only, but can still put a file with the marker of any document there for the others who may read that folder, and a file that stays behind once a share is read-only again counts for every reader. So does a file that leaves the folder with write permission for one that its writer may only read: Paperless Sync moves an inbox file that Paperless refuses into its error folder and keeps its name, so a broken upload namedx [P999].pdfcounts as document 999 there for every reader of the base folder, its writer as well. The settings,occ paperless_unified_search:checkand the overview warn about each share that allows changes: share the archive read-only. - With Paperless Sync's ownership
per-userorper-user-shared, its rules (user_map, the same ID ignoring case,user_group) decide whose files stand for whose documents, and the search follows them as they are (decision 0013): a wrong line ofuser_mapmakes the files of a user of Nextcloud count at once for the documents of another owner, as it makes Paperless Sync write them there. The folders of each such user carry the same risk as those of the archive account: whoever may write into one through a share can put a file with the marker of any document of that owner there for its other readers. Check the table of Paperless Sync as carefully as its permissions, and share those folders read-only. - The permission View for Users, which
per-userandper-user-sharedneed, lets the token read the usernames, names and email addresses of all users of Paperless; the app keeps only the IDs and usernames. Without it, the search shows only the files of the archive account, and the settings warn. - The lines of Tags that a user may see name tags of Paperless by their names, which the cache of Nextcloud turns into IDs for ten minutes: after a tag is renamed in Paperless, a user with that tag still meets its documents for up to ten minutes, and then none of them until the line names the new name, which Paperless Sync reports as a tag that Paperless doesn't have. Whoever may change the tags of a document in Paperless decides who of the users with tags meets it in Nextcloud.
- Paperless ranks every document in the reach of the search account that matches a query, also those that the searching user can't open, and a page of results goes through at most 4 pages of 25 hits, or 20 while it has found no result yet, or 3 seconds, of that ranking (decision 0016, decision 0017). Whether a document that the user may open lies within that budget, and how long an answer takes, therefore still depend on the documents of others: with queries of their choice, a user can learn coarse bounds of how many documents that they may not open match, such as more than about 500 in front of one of theirs. The reach of the search account in Paperless, not the shares in Nextcloud, bounds what a user without tags can learn this way; a user with tags meets only the documents with one of their tags. Give the search account only the documents that the users of Nextcloud may know of.
- The permissions of the Paperless account decide which documents the search can find. Use a dedicated account with only the read permissions that the search needs, as the README describes. The test of the connection warns about an account that may do more, but only when the account may view its UI settings, and only as the account was at the time of the test: a permission granted later shows at the next test, such as
occ paperless_unified_search:checkin a scheduled job. - With Always include Paperless in global search on, every search term of every user reaches Paperless. Turn it on only for a Paperless server that you trust as much as Nextcloud.
- Every search term of a user who chose Always search my Paperless documents reaches Paperless, as the hint of the checkbox says; nobody can choose it for another user. Turn off Let users include Paperless in all their searches to keep every term that the switch doesn't send away from Paperless; the search then ignores the stored choices (decision 0008).
- A notification keeps the title and the path of a file that the user could open as it went out. Taking back the share later closes the file, but not what the notification already says, as with a mail about the file. Paperless sees the saved searches of all users under the one account of the token, so its logs can't tell whose search it is, and an administrator of Paperless can read them there. The titles of the documents that wait for their files, at most 200 and also of those that nobody in Nextcloud may open, stay in the app configuration of Nextcloud for up to two days; Disconnect deletes them.
- Creating the search account sends the token of a superuser through Nextcloud once: whoever controls the server of Nextcloud at that moment could read it, as they could read the stored token at any time. Administrators who would rather not can set the account up by hand in Paperless, as A Paperless account for the search in Configure describes.
- An
httpURL is allowed, for a Paperless in a trusted local network; then the token and the search terms travel unencrypted. Usehttpswhenever the connection leaves such a network. - Within 30 minutes of a confirmed password, whoever takes over the session of an administrator can still change the settings, for example to a server of their own with a token of that server, which then receives the search terms. They can't collect the stored token this way. Nextcloud's own settings carry the same risk; sign out of shared browsers.
- With Paperless runs in my local network selected, an administrator, or whoever takes over their session within 30 minutes of a confirmed password, can point the test of the connection at any address and port of the network, with a token of their own, and learn from its result and from how long it takes whether a service listens there, and whether it answers as Paperless does. The request has the path of the Paperless API and follows no redirect; of the answer, the settings show only the kind of failure, such as a host that doesn't resolve, a refused token, a status of HTTP or an answer that isn't the one of Paperless, never its content, and the stored token never goes there. An administrator of Nextcloud can do more than that anyway, for example by installing an app.
- A blank token keeps the stored one for another path of the same server, so an application that the same scheme, host and port serve under another path receives it once an administrator enters that path.