Skip to content

fix(security): hardening fixes from upstream 9.4 - #546

Open
juliusknorr wants to merge 12 commits into
mainfrom
upstream-9.4/b1-hardening
Open

juliusknorr wants to merge 12 commits into
mainfrom
upstream-9.4/b1-hardening

Conversation

@juliusknorr

Copy link
Copy Markdown
Member

Brings 10 hardening fixes from ONLYOFFICE/core upstream/v9.3.1..upstream/v9.4.0 (upstream commits from 2026-04-21 to 2026-04-28), picked 1:1 with -x. GUIDs and random ids in OOXML output and the CFF writer now come from the OS random source (new OOXML/Base/Rand.h); XLS ActiveX control data, threaded comment userId and temp file names get stricter handling. Two own commits: upstream's header for Rand.h (added upstream after 9.3) and dropping the now unused XmlUtils::Rand() declaration.

Commit Upstream Conflict
fix(ooxml): generate GUIDs and random ids from a CSPRNG d9d7ffef26 no
build(starmath): link CryptoPP into StarMath2OOXML c03fd25b6d no
fix(xls): check ActiveX control position and size separately bd3dd15a4f no
build(cryptopp): disable CryptoPP asm in OFD, DocxFormat and StarMath 99b31a46f7 no
fix(xlsx): escape userId in threaded comment persons 2deb6b8c42 no
fix(pdf): take the CFF random operator value from a CSPRNG 2761614b8d no
fix(common): size the temp file name buffer to the path 5b15d9b77b no
refactor(ooxml): use OS random sources instead of CryptoPP 71a8a22d2e yes, Unit.cpp: took upstream's removal of Rand()/Rand1()
chore(license): add upstream's header to OOXML/Base/Rand.h 76ee07f61c (Rand.h only) no
refactor(pdf): use RandUInt for the CFF random operator dfe6d300d8 no
build(mac): link the Security framework for Rand.h 6a45740f98 no
refactor(ooxml): drop the unused XmlUtils::Rand() declaration ours -

Not picked: 8c2c4060a7 (font thumbnail run limit), already covered by our a045fc5 (#443).

Worth a look:

  • Only the head builds: until build(mac) the picks include upstream's Common/3dParty/cryptopp/osrng.h path, which our layout doesn't have. Skip this range when bisecting; merge with rebase, not squash
  • CFF random operator: (RandUInt() + 1) / (RAND_MAX + 1) gives (0, 2] on Linux/mac instead of (0, 1], same as upstream. The value is not written to the output
  • RandUInt() returns 0 if every random source fails, without an error
  • CRYPTOPP_DISABLE_ASM stays in OFDFile.pro and DocxFormatLib.pro, unused after the switch to Rand.h
  • Unit.h gets our notice for a one-line removal; upstream still declares Rand() in 10.0

Land before the core pin bumps in DocumentServer and DesktopEditors.

Tests: no new tests (no-tests-needed): 1:1 upstream picks, tests come with upstream or not at all. Checked on macOS: touched files compile (-fsyntax-only, _MAC), Rand.h smoke run, 20k GUIDs use 16-bit groups, an 1100-char temp folder no longer overruns the name buffer. Header gate passes on main and on the head. Full builds and ctest in CI.

AI-assisted, see Assisted-by trailer.

ElenaSubbotina and others added 8 commits December 4, 2026 16:39
GenerateGuid and GenerateInt now read from a mutex-guarded CryptoPP
AutoSeededRandomPool instead of rand() seeded with time(). Each GUID
group now takes 16 random bits instead of 8.

Upstream-Subject: fix bug #81148
(cherry picked from commit d9d7ffe)
Signed-off-by: Julius Knorr <jus@bitgrid.net>
Assisted-by: ClaudeCode:claude-opus-5-5
StarMath2OOXML builds Unit.cpp, which now needs CryptoPP.
Follow-up to fix(ooxml): generate GUIDs and random ids from a CSPRNG

Upstream-Subject: Fix build
(cherry picked from commit c03fd25)
Signed-off-by: Julius Knorr <jus@bitgrid.net>
Assisted-by: ClaudeCode:claude-opus-5-5
Compare lPosInCtlStm and cbBufInCtlStm one at a time against the
control stream size before the control data is written, instead of
comparing their sum.

Upstream-Subject: fix bug #81040
(cherry picked from commit bd3dd15)
Signed-off-by: Julius Knorr <jus@bitgrid.net>
Assisted-by: ClaudeCode:claude-opus-5-5
Build the CryptoPP headers without inline assembly in the projects
that compile Unit.cpp.
Follow-up to fix(ooxml): generate GUIDs and random ids from a CSPRNG

Upstream-Subject: fix bug #81216
(cherry picked from commit 99b31a4)
Signed-off-by: Julius Knorr <jus@bitgrid.net>
Assisted-by: ClaudeCode:claude-opus-5-5
Write the person userId attribute XML-escaped, like displayName and
providerId already are.

Upstream-Subject: fix bug #81241
(cherry picked from commit 2deb6b8)
Signed-off-by: Julius Knorr <jus@bitgrid.net>
Assisted-by: ClaudeCode:claude-opus-5-5
FontOTWriter's Type 2 charstring random operator now reads from a
mutex-guarded CryptoPP pool instead of rand().

Upstream-Subject: Fix bug 81148
(cherry picked from commit 2761614)
Signed-off-by: Julius Knorr <jus@bitgrid.net>
Assisted-by: ClaudeCode:claude-opus-5-5
CreateTempFileWithUniqueName lets the UTF-8 converter allocate the
mkstemp template instead of using a fixed MAX_PATH buffer, and returns
an empty string when the name can't be built or GetTempFileNameW fails.

Upstream-Subject: Fix bug 81149
(cherry picked from commit 5b15d9b)
Signed-off-by: Julius Knorr <jus@bitgrid.net>
Assisted-by: ClaudeCode:claude-opus-5-5
Add OOXML/Base/Rand.h with SecureRandomBytes and RandUInt
(BCryptGenRandom or RtlGenRandom, SecRandomCopyBytes, getrandom,
then /dev/urandom and std::random_device). Unit.cpp uses RandUInt and
drops the CryptoPP pool and the old Rand() helper.
Follow-up to fix(ooxml): generate GUIDs and random ids from a CSPRNG
Conflict: OOXML/Base/Unit.cpp: took upstream's removal of Rand() and Rand1() over our nullptr cleanup

Upstream-Subject: Add security rand function
(cherry picked from commit 71a8a22)
Signed-off-by: Julius Knorr <jus@bitgrid.net>
Assisted-by: ClaudeCode:claude-opus-5-5
@juliusknorr juliusknorr added bug Something isn't working format: ooxml format: pdf security Hardening and privacy, report vulnerabilities privately no-tests-needed upstream Also affects ONLYOFFICE upstream, or comes from an upstream change labels Dec 4, 2026
@juliusknorr
juliusknorr marked this pull request as ready for review December 4, 2026 22:35
@juliusknorr
juliusknorr requested a review from a team as a code owner December 4, 2026 22:35
@juliusknorr
juliusknorr requested review from Aiiaiiio, OlhaUshkalenko and chrip and removed request for a team December 4, 2026 22:35
juliusknorr and others added 4 commits December 6, 2026 17:56
Upstream added Rand.h after 9.3, so the licence branch removed it and
the pick above brought it back without a header. Apply the Rand.h hunk
of upstream's header commit.

OOXML/Base/Rand.h only

Upstream-Subject: [copyright] Update copyright header
(cherry picked from commit 76ee07f)
Signed-off-by: Julius Knorr <jus@bitgrid.net>
Assisted-by: ClaudeCode:claude-opus-5-5
Replace the local CryptoPP pool in FontOTWriter with RandUInt from
OOXML/Base/Rand.h.
Follow-up to fix(pdf): take the CFF random operator value from a CSPRNG

Upstream-Subject: Fixes with rand
(cherry picked from commit dfe6d30)
Signed-off-by: Julius Knorr <jus@bitgrid.net>
Assisted-by: ClaudeCode:claude-opus-5-5
Link Security into StarMath2OOXML, PdfFile and x2t on mac and iOS for
SecRandomCopyBytes, drop the CryptoPP link and define from
StarMath2OOXML, and move the Rand.h include and the generators to the
end of Unit.cpp.
Follow-up to refactor(ooxml): use OS random sources instead of CryptoPP

Upstream-Subject: Fix mac|ios build
(cherry picked from commit 6a45740)
Signed-off-by: Julius Knorr <jus@bitgrid.net>
Assisted-by: ClaudeCode:claude-opus-5-5
Unit.cpp no longer defines Rand() and nothing calls it. Unit.h gets
our modification notice.
Follow-up to refactor(ooxml): use OS random sources instead of CryptoPP

Signed-off-by: Julius Knorr <jus@bitgrid.net>
Assisted-by: ClaudeCode:claude-opus-5-5
No-test: removes an unused declaration, the CI build covers it
@juliusknorr
juliusknorr force-pushed the upstream-9.4/b1-hardening branch from 9c50f78 to bb56c6d Compare December 6, 2026 16:56

This branch was successfully deployed

1 active deployment
build-cache — bb56c6d4 Deployed Dec 6, 2026 by juliusknorr via publish / publish #939
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working format: ooxml format: pdf no-tests-needed security Hardening and privacy, report vulnerabilities privately upstream Also affects ONLYOFFICE upstream, or comes from an upstream change

Projects

Status: 📄 To do

Development

Successfully merging this pull request may close these issues.

5 participants