Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@ version may change things that need attention when updating, and these notes say

## Unreleased

### For visitors

- **Stories, second part.** Published stories are public. `/stories` lists them with a picture and a few words, the start
page shows the first three, and `/stories/{number}` reads one: the curator's texts, and the items of the story as cards with
the curator's captions. An item that visitors may not see (a draft, not yet public, in the bin, withdrawn) is left out
without a trace, and a story with nothing to read (no item visitors may see, no text with words in it) answers "not found" like an unknown page. A record-only item has no picture.
The sitemap lists the stories. A link to a story shows its title and its summary and nothing from an item: no item picture, the archive logo as on every other page.
Stories are not in the feed or in search. The demo archive's story is published.

### For curators

- **Stories, first part.** Under "Stories" in the admin area, curators write a story: a title, a few words of summary, and
parts in order, each a text or one of the items of the archive with a caption. A story can be moved up and down in the
list, and its parts within it, with buttons that work without JavaScript and keep the place on the page. The preview shows
it as visitors will see it: a part with an item that is not public is left out. A story with parts that visitors cannot
see says so on the page, only here. Publishing a story changes nothing for visitors yet; the public pages come in a later
part. Helpers do not see stories.
see says so on the page, only here. Helpers do not see stories.
- **Export format 9** has `stories` after `items`. An export of published items has only published stories and the parts
whose item is in it. An import counts the stories in the dry run and does not import them. The demo archive has a story.

Expand Down
5 changes: 5 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ the request, so behind Caddy they depend on `ASPNETCORE_FORWARDEDHEADERS_ENABLED
tries that setting. Text goes into XML through `XmlText`, because one pasted control character would make a whole feed unreadable.
`ArchiveItem.MayTravel` decides what goes along with a link, and it needs the contribution to be loaded.

Stories (`Pages/Stories`, `Search/StoryCards.cs`): public pages start from `db.VisibleStories` and read parts only through
`VisibleStoryBlocks` (`LoadAsync` for the page, `CoversAsync` for the list). `_StoryBody` is shared with the curator preview and
must stay free of ids, anchors and `data-` attributes; `_ItemCard` is the one item card, also used by `_ItemCards`. The link
preview of a story has no image and no item text, and the sitemap has no `lastmod` for stories.

`Search/PublicItemRecord.cs` is what an item says to programs: `/items/{id}.json` and the `DC.*` tags (`Pages/Shared/_DublinCore.cshtml`,
written by the layout when the page set `ViewData["Record"]`). `PublicItemRecord` is an allow-list: add a field there on purpose,
and never serialise `ArchiveItem` or `MediaFile`. It follows the link-preview rules, so description and files go with `MayTravel`,
Expand Down
4 changes: 2 additions & 2 deletions docs/plan-m29-stories.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ A block whose item is hidden is left out without a trace: no placeholder, no cap

The rule lives in `Data/` only, as it does for M27:

- `Visibility.Story(DateOnly today)` in `Data/Visibility.cs`: published, and at least one text block or one item block whose item
- `Visibility.Story(DateOnly today)` in `Data/Visibility.cs`: published, and at least one text block with words in it (not only white space; a blank text is also left out of the page) or one item block whose item
passes the item rule. The item condition is built from `Visibility.Item`, never a second spelling of `ItemStatus.Published`.
The explicit `DeletedAt == null` is belt and braces on top of the query filter.
- `CommonageDbContext.VisibleStories` and `BinnedStories` (`IgnoreQueryFilters`, `DeletedAt != null`).
Expand Down Expand Up @@ -205,7 +205,7 @@ The `privacy-reviewer` found no design-level leak and asked for these, which are
its other blocks in order.
5. **`/stories` is computed from visible rows only**: total, paging and covers. Covers come from one query, not one per story,
and the page size is capped. Test: `/stories` is byte-identical with and without a hidden story.
6. **Link preview and sitemap.** The preview holds no item text, id or picture; when the summary is empty the description is empty
6. **Link preview and sitemap.** The preview holds no item text, id or picture (the archive logo, as on every other page, may be its image); when the summary is empty the description is empty
(never the first text block). A story cover must never go into `og:image` without a `MayTravel` check (comment in the code).
Story ids are sequential, so a gap is visible, as for items: listed under known limits.
7. **A published-only export is a public copy**, so captions of visible items travel with it; this is intended (the items do too).
Expand Down
8 changes: 7 additions & 1 deletion docs/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ vulnerability, see [SECURITY.md](../SECURITY.md).
| Import | Only curators (the `/Admin` policy). The sheet and ZIP are kept in `import-staging` on the media volume, which is never served by path, for a day at most. A sheet is read as strict UTF-8, at most 20 MB and 100,000 rows; a ZIP at most 4 GB and 200,000 entries; every entry is counted as it is unpacked into a temporary file, and a name inside it is never used in a path. A folder to import from is chosen from a listing of `import/`, links and hidden files are skipped. Files go through the same checks as an upload. One import at a time. Everything imported is a draft; the activity log records each item and the import, never the spreadsheet or the contributors' details. `ImportTests`. |
| Reading an export | Admins only (`Administer`), the dry run is `private, no-store`. Same staging folder, one-at-a-time lock and file checks as the spreadsheet import; the ZIP is at most 4 GB and 200,000 entries, `archive.json` at most 256 MB counted as it is unpacked (a ZIP entry's declared size is not trusted), parsed with a depth limit and capped lists (20,000 items, 5,000 collections, 50,000 tags, 500 files per item, 100,000 files in all), at most 8 GB of files in all, 50 new collections per run and 10,000 recorded lines in the dry run (the rest is counted). A file is taken only under the exact path `files/<item>/<file>-<name>`, unique, never by name and never as a path on disk; its type and size are found from the bytes and its sha256 must match. Unknown values are lines in the dry run, not exceptions. **Decision on consent:** a contributor's name, email address, consent text, rights statement and reference code, visitor notes, internal notes and received-from are never deserialised or stored (`ExportImportTable` decides every property of the export, and `ExportImportTests` fails when the exporter gains one without a decision); only whether the contributor agreed to sharing is read, and an item with a contribution that does not say yes (no, null or no answer at all), or one rejected or withdrawn, is left out. The ZIP is staged in a folder and file only the app's account can read (Linux and macOS), and a file that cannot be stored costs only that file, counted without the error text; the run is not cancelled by closing the tab. Everything arrives as a draft, whatever its status, and the code only inserts (a test reads the source for publishing, removing and unfiltered queries). `ExportImportTests`. |
| Earlier texts | `ItemRevisions` keeps what a title, description, date, credit, original location or reference number said before a change, with the account that changed it (its name at the time) and when. The fields are a fixed list (`RevisionField`): never a contributor's name or email, the internal notes or where an item was received from, so removing a contributor's details never has to touch it. Who changed it is forgotten on the activity log's schedule (`ActivityLogKeptYears`); the text itself stays with the item. Shown on the item's admin page only; a curator may restore, a helper only reads. The rows go with their item (cascade, hidden while it is in the bin) and are not exported. `RevisionTests`, `ExportTests`. |
| Stories | Curators and admins only (`ManageArchive`; a helper gets 403 on every page and handler). A story is text and item parts in a chosen order; part 1 has no public page. What visitors will be able to see is decided in one place: `Visibility.Story` and `VisibleStoryBlocks` (a published story, and only the parts whose item passes `Visibility.Item` with the day; a story with no visible part is as hidden as a draft). The curator pages show hidden items to curators only and say why visitors do not see them. Input is limited on the server (title 200, summary 1,000, text 20,000, caption 1,000 characters, 200 parts per story); an item is added by number or by a page address on this site, never by path. Block handlers are scoped to their story and never save the story row. Accepted: a removed part is deleted at once (the bin covers whole stories, from part 3; the confirmation says so). The export lists stories (`stories`, format 9): a copy of what is public holds published stories with only parts whose item is in the copy, a full copy holds drafts, and the bin is never exported. The import only counts stories (`StoryCountConverter` skips them) and creates nothing. `StoryEditTests`, `VisibilityGuardTests`, `ExportTests`, `ExportImportTests`. |
| Stories | Curators and admins only (`ManageArchive`; a helper gets 403 on every page and handler). A story is text and item parts in a chosen order. What visitors see is decided in one place: `Visibility.Story` and `VisibleStoryBlocks` (a published story, and only the parts whose item passes `Visibility.Item` with the day; a story with no visible part is as hidden as a draft). The curator pages show hidden items to curators only and say why visitors do not see them. Input is limited on the server (title 200, summary 1,000, text 20,000, caption 1,000 characters, 200 parts per story); an item is added by number or by a page address on this site, never by path. Block handlers are scoped to their story and never save the story row. Accepted: a removed part is deleted at once (the bin covers whole stories, from part 3; the confirmation says so). The export lists stories (`stories`, format 9): a copy of what is public holds published stories with only parts whose item is in the copy, a full copy holds drafts, and the bin is never exported. The import only counts stories (`StoryCountConverter` skips them) and creates nothing. `StoryEditTests`, `VisibilityGuardTests`, `ExportTests`, `ExportImportTests`. |
| Stories on the website | `/stories` and `/stories/{id}` start from `VisibleStories` (published, not in the bin, at least one visible part) and show parts only through `VisibleStoryBlocks`, which loads items through `VisibleItems`; a story page never follows a part to its item (`VisibilityGuardTests` reads the source). A draft, a story in the bin, one whose parts are all hidden and an unknown number answer the same 404 (same body and headers, `StoryVisibilityMatrixTests`). A part that is left out leaves nothing behind: no id, position, anchor, `data-` attribute, caption, placeholder, count or "n of m" in the public page (`_StoryBody` has none, and the page equals the page without the part, also with a hidden part between two visible ones). The list, its total, its paging (24 a page) and its covers (two queries for all stories of a page) are computed from visible rows only, so a hidden story changes nothing about them. The cover is a visible item's thumbnail, never of a record-only item. Block changes never save the story row, so there is no "updated" date, no `lastmod` in the sitemap and no `ETag` or `Last-Modified` from block or item data. The start page shows the first three, without a count. `StoryVisibilityMatrixTests`, `EndpointAccessTests`, `AccessibilityTests`. |
| Stories beyond the website | The link preview of a story has its title and its summary and nothing else: no item picture (a cover never goes into `og:image`; an item's rights and consent may not allow it to travel; the archive logo is the preview picture, as on every other page), no item title, id or caption, and no description when the summary is empty (never the first lines of a part). Stories are not in `/feed.xml`, `/search`, the JSON or Dublin Core. The sitemap lists `/stories` and each visible story, without a date, and follows `AllowSearchEngines`. A contributor who did not agree to sharing beyond the website has their item shown in a story on the website like anywhere else, and nothing of it in the preview or the feed. `StoryVisibilityMatrixTests`. |
| Recordings | Only curators can add a recording (MP3, M4A, WAV, FLAC, recognised by their first bytes); contribution links refuse them. Visitors hear only a copy made by the app itself (`AudioTools`, no outside program): the sound is copied byte for byte, and ID3v2/ID3v1/APE tags (MP3), `udta`, `meta`, `uuid` and padding boxes and the dates in the headers (M4A), every chunk except `fmt `, `fact` and `data` (WAV), and every block except stream info and the seek table (FLAC) are left out. A file that is not built as its type says (impossible sizes, missing parts, fragmented M4A) fails and has no copy, so nothing is ever served untouched. The parser is managed code reading sizes against the file's length, with the header of an M4A limited to 64 MB; it runs on the single preview queue and a failure marks only that file. Served for published items only, from `/media/{id}/audio` with range requests, with its own copy (`audio/…` key); the original is only at `/admin/media/{id}/original` for curators. Accepted: the sound itself may contain a voice that identifies someone, which is what an oral history is; curators decide what to publish. `AudioTests`. |
| PDF files | Only curators can add a PDF; contribution links refuse it. A PDF is recognised by `%PDF-` and read by poppler (`pdfinfo`, `pdftoppm`), a large C++ parser, so it runs as separate processes, never inside the app: each call has a time limit (`Uploads:PdfTimeoutSeconds`, 60) and is killed with its children when it takes longer, the size of the drawn picture is set by us with `-scale-to` whatever size the page claims, at most 300 pages are drawn, and no part of the file or its name reaches a command line (arguments are passed as a list, the file is copied to a random name in an owner-only temporary folder that is removed afterwards). Pages are served only for published items; the PDF stays private. Accepted: a hostile PDF made by a curator could still exploit poppler, which runs with the app's rights in the container; build with `WITH_PDF=false` to remove it. `poppler-utils` comes from the distribution at build time and is not pinned to a version, so a rebuild of the same commit can ship another poppler (accepted; the base image digest is pinned). The text of a PDF (`pdftotext`, same limits, control characters removed, at most 200,000 characters) is only matched by search, never shown, and it is in the index only while the item is not in the bin and the PDF is not in the bin; a draft is found only by curators, as before. The preview queue is single, so a very long PDF delays other previews (at most 60 s per page); copies of a PDF left by a stopped app are removed at the next start. |
| Uploads | Files are recognised by their content (magic bytes), never by name or browser type, and stored under random names outside the web root. Originals are never changed or served to visitors. Previews are made by libvips, rotated upright and stripped of all metadata. Images over 250 megapixels get no preview (decompression bombs), also for GIF and AVIF (`Images_with_more_pixels_than_the_limit_get_no_preview`). GIF and AVIF (libheif with an AV1 decoder, from M23) are further decoders reachable from a contribution link; a GIF is read as its first frame only. There is no time limit on a decode, so a very large AVIF costs memory and time on a small server; the pixel limit and the three-attempt guard are the protection. Size limits per file and per request. A file that the preview maker fails on, in whatever way, costs only its own preview, and one that takes the app down is given up after three attempts instead of at every start (`PreviewFailureTests`). |
Expand Down Expand Up @@ -71,6 +73,10 @@ server updated and its access limited is what protects against that.
the same care as the server.
- **The login page reveals whether an account exists** when it has been locked after wrong passwords ("too many
failed attempts").
- **Story texts and captions are the curators' words and are not checked.** A caption or a text can name a hidden item or
person; only the part of a hidden item is left out, never what a curator wrote elsewhere. Story numbers are sequential,
so a gap between two stories can be seen, as for items. The sitemap may list a story that has just been hidden, or lack
one that has just been published, for up to ten minutes.
- **Deleted material stays for 30 days.** Items and photos in the bin keep their files and personal data until they are
deleted for good, which curators can do at once when someone asks for removal.
- **The default privacy text is a template**, describing what Commonage stores. Each group has to adapt it and check its
Expand Down
5 changes: 3 additions & 2 deletions src/Commonage.Web/Data/Visibility.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Text.RegularExpressions;
using System.Linq.Expressions;
using Commonage.Web.Domain;

Expand Down Expand Up @@ -27,13 +28,13 @@ public static Expression<Func<MediaFile, bool>> Media(DateOnly today) =>
&& f.ArchiveItem.MediaLevel == MediaLevel.Everything;

/// <summary>
/// The stories visitors may read: published, not in the bin, and with at least one text block or one item block whose item
/// The stories visitors may read: published, not in the bin, and with at least one text block that has words in it (not only white space) or one item block whose item
/// <see cref="Item"/> allows (so embargo and withdrawal come with it). This is the only place that writes
/// <see cref="StoryStatus.Published"/> in a query. The explicit <c>DeletedAt</c> test is belt and braces on the query filter.
/// A method on the context rather than an expression: it cannot be applied to a navigation from a block to its item.
/// </summary>
public static IQueryable<Story> Story(CommonageDbContext db, DateOnly today) =>
db.Stories.Where(s => s.Status == StoryStatus.Published && s.DeletedAt == null
&& s.Blocks.Any(b => b.Kind == StoryBlockKind.Text
&& s.Blocks.Any(b => (b.Kind == StoryBlockKind.Text && b.Text != null && Regex.IsMatch(b.Text, @"\S"))
|| db.ArchiveItems.Where(Item(today)).Any(i => i.Id == b.ArchiveItemId)));
}
Loading