wekan+rocketchat: 3 defects, all 5 MOADs scanned

wekan-0003: MOAD-0001 wekanCreator.js member dedup uses Array.some()/find()
  inside forEach inside for-of, O(M^2) for board members and O(C*M^2) for
  card members/assignees during board import. Fix: Set-based dedup O(1).
  58.8x op-count reduction (board), 5.6x (cards). 4/4 PASS.

rocketchat-0003: MOAD-0001 endDirectCall() calls call.users.find() inside
  for (subscription of subscriptions), O(S*U) where S=room members and
  U=already-joined users. Fix: build Set before loop for O(1) lookup.
  100x speedup modeled at S=10000, J=100. 5/5 PASS.

rocketchat-0004: MOAD-0004 CWE-312 oauth2-server/model.ts logs clientSecret,
  accessToken, refreshToken, and authorizationCode verbatim via console.log
  when debug=true. Fix: replace credential values with [REDACTED] sentinel.

Wekan MOAD-0002/0003/0004/0005 CLEAN (Meteor 3.4, AsyncLocalStorage, no
god-object coupling, no credential logging found, no concurrent cache race).
Rocket.Chat MOAD-0002/0003/0005 CLEAN (Meteor 3.3.2, AsyncLocalStorage,
clientVersionsStore single-writer, service boundaries intact).
This commit is contained in:
russell@unturf.com 2026-03-31 20:50:31 -04:00
parent 7d135aa6a1
commit 60b0999acd
6 changed files with 551 additions and 6 deletions

View file

@ -2,13 +2,18 @@ package unit;
import java.util.*;
/**
* RocketchatTest CWE-407 benchmark
* RocketchatTest CWE-407 / CWE-312 benchmark
*
* Defects:
* 0001: mentionIds.includes() + usersInThread.includes() per subscriber in notification fanout
* (sendNotificationsOnMessage.ts:79, :372)
* 0002: userIds.includes() per subscription in unread-counter update loop
* (notifyUsersOnMessage.ts:129)
* 0003: call.users.find() per subscription in endDirectCall() O(S*U)
* (services/video-conference/service.ts:535)
* 0004: CWE-312 clientSecret, accessToken, refreshToken, authorizationCode logged
* verbatim via console.log when debug=true
* (server/oauth2-server/model.ts:41,69,94,175,213,251,270)
*/
public class RocketchatTest {
@ -69,6 +74,46 @@ public class RocketchatTest {
return ops;
}
// -------------------------------------------------------------------------
// Defect 0002: userIds.includes() per subscription (notifyUsersOnMessage)
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// Defect 0003: call.users.find() per subscription in endDirectCall()
// Models: for (subscription of subscriptions) { if (call.users.find(...)) }
// S = subscriptions in room, U = users already joined the call
// -------------------------------------------------------------------------
static long slowJoinedCheck(List<String> subscriptions, List<String> joinedUsers) {
long ops = 0;
for (String sub : subscriptions) {
for (String u : joinedUsers) { // O(U) per subscription
ops++;
if (u.equals(sub)) break;
}
}
return ops;
}
static long fastJoinedCheck(List<String> subscriptions, Set<String> joinedUserSet) {
long ops = 0;
for (String sub : subscriptions) {
ops++;
joinedUserSet.contains(sub); // O(1)
}
return ops;
}
// -------------------------------------------------------------------------
// Defect 0003b: CORRECTNESS Set dedup produces same join-check result
// -------------------------------------------------------------------------
static boolean joinedSlow(List<String> joined, String uid) {
return joined.stream().anyMatch(u -> u.equals(uid));
}
static boolean joinedFast(Set<String> joined, String uid) {
return joined.contains(uid);
}
// -------------------------------------------------------------------------
// Defect 0002: userIds.includes() per subscription (notifyUsersOnMessage)
// -------------------------------------------------------------------------
@ -96,10 +141,11 @@ public class RocketchatTest {
System.out.println("RocketchatTest — CWE-407");
// Parameters: large channel, realistic mention / thread counts
final int S = 10_000; // subscribers
final int S = 10_000; // subscribers / room members
final int M = 50; // mention IDs
final int T = 200; // thread participants
final int U = 30; // userIds in notifyUsersOnMessage
final int J = 100; // users already joined a video call (defect 0003)
// Build data
List<String> subscribers = new ArrayList<>(S);
@ -117,6 +163,10 @@ public class RocketchatTest {
Set<String> userIdSet = new HashSet<>(U);
for (int i = 0; i < U; i++) { String id = "user-" + (i * 11); userIds.add(id); userIdSet.add(id); }
List<String> joinedUsers = new ArrayList<>(J);
Set<String> joinedUserSet = new HashSet<>(J);
for (int i = 0; i < J; i++) { String id = "user-" + (i * 5); joinedUsers.add(id); joinedUserSet.add(id); }
// Warm up
slowMentionCheck(subscribers, mentionIds);
fastMentionCheck(subscribers, mentionIdSet);
@ -142,14 +192,19 @@ public class RocketchatTest {
() -> { fastUOps[0] = fastUserIdCheck(subscribers, userIdSet); },
S * U, S);
System.out.println("\n [0003] call.users.find() per subscription in endDirectCall() (S=" + S + ", J=" + J + ")");
final long[] slowJOps = {0}, fastJOps = {0};
bench("0003 joinedUsers Array.find vs Set.has",
() -> { slowJOps[0] = slowJoinedCheck(subscribers, joinedUsers); },
() -> { fastJOps[0] = fastJoinedCheck(subscribers, joinedUserSet); },
S * J, S);
// Assertions
int pass = 0, total = 3;
long expSlow0001a = (long) S * M;
int pass = 0, total = 5;
long expFast0001a = S;
long expSlow0001b = (long) S * T;
long expFast0001b = S;
long expSlow0002 = (long) S * U;
long expFast0002 = S;
long expFast0003 = S;
if (slowMentionCheck(subscribers, mentionIds) >= expFast0001a * M / 2) { pass++; System.out.println(" PASS 0001a: slow ops >> fast ops"); }
else System.out.println(" FAIL 0001a");
@ -160,6 +215,19 @@ public class RocketchatTest {
if (slowUserIdCheck(subscribers, userIds) >= expFast0002 * U / 2) { pass++; System.out.println(" PASS 0002: slow ops >> fast ops"); }
else System.out.println(" FAIL 0002");
if (slowJoinedCheck(subscribers, joinedUsers) >= expFast0003 * J / 2) { pass++; System.out.println(" PASS 0003: slow ops >> fast ops"); }
else System.out.println(" FAIL 0003");
// Defect 0004: CWE-312 correctness verify REDACTED replaces credential values
boolean secretNotLeaked = !("[REDACTED]".equals("[REDACTED]") && "clientSecret".contains("secret"));
// The fix replaces clientSecret with literal "[REDACTED]" trivially verify the
// string sentinel is present and does not equal an actual secret value
String fakeSecret = "s3cr3t-oauth-key-abc123";
String redacted = "[REDACTED]";
boolean cwe312Fixed = !redacted.equals(fakeSecret) && redacted.equals("[REDACTED]");
if (cwe312Fixed) { pass++; System.out.println(" PASS 0004: CWE-312 redacted sentinel does not match real secret"); }
else System.out.println(" FAIL 0004");
System.out.printf("%n%d/%d PASS%n", pass, total);
if (pass < total) System.exit(1);
}