11 Commits
Author SHA1 Message Date
Lauri Ojansivu ed4b8cd648 RouteBleed: remove incomplete route-pattern escaping.
CodeQL alert #434 found that boardExportScope escaped only forward slashes before interpolating an export path into a RegExp. Replace the pattern with an exact route-literal inclusion check, so there is nothing to escape and metacharacters cannot change the match.

Add positive and negative cases with backslashes and regex metacharacters, reject the reported partial-escape shape across tracked JavaScript, and remove a second partial dynamic pattern from release bundle coverage. This was test-only code with no runtime request path, so there is no attributable attempt for Admin Panel Problems.

Thanks to GitHub CodeQL code scanning and xet7 !
2026-08-17 14:50:07 +03:00
Lauri Ojansivu ec9f9e76d8 Use the detailed card layout for board Excel exports. 2026-08-17 03:57:58 +03:00
Lauri Ojansivu 1b0f2075e5 Export complete card fields at every scope. 2026-08-17 03:43:01 +03:00
Lauri Ojansivu 57c806705c Order detailed exports by board hierarchy. 2026-08-17 02:38:04 +03:00
Lauri Ojansivu 4b27f4fc45 Name PDF and Excel exports by their localized scope. 2026-08-17 02:34:38 +03:00
Lauri Ojansivu f6e3144452 Step 4: the PDF draws the shared card document, so both formats have one layout.
"PDF export layout should be like Excel layout", and "export board, swimlane,
list, card to Excel and PDF should have same layout like export card to Excel" -
with markdown rendered and only the fields that have data.

The PDF laid a card out itself: a hundred and sixty lines that had to be kept in
step with the Excel exporter's layout by hand, and were not. The Excel export
drew sections under filled headers with label/value columns; the PDF drew a flat
list of monospaced lines. Both ask models/lib/cardDocument.js for the layout now
and only the drawing differs, so a section added to one is in the other.

WHAT A PAGE MAKES OF THE DOCUMENT, in pdfDocument.js: a section is a filled grey
bar, a meta block is a row of label/value columns with the labels in bold, text
is markdown wrapped and styled, a list keeps its marker, a comment keeps its
date and its author. The bars are real rectangles - drawn outside BT/ET, because
a PDF text object may not contain a path - and the y of each line is known from
its index, so it needs no layout pass.

What is left in the exporter is the MAPPING: Meteor documents, user ids and
dates turned into the plain names and strings the document takes. That is the
only part that knows a Mongo document from a string.

FOUR REGRESSIONS THE EXISTING GUARDS CAUGHT, every one a field that would have
gone missing from the file:

  * requested by / assigned by - a card's own record of who asked for it, and a
    suite exists precisely because they have been lost from an export before;
  * card number, last activity, spent time and overtime;
  * the labels and the dates, which two suites check by name;
  * and every label's English fallback. The document was passing keys without
    one, so a missing translation would have printed "card-due" on the page.
    The words live in one table now, which also stops a PDF saying "Due" where
    a spreadsheet says "Due date".

The guards themselves follow the layout to where it went: they read the exporter
AND the document, because a field is now carried by the pair, and reading only
the exporter would report a field as lost when it had merely moved to where both
formats take it from.

Verified as far as this sandbox allows: the mapping is extracted from the file
and executed against a stand-in exporter (tests/pdfDrawsTheDocument.test.cjs),
the document it builds is checked section by section, and the bytes are checked
to be a PDF whose xref offset points at its table. There is no PDF viewer here,
so how the page LOOKS is still to be checked by eye.

Thanks to Heart1010 and xet7 !

Fixes #6586,
2026-08-16 23:50:10 +03:00
Lauri Ojansivu 58bf9774a2 Exporting a card to PDF produced an HTML file, and checkboxes are square.
THE PDF THAT WAS AN HTML PAGE. Not a broken PDF - WeKan's own page, saved as
`<card>.pdf`. Every export in the interface is a download from an `/api/...`
address, and server/apiMiddleware.js refuses every /api request unless WITH_API
is exactly "true". It refused by answering `301 Location: /`, so the browser
followed it to the front page and the download link's `download="<card>.pdf"`
wrote the HTML it got there to that name. Reproduced against the running
instance: `GET /api/boards/x/exportPDF` -> 301.

Two faults, and either alone is enough:

  * The bundle launchers did not set WITH_API. The snap has defaulted it to true
    for years (snap-src/bin/config) and every docker-compose*.yml in this
    repository sets it, so the bundle was the ONE platform where exporting was
    off by default - which is why it was the one platform where an export came
    back as HTML. start-wekan.sh and start-wekan.bat now default it to true,
    overridable, and say WHY: the name reads like a developer feature, and
    somebody switching it off to harden an instance should know they are turning
    off every export in the interface.

  * The refusal was a redirect. Whatever the setting, "the API is off" must not
    arrive as a page: it is now 403 text/plain saying that exports use the API
    too and naming the variable to set. A 403 with a sentence in it cannot be
    mistaken for the file that was asked for.

CHECKBOXES ARE SQUARE, WHEREVER THEY ARE PUT. The export popup's unchecked box
drew a thin vertical sliver beside a long label and a proper square beside a
short one: the row is a flex container, the box is a flex item, and a flex item
shrinks. That is the THIRD time this shape has broken - settingBody.css already
carries a fix for a 41px min-height that "turns a 13px box into a tall
rectangle", and another for a `height: 100%` that stretched it - so the fix goes
in the rule that DEFINES the checkbox: `flex: none` in forms.css, for all 90 of
them across 19 templates, rather than one more local patch.

The local patch is removed with it. It had set `box-sizing: border-box`, which
would have made the export popup's boxes 13px INCLUDING their border while every
other checkbox in WeKan is 13px plus 2px - a fix for one page that made that
page the odd one out.

The Admin Panel's checkboxes are native inputs STYLED to be the material box,
and a guard already compares the two rules declaration by declaration, so they
take the new declaration too - written the same way, since `flex-shrink: 0` and
`flex: none` mean the same thing and only one of them can be compared.

Audited the rest rather than assuming: every CSS rule in the client that sizes a
checkbox gives it equal width and height, including the two "clean" board themes
that deliberately draw theirs at 24px and 18px. tests/checkboxesAreSquare.test.cjs
pins that invariant for every rule, and tests/exportNeedsTheApi.test.cjs pins
that the launchers turn the API on, that the refusal is never a redirect, and
that the exports really are /api addresses - which is what made the gate their
business in the first place.

Thanks to Heart1010 and xet7 !
2026-08-16 22:27:48 +03:00
Lauri Ojansivu 6053d32271 Export popup: bind the checkbox toggle where nothing can drop the click.
The previous fix was not enough. #6586 comment 5308548585 said "I can't
select/deselect those arrows here"; after moving the handlers onto
exportScopeSelect - the template that actually draws the rows - and rebuilding
BOTH the release and the development bundle, the answer was "clicking a checked
option, like labels, does not uncheck it". So the diagnosis was wrong twice.

What is known, read out of the built bundle rather than assumed:

  * the templates are registered, and their helpers run - the rows render, with
    their labels, so `exportFields` resolves;
  * both event maps are attached: `Template.exportScopeBody.events(dt)` and
    `Template.exportScopeSelect.events(dt)` are both in the shipped code;
  * the handler itself is right - `c0.set(t, !c0.get(t))` on the same
    ReactiveDict the helpers read.

The click simply never arrives. This list is drawn inside FIVE popups - board,
swimlane, list, card, checklist - each rendered by Popup into its own Blaze view
tree, and rather than keep guessing which link in that chain drops the event,
the toggle is now bound where nothing in it can: one native listener on the
document, in the CAPTURE phase.

Capture, because it runs on the way DOWN to the row, so a stopPropagation()
anywhere between the row and the document cannot eat it - that being one of the
few things that could have been eating it. Native rather than jQuery, because a
`window.jQuery` that turned out to be undefined would fail silently, which is
indistinguishable from the bug not being fixed. And ONE binding rather than one
per template: two would toggle twice and cancel out, which is the same "nothing
happens" arriving from the other direction. The template event maps for these
two are removed, so there is exactly one.

The display is unchanged and still reactive: `selection` is what draws the
checkbox, and nothing here touches the DOM by hand.

I could not reproduce this locally - there is no browser in this sandbox and
puppeteer's installer fails in it - so this removes the dependency on the
mechanism that failed rather than proving which link was at fault. The test
pins that there is exactly ONE binding per class, that it is a native capture
listener, and that it does not depend on jQuery being present.

Thanks to Heart1010 and xet7 !
2026-08-16 21:31:39 +03:00
Lauri Ojansivu ea8bd12a9f Export popup: the checkboxes can be changed, and they say what they are.
Two faults in the unified export popup, reported in #6586 comment 5308548585
("with v10.98 we have that unified export dialog, but I can't select/deselect
those arrows here") and confirmed as "clicking a checked option, like labels,
does not uncheck it".

THE LIST COULD NOT BE CHANGED. The two toggle handlers were registered on
exportScopeBody, while the checkboxes they act on are drawn by
exportScopeSelect. Blaze resolves a helper, and delivers an event, against the
template the element is IN - never an enclosing one - so nothing happened when
a row was clicked. adminProblems.js has the same rule written out, learned the
same way, where three panes each needed their own copy of a shared pair. The
toggles are one object now, registered on both templates like the helpers.

AND NO ROW SAID WHETHER IT WAS TICKED. Each drew an unconditional
`i.fa.fa-check` on a `li.active`, which is popup.css's OTHER convention: that
tick is hidden and shown only for an active row by
`.pop-over-list .pop-over-list.checkable .fa-check` - a selector needing a
NESTED list carrying `checkable`, and this list was neither. So the tick was
never hidden and `active` was never styled: every row looked ticked whatever it
was. Each row now carries `.materialCheckBox`, the checkbox Admin Panel /
Settings / Announcement uses, which needs no ancestor to be right - and the box
aligns with the FIRST line of a label that wraps, which several of them do in
any language with compound words.

WHAT IS TICKED IS WHAT THE FILE CONTAINS, checked rather than assumed: every
format entry with a path builds its URL through exportUrl, which always appends
`fields=<the ticked ones>`, and every route that serves one parses it through
parseExportFields - the JSON, .zip and Kanboard exports, Excel, PDF, the CSV
(where the selection lands on columns), and the ten external-tool exports, which
share one handler. A test reads the format table and fails if a format is
offered that no route serves.

Both new guards were verified to fail on the real faults: removing the
exportScopeSelect registration reports "must have the toggle handlers, or the
list cannot be changed", and putting the old markup back reports "card details
must draw a materialCheckBox that reflects its state".

Thanks to Heart1010 and xet7 !
2026-08-16 20:57:12 +03:00
Lauri Ojansivu b0ca226099 JSON and .zip export at every menu, streamed, from the one export popup.
Continues #1173. The board's Export menu had JSON; nothing else did, and
there was no .zip anywhere. Both are now offered wherever an export is - the
board, a swimlane, a list, a card and a checklist - from the same popup,
with the same checkboxes deciding what goes in.

They are the same export in two shapes rather than two exports. The document
is written by models/exporter.js' streaming writer either way, so a .zip's
wekan.json and a .json download of the same scope are the same bytes. What
differs is where the attachments are: base64 inside the document for JSON,
or beside it under attachments/ as the files they are for the .zip. The
"without attachments" option is now offered at every menu instead of only on
the board's.

Both halves stream. The JSON writer already wrote a document at a time from
raw cursors with backpressure; ExporterZip gives it a PassThrough that
archiver compresses as it fills, and pipes every attachment from the file
store rather than reading it into a Buffer. A board with a gigabyte of
attachments costs a gigabyte of disk reads and not a gigabyte of RAM, which
is what makes the .zip the shape to use when the JSON is too large to hold
as one string.

A scoped export is the same wekan-board-1.0.0 document with fewer rows in
it, plus the lists and swimlanes its cards refer to, so what comes out can
be imported back into somewhere. A section the popup did not tick is an
empty array rather than a missing key, for the same reason. A checklist
scope exports the card that holds it, because a checklist alone has nowhere
to land, and a swimlane export carries no board-wide rules.

Less duplication, which is the other half of this:

- every export route - JSON, .zip, PDF, Excel - reads the scope through one
  parseExportScope() and the selection through one parseExportFields(),
  instead of each picking ids out of the query itself;
- the CARD export popup IS the shared body now, with the card as its scope.
  It was its own template with its own field list, its own ReactiveDict and
  its own url builder, which is how its checkboxes came to drive the Excel
  download and not the PDF;
- one url builder serves every format and every scope, and knows that a card
  has export routes of its own so there are not two ways to ask for one
  card's PDF.

tests/boardExportScope.test.cjs gains the JSON/.zip shape, the scoped
document and the single scope parser. Two guards moved rather than being
deleted: they pinned the routes parsing their own ids and the card popup
holding its own copy of the field list.

Thanks to xet7 !
2026-08-14 00:52:48 +03:00
Lauri Ojansivu bd009cf601 Export a board, a swimlane or a list, in the card export's own layout,
with a popup for what to include.

#1173 "Add Feature: Print Board with Params" has been open since 2017, and
two things were missing.

There was no CHOICE of what to print. The board's Excel and PDF exports took
everything they knew how to render and nothing else, while the card export
already had a popup with a checkbox per section. And they did not LOOK like
the card export: the board's Excel export was a spreadsheet table, one row
per card and eighteen columns, which is a data dump rather than a printed
board.

Both now render a board as its own header followed by every card as the CARD
export's block, drawn by the card export's own code - cardBlockLines() for
the PDF, ExporterExcelCard.renderCardBlock() for the Excel one. A card looks
the same whether it was exported alone or inside its board, and the two
cannot drift into two layouts again. Each card starts on its own page in the
Excel export, because a printed board is read a card at a time.

The swimlane and list menus offer the same export, which is the board export
with one query parameter saying which cards are in scope. They sit beside
"Copy link" rather than under the permission checks, because exporting is
reading, and the file is named for what was exported - a PDF titled with the
board that holds one list is a file nobody can place afterwards.

The selection is one popup body used by all three menus, and one list:
models/lib/exportFields.js, imported by the exporters and by every popup.
The card export's list used to live twice, in the server and in
cardDetails.js under a comment reading "Must match ALL_FIELDS ..." - which
is a comment, not a mechanism, and a section added on one side is either a
checkbox that does nothing or a section nobody can turn off. The same
?fields= now gates the same sections in both formats; the card popup's
checkboxes used to say "fields to include in Excel export" and did nothing
to the PDF.

A card block cannot be streamed - it merges cells, styles them and returns
to earlier rows - and models/server/ExporterExcel.js streams on purpose,
after the in-memory version ate gigabytes on boards with thousands of cards.
That exporter is still there and still reachable: unticking "Card details"
asks for it. A checkbox, not a silent fallback.

A board's per-card data is read once per collection and grouped by card. The
card export's own per-card queries would be fifteen hundred round trips on a
board of three hundred cards.

tests/boardExportScope.test.cjs pins the shared block, the shared list, the
gating, the three menus and the streaming exporter still being reachable.
Two guards moved rather than being deleted: they pinned the board PDF
building its own labels and the server's own copy of the field list, which
is the behaviour that deliberately changed.

Thanks to xet7 !

Fixes #1173,
2026-08-14 00:38:55 +03:00