vrtmrz / obsidian-livesync

MIT License
4.84k stars 160 forks source link

CORS again #508

Open thany opened 2 weeks ago

thany commented 2 weeks ago

Abstract

It's doing CORS errors again. The server is configured correctly though, this time.

Expected behaviour

Actually happened

Reproducing procedure

  1. Latest CouchDB
  2. CORS enabled, on all domains
  3. Sync it

Report from the LiveSync

For more information, please refer to Making the report.

Report from hatch ``` ---- Obsidian info ---- Navigator: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) obsidian/1.6.7 Chrome/124.0.6367.243 Electron/30.1.2 Safari/537.36 FileSystem: insensitive ---- remote config ---- Requesting information from the remote CouchDB has failed. If you are using IBM Cloudant, this is normal behaviour. ---- Plug-in config --- version:0.23.22 remoteType: "" useCustomRequestHandler: false couchDB_URI: self-hosted(HTTPS) couchDB_USER: 𝑅𝐸𝐷𝐴𝐢𝑇𝐸𝐷 couchDB_PASSWORD: 𝑅𝐸𝐷𝐴𝐢𝑇𝐸𝐷 couchDB_DBNAME: 𝑅𝐸𝐷𝐴𝐢𝑇𝐸𝐷 liveSync: false syncOnSave: false syncOnStart: false savingDelay: 200 lessInformationInLog: false gcDelay: 0 versionUpFlash: "" minimumChunkSize: 20 longLineThreshold: 250 showVerboseLog: true suspendFileWatching: false trashInsteadDelete: true periodicReplication: false periodicReplicationInterval: 60 syncOnFileOpen: false encrypt: false passphrase: 𝑅𝐸𝐷𝐴𝐢𝑇𝐸𝐷 usePathObfuscation: false doNotDeleteFolder: false resolveConflictsByNewerFile: false batchSave: false batchSaveMinimumDelay: 5 batchSaveMaximumDelay: 60 deviceAndVaultName: "" usePluginSettings: false showOwnPlugins: false showStatusOnEditor: true showStatusOnStatusbar: true showOnlyIconsOnEditor: false usePluginSync: false autoSweepPlugins: false autoSweepPluginsPeriodic: false notifyPluginOrSettingUpdated: false checkIntegrityOnSave: false batch_size: 50 batches_limit: 40 useHistory: true disableRequestURI: true skipOlderFilesOnSync: true checkConflictOnlyOnOpen: false showMergeDialogOnlyOnActive: false syncInternalFiles: true syncInternalFilesBeforeReplication: false syncInternalFilesIgnorePatterns: \/node_modules\/, \/\.git\/, \/obsidian-livesync\/ syncInternalFilesInterval: 60 additionalSuffixOfDatabaseName: 923dd4a9cb007396 ignoreVersionCheck: false lastReadUpdates: 23 deleteMetadataOfDeletedFiles: false syncIgnoreRegEx: "" syncOnlyRegEx: "" customChunkSize: 0 readChunksOnline: true watchInternalFileChanges: true automaticallyDeleteMetadataOfDeletedFiles: 0 disableMarkdownAutoMerge: false writeDocumentsIfConflicted: false useDynamicIterationCount: false syncAfterMerge: false configPassphraseStore: "" encryptedPassphrase: 𝑅𝐸𝐷𝐴𝐢𝑇𝐸𝐷 encryptedCouchDBConnection: 𝑅𝐸𝐷𝐴𝐢𝑇𝐸𝐷 permitEmptyPassphrase: false useIndexedDBAdapter: true useTimeouts: false writeLogToTheFile: false doNotPaceReplication: false hashCacheMaxCount: 300 hashCacheMaxAmount: 50 concurrencyOfReadChunksOnline: 100 minimumIntervalOfReadChunksOnline: 333 hashAlg: xxhash64 suspendParseReplicationResult: false doNotSuspendOnFetching: false useIgnoreFiles: false ignoreFiles: .gitignore syncOnEditorSave: false pluginSyncExtendedSetting: {} syncMaxSizeInMB: 50 settingSyncFile: "" writeCredentialsForSettingSync: false notifyAllSettingSyncFile: false isConfigured: true settingVersion: 10 enableCompression: false accessKey: 𝑅𝐸𝐷𝐴𝐢𝑇𝐸𝐷 bucket: 𝑅𝐸𝐷𝐴𝐢𝑇𝐸𝐷(0 letters) endpoint: Not configured or AWS region: 𝑅𝐸𝐷𝐴𝐢𝑇𝐸𝐷(4 letters) secretKey: 𝑅𝐸𝐷𝐴𝐢𝑇𝐸𝐷 useEden: false maxChunksInEden: 10 maxTotalLengthInEden: 1024 maxAgeInEden: 10 disableCheckingConfigMismatch: false displayLanguage: "" enableChunkSplitterV2: false disableWorkerForGeneratingChunks: false processSmallFilesInUIThread: false notifyThresholdOfRemoteStorageSize: 0 usePluginSyncV2: false usePluginEtc: false handleFilenameCaseSensitive: false doNotUseFixedRevisionForChunks: false showLongerLogInsideEditor: false sendChunksBulk: true sendChunksBulkMaxSize: 25 configPassphrase: "" preset: "" syncMode: ONEVENTS dummy: 0 ```

Obsidian debug info

Debug info ``` ```

Plug-in log

We can see the log by tapping the Document box icon. If you noticed something suspicious, please let me know. Note: Please enable Verbose Log. For detail, refer to Logging, please.

Plug-in log ``` ```

Network log

07/10/2024, 10:37:07->HTTP:GET to:/ -> failed
07/10/2024, 10:37:07->TypeError:Failed to fetch
07/10/2024, 10:37:07->TypeError:Failed to fetch
07/10/2024, 10:37:07->Could not connect to 𝑅𝐸𝐷𝐴𝐢𝑇𝐸𝐷: TypeError:Failed to fetch
**Note** This error caused by many reasons. The only sure thing is you didn't touch the server.
To check details, open inspector.
07/10/2024, 10:37:07->Could not connect to server.

Screenshots

Bog standard configuration in CouchDB webUI. This is done with the UI, I did not input these values manually at any point. image

Result in inspector: image

thany commented 1 week ago

Update: turns out it wasn't a CORS issue, but a server configuration issue. Somehow my reverse proxy stopped working, causing the proxy to display a 502, which on its turn doesn't support CORS, obviously.

But it's still a problem:

Bottomline: this shouldn't ever happen. Especially since CouchDB has a tendency to forget CORS settings at some point for some reason. Awful behaviour, but that's why CORS issues can "suddenly" pop up.

vrtmrz commented 1 week ago

Thanks for pointing that out! Please allow me a slightly longer answer. Yes, this is a deep-rooted problem with a history. I have summarised it here.

The app just says "no, figure it out" and doesn't provide any detailed information whatsoever unless you really dig for it - and know how to dig for it. The log should list important information needed to resolve the issue, especially if it's a genuine CORS issue.

I completely understand your frustration. Unfortunately, this is due to the behaviour of the CORS errors. We cannot observe anything, not even their response code. A rather helpless situation. This is because we have been identified as something potentially and possibly evil.

It shouldn't use CORS in the first place. CORS is for website-to-website communication, and this is a desktop/mobile app. Even though it is built on web tech, it is still a standalone app. This is probably for the Obsidian devs, but it would be better if you, Livesync dev(s), would collaborate with Obsidian on this - I don't feel like I should be a middleman here.

As you mentioned, there is a way to actually send a request via the Obsidian API, which is not a web standard. However, there are some reasons to avoid using them from this plug-in:

So, they are already working hard for us. We are just in on a bit of a niche.

Hence, using them can only be an optional feature with many downsides. And indeed has been in the past. The feature requires giving up LiveSync and only Periodic must be used.

I think we can see the same bad omen for the problem the situation caused, with my explanation, and the other issues involved. This option was finally removed in earlier releases due to "complication of the configuration dialogue" and "synchronisation problems". This was essentially an edge case feature, but because it promoted ease of use, it caused other problems that resulted from it, complicating the configuration and the situation. I have to swallow my shame, but you know the nightmare.

As you know, there are too many edge cases to simplify things. I wish I could express that my position and perspective are the same as yours. ...... I'm one of the contributors, but I'm also one of the users; I've been using it the longest, and I'm very dependent on it. (Ah, maybe that's why I'm so used to the terrible UI. Now I realise that I am starving for the new flavours).

If you have a good idea of how to implement this in the setting dialogue, please let me know. It could be quite helpful, even if it is just an image. (Using Obsidian's API cannot be enabled from the interface and is automatically disabled, but still works).