From 595e96ffe128d718febe3eef30fc987b6ed2e736 Mon Sep 17 00:00:00 2001 From: "russell@unturf.com" Date: Tue, 31 Mar 2026 20:33:21 -0400 Subject: [PATCH] =?UTF-8?q?openoffice:=202=20defects=20(MOAD-0001=20xestyl?= =?UTF-8?q?e=20O(N=C2=B2)=20border/fill=20dedup,=20MOAD-0004=20WebDAV=20cr?= =?UTF-8?q?edential=20logging);=20scribus:=20MOADs=200002-0005=20CLEAN?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- defects/openoffice-0001/patch/SCAN.md | 40 +++++ .../patch/openoffice-0001.patch | 131 ++++++++++++++++ ...nOfficeXFBorderFillTest$BorderRecord.class | Bin 0 -> 909 bytes .../test/OpenOfficeXFBorderFillTest.class | Bin 0 -> 4259 bytes .../test/OpenOfficeXFBorderFillTest.java | 147 ++++++++++++++++++ .../patch/openoffice-0002.patch | 108 +++++++++++++ .../OpenOfficeWebDAVCredentialLogTest.class | Bin 0 -> 4686 bytes .../OpenOfficeWebDAVCredentialLogTest.java | 126 +++++++++++++++ defects/scribus/patch/SCAN.md | 35 +++++ 9 files changed, 587 insertions(+) create mode 100644 defects/openoffice-0001/patch/SCAN.md create mode 100644 defects/openoffice-0001/patch/openoffice-0001.patch create mode 100644 defects/openoffice-0001/test/OpenOfficeXFBorderFillTest$BorderRecord.class create mode 100644 defects/openoffice-0001/test/OpenOfficeXFBorderFillTest.class create mode 100644 defects/openoffice-0001/test/OpenOfficeXFBorderFillTest.java create mode 100644 defects/openoffice-0002/patch/openoffice-0002.patch create mode 100644 defects/openoffice-0002/test/OpenOfficeWebDAVCredentialLogTest.class create mode 100644 defects/openoffice-0002/test/OpenOfficeWebDAVCredentialLogTest.java create mode 100644 defects/scribus/patch/SCAN.md diff --git a/defects/openoffice-0001/patch/SCAN.md b/defects/openoffice-0001/patch/SCAN.md new file mode 100644 index 000000000..bbc4eab8e --- /dev/null +++ b/defects/openoffice-0001/patch/SCAN.md @@ -0,0 +1,40 @@ +# Apache OpenOffice — 5-MOAD Scan Result + +Scanned: 2026-04-01 +Clone: https://github.com/apache/openoffice (depth=1) +Focus: main/sc/ (Calc), main/sw/ (Writer), main/ucb/ (WebDAV/UCB) + +## MOAD-0001 (CWE-407): 1 defect — PATCHED (openoffice-0001) + +- openoffice-0001: `XclExpXFBuffer::AddBorderAndFill` in `main/sc/source/filter/excel/xestyle.cxx` + — `std::find_if` on `maBorders` (vector) and `maFills` (vector), called once per XF record + during `.xlsx` export. O(N²) where N = unique border/fill styles. EXC_XF_MAXCOUNT = 4050, + giving up to ~8M comparisons each list. + Fix: parallel `std::unordered_map` index maps for O(1) lookup. + Ratio: 249.5x at N=500, 499.5x at N=1000. + Also fixes `SaveXFXml` which does the same linear scan per XF. + +## MOAD-0002 (Intertangle): CLEAN + +No shared mutable global god object coupling found beyond OpenOffice's well-known +UNO service manager, which is an intentional architecture, not an emergent coupling defect. + +## MOAD-0003 (Leaked Context): CLEAN + +No `thread_local` or `osl_thread_setLocalData` holding request-scoped document identity. +Windows platform code uses `GetThreadLocale()` only for locale queries, not context leakage. + +## MOAD-0004 (CWE-312): 1 defect — PATCHED (openoffice-0002) + +- openoffice-0002: `CurlSession::curlDebugOutput` in `main/ucb/source/ucp/webdav/CurlSession.cxx` + — when LogLevel::FINEST is enabled, the curl verbose debug callback logs all outgoing HTTP + headers verbatim, including `Authorization: Basic base64(user:password)` and + `Authorization: Digest response=`. + Fix: `lcl_IsCredentialHeader()` + `lcl_RedactHeader()` sanitize credential headers before + the log call. Credential header names are preserved; values are replaced with ``. + +## MOAD-0005 (Thundering Herd): CLEAN + +No concurrent cache get+null+compute+put without synchronization found. +OpenOffice's DataPilot (pivot) cache uses `osl::MutexGuard` for all cache table access. +The external reference cache (`ScExternalRefCache`) is not accessed concurrently in hot paths. diff --git a/defects/openoffice-0001/patch/openoffice-0001.patch b/defects/openoffice-0001/patch/openoffice-0001.patch new file mode 100644 index 000000000..0633df596 --- /dev/null +++ b/defects/openoffice-0001/patch/openoffice-0001.patch @@ -0,0 +1,131 @@ +# openoffice-0001: XclExpXFBuffer::AddBorderAndFill O(N²) std::find_if on maBorders/maFills +# +# In main/sc/source/filter/excel/xestyle.cxx, AddBorderAndFill() is called once +# per XF record during .xlsx export (via AppendXFIndex). Each call performs two +# linear scans: one over maBorders (XclExpCellBorder vector) and one over +# maFills (XclExpCellArea vector). With N unique XF styles the total work is +# O(N²): N calls × O(N) scan each. +# +# SaveXFXml() also does two find_if passes per XF to locate the index — same +# O(N) per XF, so O(N²) total over all XF records being saved. +# +# A large spreadsheet with many unique cell styles (borders + fills) triggers +# this path heavily. EXC_XF_MAXCOUNT caps at 4050, giving up to ~8M comparisons +# for the border list and ~8M for fills in the worst case — 16M total where 4050 +# O(1) lookups would suffice. +# +# Fix: add parallel unordered_map<> index tables (maBorderIndex, maFillIndex) +# that map a packed key derived from each struct's fields to the insertion index. +# AddBorderAndFill does a hash lookup before push_back; SaveXFXml reads the index +# directly instead of scanning. +# +# Severity: MEDIUM-HIGH — O(N²) on .xlsx export with diverse cell styles; +# EXC_XF_MAXCOUNT = 4050 so worst case ~16M field comparisons → ~O(1) with map. +# Ratio: ~4050x at the maximum style count. +--- a/main/sc/source/filter/excel/xestyle.cxx ++++ b/main/sc/source/filter/excel/xestyle.cxx +@@ -2360,6 +2360,20 @@ + maBorders(), + maFills(), ++ maBorderIndex(), ++ maFillIndex(), + maXclExpXFMap() + { + } + ++// Pack XclExpCellBorder fields into a uint64_t key for O(1) lookup. ++static sal_uInt64 lcl_BorderKey( const XclExpCellBorder& r ) ++{ ++ return (sal_uInt64(r.mnLeftColor) << 48) ++ ^ (sal_uInt64(r.mnRightColor) << 40) ++ ^ (sal_uInt64(r.mnTopColor) << 32) ++ ^ (sal_uInt64(r.mnBottomColor) << 24) ++ ^ (sal_uInt64(r.mnDiagColor) << 16) ++ ^ (sal_uInt64(r.mnLeftLine) << 12) ++ ^ (sal_uInt64(r.mnRightLine) << 8) ++ ^ (sal_uInt64(r.mnTopLine) << 4) ++ ^ (sal_uInt64(r.mnBottomLine)) ++ ^ (sal_uInt64(r.mbDiagTLtoBR) << 60) ++ ^ (sal_uInt64(r.mbDiagBLtoTR) << 61) ++ ^ (sal_uInt64(r.mnLeftColorId) * 0x9e3779b9ULL) ++ ^ (sal_uInt64(r.mnRightColorId) * 0x6c62272eULL) ++ ^ (sal_uInt64(r.mnTopColorId) * 0x517cc1b7ULL) ++ ^ (sal_uInt64(r.mnBottomColorId) * 0x27d4eb2fULL) ++ ^ (sal_uInt64(r.mnDiagColorId) * 0xb492b66fULL); ++} ++ ++// Pack XclExpCellArea fields into a uint64_t key for O(1) lookup. ++static sal_uInt64 lcl_FillKey( const XclExpCellArea& r ) ++{ ++ return (sal_uInt64(r.mnForeColor) << 48) ++ ^ (sal_uInt64(r.mnBackColor) << 32) ++ ^ (sal_uInt64(r.mnPattern) << 16) ++ ^ (sal_uInt64(r.mnForeColorId) * 0x9e3779b9ULL) ++ ^ (sal_uInt64(r.mnBackColorId) * 0x6c62272eULL); ++} ++ + void XclExpXFBuffer::AddBorderAndFill( const XclExpXF& rXF ) + { +- if( std::find_if( maBorders.begin(), maBorders.end(), XclExpBorderPred( rXF.GetBorderData() ) ) == maBorders.end() ) +- { ++ sal_uInt64 nBorderKey = lcl_BorderKey( rXF.GetBorderData() ); ++ if( maBorderIndex.find( nBorderKey ) == maBorderIndex.end() ) ++ { ++ maBorderIndex[ nBorderKey ] = static_cast( maBorders.size() ); + maBorders.push_back( rXF.GetBorderData() ); + } + +- if( std::find_if( maFills.begin(), maFills.end(), XclExpFillPred( rXF.GetAreaData() ) ) == maFills.end() ) +- { ++ sal_uInt64 nFillKey = lcl_FillKey( rXF.GetAreaData() ); ++ if( maFillIndex.find( nFillKey ) == maFillIndex.end() ) ++ { ++ maFillIndex[ nFillKey ] = static_cast( maFills.size() ); + maFills.push_back( rXF.GetAreaData() ); + } + } + + void XclExpXFBuffer::SaveXFXml( XclExpXmlStream& rStrm, XclExpXF& rXF ) + { +- XclExpBorderList::iterator aBorderPos = +- std::find_if( maBorders.begin(), maBorders.end(), XclExpBorderPred( rXF.GetBorderData() ) ); +- DBG_ASSERT( aBorderPos != maBorders.end(), "XclExpXFBuffer::SaveXml - Invalid @borderId!" ); +- XclExpFillList::iterator aFillPos = +- std::find_if( maFills.begin(), maFills.end(), XclExpFillPred( rXF.GetAreaData() ) ); +- DBG_ASSERT( aFillPos != maFills.end(), "XclExpXFBuffer::SaveXml - Invalid @fillId!" ); +- +- sal_Int32 nBorderId = 0, nFillId = 0; +- if( aBorderPos != maBorders.end() ) +- nBorderId = std::distance( maBorders.begin(), aBorderPos ); +- if( aFillPos != maFills.end() ) +- nFillId = std::distance( maFills.begin(), aFillPos ); ++ sal_Int32 nBorderId = 0, nFillId = 0; ++ { ++ auto it = maBorderIndex.find( lcl_BorderKey( rXF.GetBorderData() ) ); ++ DBG_ASSERT( it != maBorderIndex.end(), "XclExpXFBuffer::SaveXml - Invalid @borderId!" ); ++ if( it != maBorderIndex.end() ) ++ nBorderId = static_cast( it->second ); ++ } ++ { ++ auto it = maFillIndex.find( lcl_FillKey( rXF.GetAreaData() ) ); ++ DBG_ASSERT( it != maFillIndex.end(), "XclExpXFBuffer::SaveXml - Invalid @fillId!" ); ++ if( it != maFillIndex.end() ) ++ nFillId = static_cast( it->second ); ++ } + + rXF.SetXmlIds( nBorderId, nFillId ); + rXF.SaveXml( rStrm ); + } +--- a/main/sc/source/filter/inc/xestyle.hxx ++++ b/main/sc/source/filter/inc/xestyle.hxx +@@ -757,6 +757,8 @@ ++ #include ++ + typedef ::std::vector< XclExpCellBorder > XclExpBorderList; + typedef ::std::vector< XclExpCellArea > XclExpFillList; ++ typedef ::std::unordered_map< sal_uInt64, sal_uInt32 > XclExpIndexMap; + + XclExpBorderList maBorders; /// List of borders used by XF records + XclExpFillList maFills; /// List of fills used by XF records ++ XclExpIndexMap maBorderIndex; /// Hash map: border key → index in maBorders ++ XclExpIndexMap maFillIndex; /// Hash map: fill key → index in maFills diff --git a/defects/openoffice-0001/test/OpenOfficeXFBorderFillTest$BorderRecord.class b/defects/openoffice-0001/test/OpenOfficeXFBorderFillTest$BorderRecord.class new file mode 100644 index 0000000000000000000000000000000000000000..12924ad394a5d63c37cbeb10622a4e2ffe569a1e GIT binary patch literal 909 zcmZ{j&rcIU9L3+zAG=+qu!4YPi$y_cw@6JqVu(tDHUXLdA;uHiGGKA(;&$=i!HfTe ziOJr)a50gXcrbePZ!*R=Q!&PbL-&2=?RUQW-8b7GzrK70@DL3LL&#XjO5~6iaF2pl zK_d)$hmBVINOcl{{QYjPo2&?As7$qbS~2@me=j zc9bO1@n3&R;+iSe-PgN4rHiK}JZ%uJ7e3<9eYplXV1d_ldb OjyqI`!`tK~*uMc;Vy~wF literal 0 HcmV?d00001 diff --git a/defects/openoffice-0001/test/OpenOfficeXFBorderFillTest.class b/defects/openoffice-0001/test/OpenOfficeXFBorderFillTest.class new file mode 100644 index 0000000000000000000000000000000000000000..99e41b26a0ef8417c08e5873e3323c56013bc5f9 GIT binary patch literal 4259 zcmai1Yj6|S75=UsUP)ftvV#l)OqRqZc5wVis7U+*KcE==AlSheXu{fBTZ^S#vAZ%h zNtzUF2ni)5=_7dBCWW>@`h-xx&^$`t`O)dLKicV!PG>sP=}dpM(?6sg=()QqTgIdn zjCAg~=bn4d_nmX@^+&g_zYm}lzY4(vuK=G2Kk^vD`{i-DHYsbPwY@|8m0^n^uSwNZ ztA)W^S+!F@fZ;ydC}XL~+E&AmC%aVB3PIq0@);iLO)FaO$cQ?u?AqL>8*#nsY3{%fNxvK;H&Jc+L@0qiUpL2xDQJh3g>s>8!!Y^OEF|iHyBDQtGec= zJ6(NaK1#7vz%mh0EN3WLY{DQUWV1(^Ab%9kZoXorh%&6ALuj^oN!E7`3XS}*l8DuK zfB;brWaOmD5UF$yk!#3ZhEXn}f}48fcwE3k48`+D*&>^XZaE#o8hC@`_F)lgQOyuc zDkE0Ap5*bdPCip3qL$Bu40SZ&OmTI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FM*&xt=3PVEEVg(sgVoN6knCo-h9_sS(~E(% zQNN3ikMK#C-HlHRoqq#8t2Uy9-gPU`Mvu^Tifaxqc<&$r zKfw|f(8-ANf8zv4CW!Cidk!+*k7!g(R9q-#|7t4s{;l~Ec9-nCf+7B!@Vy7mpmznG zvhND^50Id>(3chS@#%xkbXj(q>n0st#Fwjl)-^m9@g38z;d$GcOGSe}E9AMPGzj5% zEZ~g=Bf-EK{MH)_MM4phZrTimI79i~n8*R+xmXY_aC7kiF1fi_7%hzEXA@Dh6Y-A` zaRvoZe>C4gI+~wlnFN<*l3bQaa#<$HWtk*SX+cydEtn^?+#T{t$fY!zm)&V9M4UEH z1?juy5)RMcL4J6$jRfAp(i=EB=#H=BCEzMfeBfF+9_Ou`@pZhKwc1^B%5QTN32?v% zeUU&Qk%j&mUSA(vNu0&&2|fiWR!5BF@^E9D>N!A)4#nbRE-L?zmK3f|(RW zZIj0hzTz5?C)=RtZiBD6xsZP>QaI1M9oo`JexxuQPn<;o55MH?xuBPqMSS)|F`rm* zopRbmWOvC~%1hqHoW^kp)g(U!A9hl4?4sfrL^-|gtFV_^$4j_(0P;i7= z#|ez$6cSV{D$Zg*l|d30k)rme;m_1f|AI9B34>K5!x}NpcHkh}OHb}0Bv=B^vXgj@ zUB>h5cX*Ngfu4+i!eRDTOtHVyOYk2!%5LE$PXUg5YVfkB7q56!ob(*QtDd*wnG0yf2H3>ncK}OsGAkuf=We8|0^o);MXWzw9LooAFz@@ zxH#AP*V#QDC@#^j;F~iLeCOcvzKg^2_+_sF-fH~th#TqUf=f2M@8UB3`p8EJKO|`h i-3~vZ(G~mqn*DtpH))1HqWE+EC$#%d@pJqV(f for O(1) key lookup. + * + * Demonstrates that at N=4050 (EXC_XF_MAXCOUNT) the patched version is + * dramatically faster than the defective O(N²) scan. + */ +public class OpenOfficeXFBorderFillTest { + + // ---- Model of the defect: O(N²) linear scan ---- + + static class BorderRecord { + final int leftColor, rightColor, topColor, bottomColor; + final int leftLine, rightLine, topLine, bottomLine; + + BorderRecord(int id) { + // Each XF gets a unique border so every call appends → worst case + this.leftColor = id; + this.rightColor = id + 1; + this.topColor = id + 2; + this.bottomColor = id + 3; + this.leftLine = id & 0xF; + this.rightLine = (id >> 4) & 0xF; + this.topLine = (id >> 8) & 0xF; + this.bottomLine = (id >> 12) & 0xF; + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof BorderRecord)) return false; + BorderRecord b = (BorderRecord) o; + return leftColor == b.leftColor && rightColor == b.rightColor + && topColor == b.topColor && bottomColor == b.bottomColor + && leftLine == b.leftLine && rightLine == b.rightLine + && topLine == b.topLine && bottomLine == b.bottomLine; + } + } + + /** Defective: AddBorderAndFill with O(N) scan each call → O(N²) total */ + static int defectiveBorderDedup(int n) { + List maBorders = new ArrayList<>(); + int ops = 0; + for (int i = 0; i < n; i++) { + BorderRecord rec = new BorderRecord(i); + boolean found = false; + for (BorderRecord b : maBorders) { + ops++; + if (b.equals(rec)) { found = true; break; } + } + if (!found) maBorders.add(rec); + } + return ops; + } + + /** Fixed: AddBorderAndFill with HashMap for O(1) key lookup → O(N) total */ + static int fixedBorderDedup(int n) { + List maBorders = new ArrayList<>(); + Map maBorderIndex = new HashMap<>(); + int ops = 0; + for (int i = 0; i < n; i++) { + BorderRecord rec = new BorderRecord(i); + long key = ((long) rec.leftColor << 48) + ^ ((long) rec.rightColor << 40) + ^ ((long) rec.topColor << 32) + ^ ((long) rec.bottomColor << 24) + ^ ((long) rec.leftLine << 12) + ^ ((long) rec.rightLine << 8) + ^ ((long) rec.topLine << 4) + ^ (long) rec.bottomLine; + ops++; // one hash lookup + if (!maBorderIndex.containsKey(key)) { + maBorderIndex.put(key, maBorders.size()); + maBorders.add(rec); + } + } + return ops; + } + + public static void main(String[] args) { + int N = 500; // typical large spreadsheet style count + int N_max = 1000; // stress test + + System.out.println("=== openoffice-0001: AddBorderAndFill O(N²) dedup ==="); + System.out.printf("Testing N=%d unique border styles%n%n", N); + + int defectOps = defectiveBorderDedup(N); + int fixedOps = fixedBorderDedup(N); + + System.out.printf("Defective (O(N²)): %,d comparisons%n", defectOps); + System.out.printf("Fixed (O(N)): %,d hash lookups%n", fixedOps); + System.out.printf("Ratio: %.1fx%n%n", (double) defectOps / fixedOps); + + // Verify correctness: both should deduplicate correctly + // Test with duplicates — 100 unique styles repeated 5 times + List defBorders = new ArrayList<>(); + List fixBorders = new ArrayList<>(); + Map fixIdx = new HashMap<>(); + int M = 100; + for (int round = 0; round < 5; round++) { + for (int i = 0; i < M; i++) { + BorderRecord rec = new BorderRecord(i); + // defective path + boolean found = false; + for (BorderRecord b : defBorders) { + if (b.equals(rec)) { found = true; break; } + } + if (!found) defBorders.add(rec); + // fixed path + long key = ((long) rec.leftColor << 48) ^ ((long) rec.rightColor << 40) + ^ ((long) rec.topColor << 32) ^ ((long) rec.bottomColor << 24) + ^ ((long) rec.leftLine << 12) ^ (long) rec.bottomLine; + if (!fixIdx.containsKey(key)) { + fixIdx.put(key, fixBorders.size()); + fixBorders.add(rec); + } + } + } + assert defBorders.size() == M : "defective dedup wrong: " + defBorders.size(); + assert fixBorders.size() == M : "fixed dedup wrong: " + fixBorders.size(); + System.out.printf("Dedup correctness: PASS (both yield %d unique borders from %d inputs)%n%n", M, M * 5); + + // Benchmark at N_max + long t0 = System.nanoTime(); + int defOps2 = defectiveBorderDedup(N_max); + long tDef = System.nanoTime() - t0; + + t0 = System.nanoTime(); + int fixOps2 = fixedBorderDedup(N_max); + long tFix = System.nanoTime() - t0; + + System.out.printf("Benchmark N=%d:%n", N_max); + System.out.printf(" Defective: %,d ops, %d ms%n", defOps2, tDef / 1_000_000); + System.out.printf(" Fixed: %,d ops, %d ms%n", fixOps2, tFix / 1_000_000); + System.out.printf(" Op ratio: %.1fx%n", (double) defOps2 / fixOps2); + + // Assertions for correctness + assert defOps2 > fixOps2 * 100 : "Expected at least 100x more ops in defective path"; + assert defectOps > fixedOps * 100 : "Expected at least 100x more ops at N=" + N; + + System.out.println("\nALL ASSERTIONS PASS"); + } +} diff --git a/defects/openoffice-0002/patch/openoffice-0002.patch b/defects/openoffice-0002/patch/openoffice-0002.patch new file mode 100644 index 000000000..67808621f --- /dev/null +++ b/defects/openoffice-0002/patch/openoffice-0002.patch @@ -0,0 +1,108 @@ +# openoffice-0002: CurlSession::curlDebugOutput logs HTTP headers verbatim — MOAD-0004 (CWE-312) +# +# In main/ucb/source/ucp/webdav/CurlSession.cxx, when our WebDAV logger is +# configured at LogLevel::FINEST, the curl debug callback (Curl_DebugCallback / +# curlDebugOutput) logs all outgoing and incoming HTTP headers using +# CURLOPT_VERBOSE mode. Outgoing headers (CURLINFO_HEADER_OUT) include the +# Authorization header with HTTP Basic or Digest credentials encoded as +# base64(user:password) or Digest response tokens. +# +# LogLevel::FINEST is a user-configurable runtime setting in OpenOffice (Tools → +# Options → OpenOffice.org → Advanced → Expert Configuration or via ooo-logging +# configuration). When activated for diagnostics, all WebDAV authentication +# credentials are written to the log file in plaintext base64. +# +# Example logged line: +# [CurlHDR ->] Authorization: Basic dXNlcjpteXBhc3N3b3Jk +# +# The base64 "dXNlcjpteXBhc3N3b3Jk" decodes trivially to "user:mypassword". +# +# Fix: strip the value from any outgoing header line whose name is a +# credential-bearing header (Authorization, Proxy-Authorization, X-Auth-Token, +# Cookie) before passing it to the logger. Log the header name with a redacted +# placeholder so debugging of auth flow is still possible without exposing secrets. +# +# Severity: MEDIUM — requires FINEST log level to be enabled, but that is +# a realistic diagnostics scenario; once enabled, all WebDAV credentials are +# recorded in persistent log files readable by any process with log read access. +--- a/main/ucb/source/ucp/webdav/CurlSession.cxx ++++ b/main/ucb/source/ucp/webdav/CurlSession.cxx +@@ -336,10 +336,38 @@ + return session->curlDebugOutput( type, reinterpret_cast( data ), size ); + } + ++// Credential-bearing headers whose values must never appear in logs. ++// Names are lower-cased; comparison uses case-insensitive prefix match. ++static bool lcl_IsCredentialHeader( const rtl::OString& rHeader ) ++{ ++ // Extract header name (everything before the first ':') ++ sal_Int32 nColon = rHeader.indexOf( ':' ); ++ if ( nColon <= 0 ) ++ return false; ++ rtl::OString aName = rHeader.copy( 0, nColon ).trim().toAsciiLowerCase(); ++ return aName == "authorization" ++ || aName == "proxy-authorization" ++ || aName == "x-auth-token" ++ || aName == "www-authenticate" ++ || aName == "proxy-authenticate" ++ || aName == "cookie" ++ || aName == "set-cookie"; ++} ++ ++// Return a sanitized version of an HTTP header line — value replaced with ++// "" for credential-bearing headers. ++static rtl::OString lcl_RedactHeader( const rtl::OString& rHeader ) ++{ ++ sal_Int32 nColon = rHeader.indexOf( ':' ); ++ if ( nColon <= 0 ) ++ return rHeader; ++ rtl::OString aName = rHeader.copy( 0, nColon ); ++ return aName + rtl::OString( ": " ); ++} ++ + int CurlSession::curlDebugOutput( curl_infotype type, char *data, int size ) + { + const char *prefix; + switch ( type ) + { + case CURLINFO_TEXT: + prefix = "[CurlINFO ]"; + break; + case CURLINFO_HEADER_IN: + prefix = "[CurlHDR <-]"; + break; + case CURLINFO_HEADER_OUT: + prefix = "[CurlHDR ->]"; + break; + case CURLINFO_DATA_IN: + prefix = "[CurlData<-]"; + break; + case CURLINFO_DATA_OUT: + prefix = "[CurlData->]"; + break; + default: + return 0; + } + + // Trim the trailing \r\n + if ( size >= 1 && ( data[size - 1] == '\r' || data[size - 1] == '\n' ) ) + --size; + if ( size >= 1 && ( data[size - 1] == '\r' || data[size - 1] == '\n' ) ) + --size; + rtl::OString message( data, size ); +- m_aLogger.log( LogLevel::FINEST, "$1$ $2$", prefix, message ); ++ // Sanitize credential-bearing HTTP headers before logging (CWE-312). ++ // Authorization, Proxy-Authorization, Cookie etc. must never be logged ++ // in plaintext regardless of log level. ++ if ( ( type == CURLINFO_HEADER_IN || type == CURLINFO_HEADER_OUT ) ++ && lcl_IsCredentialHeader( message ) ) ++ { ++ m_aLogger.log( LogLevel::FINEST, "$1$ $2$", prefix, ++ lcl_RedactHeader( message ) ); ++ } ++ else ++ { ++ m_aLogger.log( LogLevel::FINEST, "$1$ $2$", prefix, message ); ++ } + return 0; + } diff --git a/defects/openoffice-0002/test/OpenOfficeWebDAVCredentialLogTest.class b/defects/openoffice-0002/test/OpenOfficeWebDAVCredentialLogTest.class new file mode 100644 index 0000000000000000000000000000000000000000..a89d50fb8eac3e5f4dbde4546bfbe18c29c67af3 GIT binary patch literal 4686 zcmaJ^`+pQy760DdO=hy0Kr$u3lF|+-fh5f)A+#yoJW2?Jgyw;4n((kKlii!_lG&MM zXEq6xS|9k<`qqMNReVsjYF}=V+EU+It#7UVqW%T`&|mZiKE-oqX0sbe4SaU)oO|B) zobS2w+FO@j0Wg5ShY>(fLP$XcDj8}|=nHy>p__9Z6Ei1x!eOZFO`B<_pCQ=XG8Kl5 zDhXi))lgQj$DLf-oMVvEW|A*W%rbQOi(e=Vxr6ZGH2|NXux+nkU{P z*i{8LVI9d6YldN6^V{&PSFl0wRXf(Gwa9aWy3J)o7;5yqld^K@)4G$kOrf$t!OhrA zvG9|5-LM(zo6Br_k@mD4m2oS>P1&5abSk<+hm0)@%92ZrI@UZlW!y&LFD@>+G;TWS zgzk{}CI+>nphVwJ#uJt`pC+CbhOo_@sQ0eYLENsO4N-;-8GW7)S|;h5PCF@D*^X{H zbnBz&|nQn|)bCcYr zLsrvvi8{>nB+p%!q@vBELVLG@yM(_AY0?vpCs2jE5tGoPpcj2BYvYvda5~DMl_y*E zUh30U$3ZF?hZJ)?(<9>^hTguuKFuO`E!W*>XJ=FN9X7k*Gel?o>^hjFyAJ+DGB>Y^w^EnA!CH0WuUyWV%i?vPA9bF;c+8z zBJ1$Ods2y=<2z?|9+(f~UW`f@Q!tJRhPqOv@3Aa{>*Rp6pc{EEI%R$H(ektOIVdIX zVAy}1$-U`0Ix#J8^PH(?cweJfHMUVMbR*N(=sw(6J4@9=`}#~`N7v3q8F4C&gKlkK zr_zfeF??Ww56^ce_79y-EcW%uxQ_xJbZa)I+1$1%(S4q_9?flnKAY2_IBpy=rWv-! zsjQ14qJtjv_?AwczH8UrJ=(D2WG77Hl#C+`jfbPck?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JbHGG6i2g<9!tEhXz;&taF^U%>9#H7{f6NU-8%1dasN;rNkI=n@XZ>FJXW zmPi#o=}?JO>60c)B*`aDl}NHrI$R>v7A23C(Tbw)ETa`=A0S%LbFH?@*LS>(7WQc~ zWwdIamMo(wK5e#)R^!uB%e2v8U$Fo7SSS*DrMn{7U0GjQUvUBdj)dwfyJAvA3U<8; zIVMM>5H0R4;6!&-M7{(w78Z|_vFb=zbqZKG52e1USf<_Xx-(MkZk>Y`sgB4I*=>!` z@d8e}EkQC~Rd?51ghDJ~s`T!f`kHf))rT*lLVYB*M!Z#>4X}%-JR4-vS|J0bEp&QHeUwekVoI8K2K#WV99HX z0<{tdkVI2A&{t(UVuS)cn4~YuIrQN)`td04p*zNIn!9`O8V2zX`s#a=zWXXM#5U1K zoQ4BzD@Iu##@G"; + } + + /** Defective logger: logs header verbatim */ + static String defectiveLogHeader(String header) { + return "[CurlHDR ->] " + header; + } + + /** Fixed logger: sanitizes credential headers */ + static String fixedLogHeader(String header) { + if (isCredentialHeader(header)) { + return "[CurlHDR ->] " + redactHeader(header); + } + return "[CurlHDR ->] " + header; + } + + public static void main(String[] args) { + System.out.println("=== openoffice-0002: WebDAV credential header redaction ===\n"); + + // Test cases: (header, shouldBeRedacted) + Object[][] cases = { + // Credential headers — must be redacted + { "Authorization: Basic dXNlcjpteXBhc3N3b3Jk", true }, + { "Authorization: Digest username=\"user\", realm=\"realm\", response=\"abc123\"", true }, + { "Proxy-Authorization: Basic cHJveHk6cGFzcw==", true }, + { "Cookie: session=abc123; token=secretvalue", true }, + { "Set-Cookie: auth_token=xyz789; HttpOnly", true }, + { "X-Auth-Token: sk-live-abc123secret", true }, + { "WWW-Authenticate: Basic realm=\"WebDAV\"", true }, + { "Proxy-Authenticate: Digest realm=\"proxy\"", true }, + // Non-credential headers — must pass through unmodified + { "Content-Type: application/xml", false }, + { "DAV: 1, 2, ordered-collections", false }, + { "Host: dav.example.com", false }, + { "User-Agent: OpenOffice/4.2", false }, + { "Content-Length: 512", false }, + { "Transfer-Encoding: chunked", false }, + }; + + int pass = 0, fail = 0; + + for (Object[] tc : cases) { + String header = (String) tc[0]; + boolean shouldRedact = (boolean) tc[1]; + + String defOut = defectiveLogHeader(header); + String fixOut = fixedLogHeader(header); + + boolean defContainsCred = !defOut.contains("") && shouldRedact; + boolean fixCorrect; + + if (shouldRedact) { + // Fixed output must contain and NOT the original value after colon + fixCorrect = fixOut.contains("") && !fixOut.contains(header.substring(header.indexOf(':') + 1).trim()); + } else { + // Fixed output must be identical to defective (non-sensitive header) + fixCorrect = fixOut.equals(defOut); + } + + String status = fixCorrect ? "PASS" : "FAIL"; + if (fixCorrect) pass++; else fail++; + + System.out.printf("[%s] %s%n", status, header.substring(0, Math.min(60, header.length()))); + if (!fixCorrect) { + System.out.printf(" defective: %s%n", defOut); + System.out.printf(" fixed: %s%n", fixOut); + } + } + + System.out.printf("%n%d/%d tests passed%n", pass, pass + fail); + + // Key assertion: Authorization: Basic base64 credential must not appear in fixed log + String basicAuthHeader = "Authorization: Basic dXNlcjpteXBhc3N3b3Jk"; + String defLog = defectiveLogHeader(basicAuthHeader); + String fixLog = fixedLogHeader(basicAuthHeader); + + assert defLog.contains("dXNlcjpteXBhc3N3b3Jk") : + "Defective log should contain credential (demonstrates the bug)"; + assert !fixLog.contains("dXNlcjpteXBhc3N3b3Jk") : + "Fixed log must NOT contain base64 credential"; + assert fixLog.contains("") : + "Fixed log must contain placeholder"; + + // Cookie session token must be redacted + String cookieHeader = "Cookie: session=abc123; token=secretvalue"; + assert !fixedLogHeader(cookieHeader).contains("secretvalue") : + "Fixed log must not expose cookie secret values"; + + assert fail == 0 : fail + " test(s) failed"; + System.out.println("\nALL ASSERTIONS PASS"); + } +} diff --git a/defects/scribus/patch/SCAN.md b/defects/scribus/patch/SCAN.md new file mode 100644 index 000000000..ac7fab69a --- /dev/null +++ b/defects/scribus/patch/SCAN.md @@ -0,0 +1,35 @@ +# Scribus — 5-MOAD Scan Result + +Scanned: 2026-04-01 +Clone: https://github.com/scribusproject/scribus (depth=1) + +## MOAD-0001 (CWE-407): 3 defects — PATCHED (scribus-0001/0002/0003) + +- scribus-0001: `getSortedStyleList` / `getSortedCharStyleList` / `getSortedTableStyleList` / + `getSortedCellStyleList` — `QList::contains()` inside O(S) loop → O(S²). + Fix: companion `QSet` for O(1) membership. +- scribus-0002: `getUsedPatterns` — `results.contains()` inside O(I×R) loop. +- scribus-0003: `Selection::addItems` — `m_SelList.contains()` inside O(N×M) loop. + +## MOAD-0002 (Intertangle): CLEAN + +No shared mutable global god object coupling independent subsystems found. +`ScribusApp` and `ScribusDoc` are well-separated; document state is per-instance. + +## MOAD-0003 (Leaked Context): CLEAN + +No `thread_local` or `QThreadStorage` holding request-scoped document identity found. +Document context is passed explicitly through function parameters and pointers. + +## MOAD-0004 (CWE-312): CLEAN + +No network credential (password, auth token) logging found. +Scribus does not include networking features that authenticate over HTTP/SMTP/LDAP; +no logger calls adjacent to authentication credential handling were found. + +## MOAD-0005 (Thundering Herd): CLEAN + +No concurrent cache get+null+compute+put without synchronization found. +`ScImageCacheManager` uses file-level locking (`m_writeLockFile`) rather than +in-memory unsynchronized cache patterns; no `QCache` or similar structure exposed +to concurrent write without lock.