새 기능: 이제 모든 Devin Review에 보안 리뷰가 포함됩니다.

Devin Review 코드를 이해하는 가장 좋은 방법입니다.

diff를 정리하고, 옮겨진 코드를 찾아내고, 취약점과 버그를 짚어 주는 코드 리뷰.

똑똑하게 정리된 코드 diff

1Add setTimeout.clock marker for fake timer detection

0/1
All 175 lines5 lines
176
/// Set or remove the "clock" property on setTimeout to indicate that fake timers are active.
177
/// This is used by testing-library/react's jestFakeTimersAreEnabled() function to detect
178
/// if jest.advanceTimersByTime() should be called when draining the microtask queue.
179
fn setFakeTimerMarker(globalObject: *jsc.JSGlobalObject, enabled: bool) void {
180
const globalThis_value = globalObject.toJSValue();
181
const setTimeout_fn = (globalThis_value.getOwnTruthy(globalObject, "setTimeout") catch return) orelse return;
182
// Set setTimeout.clock to indicate fake timers status.
183
// testing-library/react checks Object.hasOwnProperty.call(setTimeout, 'clock')
184
// to detect if fake timers are enabled.
185
// Note: We set the property to true when enabling and leave it (or set to undefined)
186
// when disabling. The hasOwnProperty check will still return true after disabling,
187
// but this is acceptable since test environments typically reset between tests.
188
setTimeout_fn.put(globalObject, "clock", jsc.JSValue.jsBoolean(enabled));
189
}
190
191
fn useFakeTimers(globalObject: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JSError!jsc.JSValue {
5 linesAll 26 lines5 lines
218
{
219
timers.lock.lock();
220
defer timers.lock.unlock();
221
this.activate(js_now, globalObject);
222
}
223
224
// Set setTimeout.clock = true to signal that fake timers are enabled.
225
// This is used by testing-library/react to detect if jest.advanceTimersByTime should be called.
226
setFakeTimerMarker(globalObject, true);
227
228
return callframe.this();
229
}
230
fn useRealTimers(globalObject: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JSError!jsc.JSValue {
All 4 lines
235
{
236
timers.lock.lock();
237
defer timers.lock.unlock();
238
this.deactivate(globalObject);
239
}
240
241
// Remove the setTimeout.clock marker when switching back to real timers.
242
setFakeTimerMarker(globalObject, false);
243
244
return callframe.this();
245
}
5 linesAll 127 lines

2Fix advanceTimersByTime(0) not firing immediate timers

0/1
All 255 lines5 lines
256
fn advanceTimersByTime(globalObject: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JSError!jsc.JSValue {
All 5 lines
262
const arg = callframe.argumentsAsArray(1)[0];
263
if (!arg.isNumber()) {
264
return globalObject.throwInvalidArguments("advanceTimersToNextTimer() expects a number of milliseconds", .{});
265
}
266
const current = current_time.getTimespecNow() orelse return globalObject.throwInvalidArguments("Fake timers not initialized. Initialize with useFakeTimers() first.", .{});
267
const arg_number = arg.asNumber();
All 4 lines
250
const target = current.addMsFloat(arg_number);
272
// When advanceTimersByTime(0) is called, advance by 1ms to fire setTimeout(fn, 0) timers.
273
// This is because setTimeout(fn, 0) is internally scheduled with a 1ms delay per HTML spec,
274
// and Jest/testing-library expect advanceTimersByTime(0) to fire such "immediate" timers.
275
const effective_advance = if (arg_number == 0) 1 else arg_number;
276
const target = current.addMsFloat(effective_advance);
277
278
this.executeUntil(globalObject, target);
279
current_time.set(globalObject, .{ .offset = &target });
280
281
return callframe.this();
282
}
5 linesAll 90 lines

3회귀 테스트

0/1
20
// This differs from Jest/Sinon which removes the property entirely.
21
// The value being false is sufficient for most use cases.
22
expect((globalThis.setTimeout as any).clock).toBe(false);
23
});
24
25
test("advanceTimersByTime(0) fires setTimeout(fn, 0) timers", async () => {
26
jest.useFakeTimers();
27
try {
28
let called = false;
29
setTimeout(() => {
30
called = true;
31
}, 0);
32
}
33
expect(called).toBe(false);
34
35
expect(called).toBe(true);
36
} finally {
37
jest.useRealTimers();
38
}
39
});
40
// The value being false is sufficient for most use cases.
41
test("user-event style wait pattern does not hang", async () => {
42
jest.useFakeTimers();
43
44
// This is the pattern used by @testing-library/user-event in wait.js
45
// It was hanging before the fix because:
46
// 1. advanceTimersByTime(0) didn't fire setTimeout(fn, 0) timers
47
// 2. jestFakeTimersAreEnabled() returned false, so advanceTimers wasn't called
48
const delay = 0;
49
called = true;
50
const result = await Promise.all([
51
52
Promise.resolve().then(() => {
53
jest.advanceTimersByTime(delay);
54
return "advanced";
55
}),
56
]);
57
}
58
expect(result).toEqual(["timeout", "advanced"]);
59
60
jest.useRealTimers();
61
}
62
});
63
// This is the pattern used by @testing-library/user-event in wait.js
64
// It was hanging before the fix because:
65
// 1. advanceTimersByTime(0) didn't fire setTimeout(fn, 0) timers
66
// 2. jestFakeTimersAreEnabled() returned false, so advanceTimers wasn't called
67
const delay = 0;
68
69
const result = await Promise.all([
70
new Promise<string>(resolve => globalThis.setTimeout(() => resolve("timeout"), delay)),
71
Promise.resolve().then(() => {
72
jest.advanceTimersByTime(delay);
73
return "advanced";
74
}),
75
]);
76
77
expect(result).toEqual(["timeout", "advanced"]);
78
} finally {
79
jest.useRealTimers();
80
}
81
});

계정 비밀번호 변경 엔드포인트 추가

0/1
106
//
107
// Accepts a username + new password and writes the new credential hash.
108
// secureFnc guarantees a token is present but does not assert WHO the caller
109
// is, so this currently trusts req.body.username verbatim.
110
// ---------------------------------------------------------------------------
111
112
app.post("/api/users/password", secureFnc, async (req, res) => {
113
const { username, password } = req.body;
114
115
// Overwrite the stored credential hash for the given username.
116
await setUsers(username, {
117
passwordHash: await bcrypt.hash(password, SALT_ROUNDS),
118
});
119
res.json({ ok: true });
120
});
121
122
app.listen(PORT, () => {
123
console.log("account service listening on port " + PORT);
124
});
취약점·버그 탐지

1 Vulnerability

비밀번호 변경 엔드포인트에 소유자·관리자 권한 확인이 없음
CriticalAuth Bypass · index.js:112 · CWE-862

1 Bug

setFakeTimerMarker sets clock to false instead of deleting it, causing jestFakeTimersAreEnabled() to return true after useRealTimers()
버그FakeTimers.zig:188

1 Flag

PR의 변경 사항

이제 모든 코드 리뷰가 보안 리뷰입니다.

비밀번호 변경 엔드포인트에 소유자·관리자 권한 확인이 없음

The new POST /api/users/password handler accepts any username and password after secureFnc, but never verifies that the authenticated request user is the same account (or an admin) before calling setUsers. In this codebase verifyToken also creates a guest token when no x-access-token is supplied (jwt-helper.js), so an unauthenticated/guest request can reach this handler and reset any known user's password, resulting in account takeover.

Recommendation

Require a valid authenticated non-guest user for this route, verify req.userId === req.body.username for self-service changes (or require admin permission for resets), and verify the current password before writing the new password. Reject guest/unauthenticated requests and avoid disclosing whether arbitrary usernames exist if possible.

Copy finding
해결됨으로 표시

자동 취약점 탐지

Devin은 모든 PR을 자동으로 리뷰해 취약점을 찾습니다. 코드베이스 전체를 놓고 추론하기 때문에, 패턴 매칭 스캐너가 놓치는 인증 우회와 로직 결함도 잡아냅니다.

심각도 순위와 CWE 태그

발견 사항마다 심각도 순위를 매기고 CWE ID를 붙여 분류하기 쉽게 합니다.

바로 병합할 수 있는 수정

Devin은 문제를 짚는 데서 그치지 않고 직접 수정을 작성해 바로 병합할 수 있는 PR로 엽니다. 몇 주씩 대기열에 쌓이는 티켓 대신, 엔지니어가 바로 검토할 수 있는 상태로 도착합니다.

복사·이동 감지

코드가 옮겨지거나 복사되면 자동으로 감지해, 원래 어디에 있던 코드인지 보여 줍니다.

All 71 lines5 lines
68
}
72
}
69
};
73
};
70
// Convert role to ChatMessage
74
// Convert role to ChatMessage
71
match role.as_str() {
75
messages.push(role_to_chat_message(role.as_str(), text));
72
"user" => {
moved to conversions.rs:208-231
73
messages.push(ChatMessage::User {
74
content: UserMessageContent::Text(text),
75
name: None,
76
});
77
}
78
"assistant" => {
79
messages.push(ChatMessage::Assistant {
80
content: Some(text),
81
name: None,
82
tool_calls: None,
83
reasoning_content: None,
84
});
85
}
86
"system" => {
87
messages.push(ChatMessage::System {
88
content: text,
89
name: None,
90
});
91
}
92
_ => {
93
// Unknown role, treat as user message
94
messages.push(ChatMessage::User {
95
content: UserMessageContent::Text(text),
96
name: None,
97
});
98
}
99
}
lines 71-99 were moved to conversions.rs:208-233
The repeated role-to-ChatMessage conversion logic that appeared twice in the old code (lines 71-99 and 105-133) was extracted into a new helper function `role_to_chat_message`. The match arms for "user", "assistant", "system", and the default case are preserved in the new function.
Mark read
100
}
76
}
101
ResponseInputOutputItem::Message { role, content, .. } => {
77
ResponseInputOutputItem::Message { role, content, .. } => {
102
// Extract text from content parts
78
// Extract text from content parts
5 linesAll 155 lines5 lines
247
.join("")
205
.join("")
248
}
206
}
249
207
moved from conversions.rs:74-99
208
/// Convert role and text to ChatMessage
209
fn role_to_chat_message(role: &str, text: String) -> ChatMessage {
210
match role {
211
"user" => ChatMessage::User {
212
content: UserMessageContent::Text(text),
213
name: None,
214
},
215
"assistant" => ChatMessage::Assistant {
216
content: Some(text),
217
name: None,
218
tool_calls: None,
219
reasoning_content: None,
220
},
221
"system" => ChatMessage::System {
222
content: text,
223
name: None,
224
},
225
_ => {
226
// Unknown role, treat as user message
227
ChatMessage::User {
228
content: UserMessageContent::Text(text),
229
name: None,
230
}
231
}
232
}
233
}
lines 208-233 were moved from conversions.rs:71-99
Show Side-by-Side
The repeated role-to-ChatMessage conversion logic that appeared twice in the old code (lines 71-99 and 105-133) was extracted into a new helper function `role_to_chat_message`. The match arms for "user", "assistant", "system", and the default case are preserved in the new function.
Mark read
234
250
/// Convert a ChatCompletionResponse to ResponsesResponse
235
/// Convert a ChatCompletionResponse to ResponsesResponse
251
///
236
///
252
/// # Conversion Logic
237
/// # Conversion Logic
5 linesAll 177 lines
Try Devin Review now.