Skip to content

Commit c125cf9

Browse files
authored
Merge pull request #121 from wevm/sync-upstream-7
Sync rocicorp/mono main (836f22e)
2 parents 9236983 + 8f13a3f commit c125cf9

107 files changed

Lines changed: 4952 additions & 621 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.changeset/swift-fast-reconnect.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'zero-swift': patch
3+
---
4+
5+
The client reconnects sooner when its connection drops or the server stops answering, as JS's client now does: the first retry comes within half a second, and each further failure in a row doubles the wait, up to the usual 5 seconds. A connection that stays up for 5 seconds starts the schedule over. Errors the server sends keep the full interval and any backoff they ask for.

‎SECURITY.md‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Security policy
2+
3+
## Reporting a vulnerability
4+
5+
Please report vulnerabilities privately. Do not open a public issue.
6+
7+
- Preferred: [open a private security advisory](https://github.com/rocicorp/mono/security/advisories/new).
8+
- By email: arv@roci.dev.
9+
10+
Useful things to include: the affected package and version, what an attacker
11+
can do, and the smallest set of steps, patch or test that shows the problem.
12+
If a reproduction needs a running `zero-cache`, say how it is configured.
13+
14+
We will acknowledge your report, tell you whether we consider it a
15+
vulnerability, and keep you posted while we work on a fix. We will credit you
16+
in the advisory and the release notes unless you would rather we did not.
17+
18+
## Supported versions
19+
20+
Security fixes land in the latest stable `@rocicorp/zero` minor release line
21+
and in canary. Earlier minors are not patched; please upgrade.
22+
23+
## Scope
24+
25+
`zero-cache` is run by each app on its own infrastructure and accepts
26+
WebSocket connections from untrusted browser clients, so everything a client
27+
sends is attacker-controlled. Reports we are most interested in:
28+
29+
- authentication or authorization bypass, including permission rules that are
30+
not applied
31+
- one user or client group reading or writing another's data
32+
- SQL injection, or remote code execution anywhere
33+
- reaching the admin endpoints without `ZERO_ADMIN_PASSWORD`
34+
35+
Out of scope: anything that needs control of the operator's configuration,
36+
environment, Postgres database or API server; missing rate limiting on its
37+
own; and expensive queries an app has explicitly allowed.

‎apps/zbugs-swift/Sources/ZBugs/Queries.swift‎

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -321,26 +321,31 @@ public enum Queries {
321321
/// A page of an issue's comments, ordered by (created, id); a backward
322322
/// page flips the order. `start` is the cursor row.
323323
public static let commentsPage = defineQuery("commentsPage") {
324-
(args: CommentsPageArgs, _: AuthData?) in
324+
(args: CommentsPageArgs, auth: AuthData?) in
325325
let dir: AST.Direction = args.dir == .forward ? .asc : .desc
326-
var q = zql.comment
327-
.related(\.creator)
328-
.related(\.emoji) { $0.related(\.creator) }
329-
.where(\.issueID, args.issueID)
330-
.orderBy(\.created, dir)
331-
.orderBy(\.id, dir)
326+
var q = applyCommentPermissions(
327+
zql.comment
328+
.related(\.creator)
329+
.related(\.emoji) { $0.related(\.creator) }
330+
.where(\.issueID, args.issueID),
331+
auth?.role
332+
)
333+
.orderBy(\.created, dir)
334+
.orderBy(\.id, dir)
332335
if let start = args.start {
333336
q = q.start([\.id: start.id, \.created: start.created], inclusive: args.inclusive)
334337
}
335338
return q.limit(args.limit)
336339
}
337340

338-
public static let comment = defineQuery("comment") { (id: String, _: AuthData?) in
339-
zql.comment
340-
.related(\.creator)
341-
.related(\.emoji) { $0.related(\.creator) }
342-
.where(\.id, id)
343-
.one()
341+
public static let comment = defineQuery("comment") { (id: String, auth: AuthData?) in
342+
applyCommentPermissions(
343+
zql.comment
344+
.related(\.creator)
345+
.related(\.emoji) { $0.related(\.creator) }
346+
.where(\.id, id),
347+
auth?.role
348+
).one()
344349
}
345350

346351
public static let issueDetail = defineQuery("issueDetail") {
@@ -396,10 +401,19 @@ public enum Queries {
396401
.one()
397402
}
398403

399-
public static let emojiChange = defineQuery("emojiChange") { (subjectID: String, _: AuthData?) in
400-
zql.emoji
401-
.where(\.subjectID, subjectID)
402-
.related(\.creator) { $0.one() }
404+
public static let emojiChange = defineQuery("emojiChange") {
405+
(subjectID: String, auth: AuthData?) in
406+
let role = auth?.role
407+
var q = zql.emoji.where(\.subjectID, subjectID)
408+
if role != .crew {
409+
// The subject is an issue or a comment.
410+
q = q.where { emoji in
411+
emoji.or(
412+
emoji.exists(\.issue) { applyIssuePermissions($0, role) },
413+
emoji.exists(\.comment) { applyCommentPermissions($0, role) })
414+
}
415+
}
416+
return q.related(\.creator) { $0.one() }
403417
}
404418

405419
/// Deprecated in zbugs.
@@ -454,6 +468,17 @@ where Result.Row == Issue {
454468
role == .crew ? q : q.where(\.visibility, .public)
455469
}
456470

471+
/// Narrows a comment query to comments whose issue `role` may see. Comments
472+
/// and emoji are fetched by id, so each of those queries applies the issue's
473+
/// visibility itself.
474+
func applyCommentPermissions<Result: QueryResult>(
475+
_ q: Query<Comment, Result>, _ role: Role?
476+
)
477+
-> Query<Comment, Result>
478+
where Result.Row == Comment {
479+
role == .crew ? q : q.whereExists(\.issue) { applyIssuePermissions($0, role) }
480+
}
481+
457482
func labelsQuery(_ projectName: String, _ orderBy: AST.Direction?) -> Query<Label, [Label]> {
458483
var q = zql.label.whereExists(\.project, scalar: true) {
459484
$0.where(\.lowerCaseName, projectName.lowercased())

0 commit comments

Comments
 (0)