Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,30 @@ Releases before 1.2 are listed in ROADMAP.md (section 5) and on the GitHub Relea

- OAuth 2.0 (client credentials, password, authorization code with PKCE and refresh), AWS Signature and Digest. Before, a request with one of
these was sent without it; a preset the app doesn't know now stops the request and says so.
- Shared collections: comments on requests, changing a member's role, deleting one for everyone (it stays on this device only), and secret
values shared with the collection fill secrets that have no value here. Team environments can be shared, changed and deleted.
- Company single sign-on (by work email).
- HITOP in the share sheet (text, an address, a file), HITOP Cloud syncing in the background, and collection runs on a schedule with a
notification when one fails. iOS decides when background work happens.
- **Security:** when the list of shared collections on the device can't be read, nothing is synced. Before, an end-to-end encrypted collection
could have been taken for an ordinary one and uploaded to the library, which the server can read. Secret values the Keychain can't show
at that moment are no longer pushed as deleted.
- Settings: the time limit of a request, certificate authorities to trust for requests, and client certificates (.p12), each for one server.
- File uploads: multipart rows take a file (a copy up to 50 MB stays on the device and goes out only with that request).
- Compare two responses (the current one, saved examples, earlier answers), Undo after a delete or a move, and runs over a CSV or JSON data file.
- Import (Postman, Insomnia, Bruno, HAR, OpenAPI, HITOP files, a collection folder's zip; pasted, picked or opened from another app) and export.

### Android

- **Security:** when the list of shared collections on the phone can't be read, nothing is synced, and a shared collection deleted for everyone
stays on this phone only. Before, such an end-to-end encrypted collection could have been uploaded to the library, which the server can read.

### Web and desktop

- **Security, web app:** signed in, a page load could upload an end-to-end encrypted shared collection to your own library, which the server
can read, before the app knew it was shared (and then delete it there). Nothing is saved to the library now until shared collections are
open, and one that was shared never goes there by itself, also when its files or the list of shared collections are damaged.
- A shared collection whose files are gone from the browser is read from the server again instead of being deleted for everyone.
- Desktop: Settings → Network: certificate authorities, a client certificate and a proxy for requests (never HITOP Cloud). While they can't be
used, requests fail with the reason. Certificate checks can be skipped only in the CLI (`--insecure`).
- Desktop: event streams show live (Stop ends them) and OAuth 2.0 authorization code signs in in the system browser (not in the Mac
Expand Down
34 changes: 32 additions & 2 deletions android/core/src/main/kotlin/tech/rws8/hitop/cloud/LibrarySync.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,38 @@ class LibrarySync(

var pushDelayMs = 1_000L
var retryDelayMs = 15_000L
var state: State = State.of(stateFile?.takeIf { it.exists() }?.let { runCatching { HitopJson.parseToJsonElement(it.readText()).jsonObject }.getOrNull() })
var state: State = State()
private set
/** The state file can't be opened now: nothing syncs and nothing is written over it. */
private var stateUnreadable = false

private fun loadState() {
stateUnreadable = false
val f = stateFile?.takeIf { it.exists() } ?: return
val text = try { f.readText() } catch (_: java.io.IOException) { stateUnreadable = true; return }
// Damaged: which collections stay on this phone only isn't known any more. As for another
// account, none is uploaded by itself (what the library has comes back by the pull).
state = runCatching { State.of(HitopJson.parseToJsonElement(text).jsonObject) }.getOrElse { State(account = "damaged") }
}
private var pushJob: Job? = null
private val roundLock = Mutex()
private var pushAgain = false

init {
loadState()
library.keepHere = { id ->
if (!isLocalOnly(id)) {
state = state.copy(localOnly = state.localOnly + id)
save()
}
}
_status.update { it.copy(lastSync = state.lastSync) }
library.onLibraryChange = { changed() }
refreshBadges()
}

private fun save() {
val f = stateFile ?: return
val f = stateFile?.takeIf { !stateUnreadable } ?: return
tech.rws8.hitop.core.SafeFiles.write(f, state.toJson().toString())
}

Expand Down Expand Up @@ -152,10 +170,22 @@ class LibrarySync(
refreshBadges()
return false
}
if (stateUnreadable) loadState()
if (library.sharingProblem?.damaged == false) library.reloadSharing?.invoke()
if (stateUnreadable || library.sharingProblem?.damaged == false) return false
if (state.account != key) {
state = firstLink(key, state, library.state.value.collections)
save()
}
library.sharingProblem?.let { p ->
// Every collection the library doesn't hold already may be a shared one: it stays on this
// phone only, and that is saved before the damaged list goes.
state = state.copy(localOnly = (state.localOnly + library.state.value.collections.map { it.id }.filter { "collection/$it" !in state.known }).distinct())
if (runCatching { save(); library.startSharingOver?.invoke() }.isFailure || library.sharingProblem != null) {
_status.update { it.copy(on = false, error = p.message) }
return false
}
}
_status.update { it.copy(on = true) }
return true
}
Expand Down
8 changes: 8 additions & 0 deletions android/core/src/main/kotlin/tech/rws8/hitop/core/Library.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ class Library(private val store: LibraryStore, private val secrets: SecretStore)
return v.filterKeys { n -> n in e!!.secrets && secrets.get(SecretStore.envKey(e.id, n)).isNullOrEmpty() }
}

/** Which collections are shared isn't known: nothing syncs until it is. */
@Volatile var sharingProblem: tech.rws8.hitop.sync.SharedListProblem? = null
var reloadSharing: (() -> Unit)? = null
/** Sets a damaged list aside (LibrarySync, once no collection can reach the library by it). */
var startSharingOver: (() -> Unit)? = null
/** A collection that stays on this phone only (LibrarySync). */
var keepHere: ((String) -> Unit)? = null

/** A collection was deleted here (SharedSync forgets its link). */
var onCollectionDeleted: ((String) -> Unit)? = null
/** The organization a new collection is filed under (null: personal). */
Expand Down
49 changes: 45 additions & 4 deletions android/core/src/main/kotlin/tech/rws8/hitop/sync/SharedSync.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,17 @@ data class SharedState(
}
}

/**
* The list of shared collections is there but can't be used. Never taken as empty: an end-to-end
* encrypted collection would look like any other and go to the library, which the server can read.
*/
class SharedListProblem(val damaged: Boolean, cause: Throwable) : Exception("The list of shared collections can't be read, so nothing is synced.", cause)

interface SharedSyncStore {
/** Throws [SharedListProblem]. */
fun load(): SharedState
/** A damaged list out of the way, kept beside. */
fun setAsideDamaged() {}
fun save(s: SharedState)
fun files(ws: String): Map<String, String>
fun saveFiles(ws: String, files: Map<String, String>)
Expand All @@ -107,7 +116,18 @@ class FileSharedSyncStore(private val root: File) : SharedSyncStore {
tech.rws8.hitop.core.SafeFiles.write(f, text)
}

override fun load() = SharedState.of(runCatching { HitopJson.parseToJsonElement(stateFile.readText()).jsonObject }.getOrNull())
override fun load(): SharedState {
if (!stateFile.exists()) return SharedState()
val text = try { stateFile.readText() } catch (e: java.io.IOException) { throw SharedListProblem(false, e) }
return try {
val o = HitopJson.parseToJsonElement(text).jsonObject
o.getValue("links").jsonObject.values.forEach { require(it.jsonObject.str("workspace").isNotEmpty()) }
SharedState.of(o)
} catch (e: RuntimeException) {
throw SharedListProblem(true, e)
}
}
override fun setAsideDamaged() { tech.rws8.hitop.core.SafeFiles.setAside(stateFile) }
override fun save(s: SharedState) = write(stateFile, s.toJson().toString())
override fun files(ws: String) = runCatching { HitopJson.parseToJsonElement(filesFile(ws).readText()).jsonObject.mapValues { (it.value as JsonPrimitive).content } }.getOrDefault(emptyMap())
override fun saveFiles(ws: String, files: Map<String, String>) = write(filesFile(ws), JsonObject(files.mapValues { JsonPrimitive(it.value) }).toString())
Expand Down Expand Up @@ -182,7 +202,7 @@ class SharedSync(private val cloud: HitopCloud, private val library: Library, pr
val pendingTrust = MutableStateFlow<SyncCore.KeyRefusal?>(null)

var pushDelayMs = 1_000L
var state: SharedState = store.load()
var state: SharedState = SharedState()
private set
private val pending = HashMap<String, Job>()
private val running = HashSet<String>()
Expand All @@ -204,7 +224,25 @@ class SharedSync(private val cloud: HitopCloud, private val library: Library, pr
saveTeamState()
}

private fun loadList() {
try {
state = store.load()
library.sharingProblem = null
} catch (e: SharedListProblem) {
state = SharedState()
library.sharingProblem = e
}
applyRoles()
}

init {
loadList()
library.reloadSharing = { loadList() }
library.startSharingOver = {
store.setAsideDamaged()
loadList()
notice(SharedNotice("The list of shared collections on this phone was damaged", "Their copies here are kept on this phone only. Open them again under Shared with you."))
}
loadTeamState()
library.onTeamChange = { saveTeamState(); scheduleTeam() }
library.onSharedChange = { schedule(it) }
Expand All @@ -214,7 +252,7 @@ class SharedSync(private val cloud: HitopCloud, private val library: Library, pr
state.links.forEach { (id, l) -> setConflicts(id, conflictList(id, l)) }
}

private fun save() = store.save(state)
private fun save() { if (library.sharingProblem == null) store.save(state) }
private fun status(id: String, f: (Status) -> Status) = _statuses.update { it + (id to f(it[id] ?: Status())) }
private fun setConflicts(id: String, list: List<SharedConflict>?) = _conflicts.update { if (list == null) it - id else it + (id to list) }
private fun notice(n: SharedNotice) = _notices.update { if (n in it) it else listOf(n) + it }
Expand Down Expand Up @@ -252,6 +290,8 @@ class SharedSync(private val cloud: HitopCloud, private val library: Library, pr

/** The signed-in account's links; another account's are kept, not synced (`gone`). This device's own key is pinned. */
fun checkAccount(): Boolean {
if (library.sharingProblem?.damaged == false) loadList()
if (library.sharingProblem != null) return false
val a = cloud.account ?: return false
val secret = cloud.deviceSecret() ?: return false
val key = cloud.accountKey
Expand Down Expand Up @@ -1006,10 +1046,11 @@ class SharedSync(private val cloud: HitopCloud, private val library: Library, pr
syncNow(id)
}

/** Deletes the shared collection for everyone; it stays on this phone as an unshared one. */
/** Deletes the shared collection for everyone. It was end-to-end encrypted: it stays on this phone only, not in the library. */
suspend fun deleteWorkspace(id: String) {
val l = live(id)
api("DELETE", "/v1/workspaces/${l.workspace}")
library.keepHere?.invoke(id)
forget(id)
library.onLibraryChange?.invoke()
runCatching { refreshWorkspaces() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,68 @@ class ReliabilityTest {
assertNotNull(other.lib.state.value.collection(c.id))
assertEquals(2, dir.walkTopDown().count { it.name.contains(".damaged-") })
}

/** A list of shared collections that can't be used never lets one reach the readable library. */
@Test
fun aDamagedListOfSharedCollectionsUploadsNone() = runBlocking {
val dir = Files.createTempDirectory("lib").toFile()
val fake = FakeCloud()
val secrets = MemorySecretStore()
val settings = MemoryCloudSettingsStore(CloudSettings(server = FakeCloud.SERVER))
fun shared(p: Phone) = tech.rws8.hitop.sync.SharedSync(p.cloud, p.lib, tech.rws8.hitop.sync.FileSharedSyncStore(dir), CoroutineScope(SupervisorJob() + Dispatchers.Default)).also { it.pushDelayMs = 3_600_000 }
val one = Phone(dir, fake, secrets, settings)
one.lib.seedShopApi()
one.cloud.startBrowserSignIn("github", FakeCloud.SERVER)
one.cloud.finishBrowserSignIn(fake.approve())
one.sync.sync()
one.sync.flush()
val plain = one.lib.state.value.collections.first { it.name == "shop-api" }.id
val secret = one.lib.addCollection("secret")
val store = tech.rws8.hitop.sync.FileSharedSyncStore(dir)
store.save(tech.rws8.hitop.sync.SharedState(account = one.cloud.accountKey, links = mapOf(secret.id to tech.rws8.hitop.sync.SharedLink("ws", "owner"))))
val file = File(dir, "shared-sync.json")
val good = file.readText()

// Can't be opened now (a folder in its place): nothing syncs until it can.
file.delete()
file.mkdir()
val two = Phone(dir, fake, secrets, settings)
shared(two)
assertEquals(false, two.lib.sharingProblem?.damaged)
two.sync.sync()
assertFalse("collection/${secret.id}" in two.sync.state.known)
file.delete()
file.writeText(good)
two.sync.sync()
assertNull(two.lib.sharingProblem)
assertTrue(two.lib.isShared(secret.id))
assertFalse("collection/${secret.id}" in two.sync.state.known)

// Damaged: kept beside, and the collection stays on this phone only, also after another start.
for (bad in listOf("{", "{}", """{"links":{"1":3}}""")) {
file.writeText(bad)
val three = Phone(dir, fake, secrets, settings)
val s = shared(three)
assertEquals(true, three.lib.sharingProblem?.damaged)
three.sync.sync()
three.sync.flush()
assertNull(three.lib.sharingProblem)
assertTrue(s.notices.value.isNotEmpty())
assertFalse("collection/${secret.id}" in three.sync.state.known)
assertTrue(three.sync.isLocalOnly(secret.id))
assertTrue("collection/$plain" in three.sync.state.known)
assertFalse(three.sync.isLocalOnly(plain))
}
assertEquals(3, dir.listFiles()!!.count { it.name.startsWith("shared-sync.json.damaged-") })
// The library's own state damaged: nothing new goes by itself.
val mine = two.lib.addCollection("only here")
File(dir, "library-sync.json").writeText("{")
val four = Phone(dir, fake, secrets, settings)
shared(four)
four.sync.sync()
four.sync.flush()
assertFalse("collection/${mine.id}" in four.sync.state.known)
assertFalse("collection/${secret.id}" in four.sync.state.known)
assertTrue("collection/$plain" in four.sync.state.known)
}
}
8 changes: 8 additions & 0 deletions cloud/ops-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,11 @@ and on hitop.rws8.tech/cloud/healthz. -->
- Portal from 2f69a78 (`cloud/portal` dist only; the rest of /var/www/hitop checked byte for byte untouched; old assets kept). A `?server=`
link asks before signing out and the sign-in page names a server that isn't HITOP Cloud: checked live in a browser.
Backup `/var/www/hitop-cloud.bak-20261125-033333`.

## 2026-11-25 Web app: shared collections never reach the library (security)

- Web app only, from 8da867a (PR 40; the owner's OK the same day), 16:14 UTC; backup `/var/www/hitop-app.bak-20261125-161434`. Old assets
kept; the rest of /var/www/hitop checked untouched; every file live equals the build, which passed the `shared-library` and `library` suites.
- It carries everything in the web app since 96f90df. gRPC calls with several client messages from the web need the newer hitop-server (C9).
- Not cleaned: `request_history` rows of leaked copies, and backups.
- Rollback (brings the leak back): `sudo rsync -a --delete /var/www/hitop-app.bak-20261125-161434/ /var/www/hitop/app/`.
14 changes: 13 additions & 1 deletion docs/PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Status is kept in the table at the end; choices made on the way go under "Decisi
| C3 | on main 193350a (PRs 23-27, every check green): run cancel, OAuth windows, desktop streams and OAuth, dialogs, portal (deployed), store.js and hitop-app.js split |
| C4 | in progress: CLI TLS options on main a9c1a18 (PR 28); gRPC client/bidi streaming on main 5801dac (PR 29); MCP gRPC tools and sync --json on main 2dc2dc8 (PR 30); OAuth refresh in core, Android and desktop (PR 31), desktop network settings and WebSocket/gRPC TLS tests built (CI pending); open: interactive streaming in the apps (they send all messages, then close), iOS TLS |
| C5 | core, CLI, web, desktop and Android on main 17ab888 (PR 33); iOS in C6 |
| C6 | in progress: import and export (PR 34), OAuth/SigV4/Digest (PR 35) on main; uploads, data files, compare/undo (PR 36) on main; settings and TLS built (CI pending); open: share extension, background sync, schedules, roles, comments, team environments, SSO |
| C6 | in progress: import and export (PR 34), OAuth/SigV4/Digest (PR 35) on main; uploads, data files, compare/undo (PR 36) on main; settings and TLS (PR 37), share extension, background sync and schedules (PR 38), roles, comments, team environments, SSO built (CI pending) |
| C7–C9 | not started |

## Decisions
Expand All @@ -69,3 +69,15 @@ Status is kept in the table at the end; choices made on the way go under "Decisi
| 2026-11-25 | Insomnia, Bruno and HAR are turned into Postman's shape and go through its importer. | One importer and report for every app. Bruno's newer YAML layout (opencollection) is not read. |
| 2026-11-25 | Bruno scripts are kept as comments; simple assertions become tests. | Its script API is not HITOP's; running it would fail every request. |
| 2026-11-25 | Main b8a2300 (PR 34) was merged with a failed iOS check, against the rule: the merge command did not stop on it. Merges now go through a script that asks GitHub for every check run. | The failure was the new import UI test; fixed with PR 35. |
- iOS schedules: BGTaskScheduler, so a run is "not before", often much later; a run known to take under 8 s also goes in the short refresh.
A run iOS stops is not recorded and counts as started (its requests aren't sent again at once). It never runs with another environment
or without secrets the Keychain can't show.
- iOS share extension only puts the item in the app group (an extension can't open its app); the app shows it before anything is added.
- A damaged list of shared collections is set aside only after every collection the library doesn't hold is marked "this device only".

## Open problems

- Android `ProtocolFlowTest.grpcFieldsAndAnUnreachableServer` (API 31 emulator), failed once on main 8da867a (2026-11-25): "Calling…" for more than
30 s although hitop-core's connect limit is 10 s (6c94353). Not reproduced and not explained; not to be hidden by a longer wait.
- Leaked copies of shared collections (web app before PR 40): `request_history` on the server keeps them after the library item is deleted.
Nothing is done on production without the owner's answer.
Loading
Loading