Cannot log in under a proxy environment - v5.6.2

proxy と agent を両方指定したら行けたという報告があるようです。

そちらの環境で直接デバッグ出来たら良いのですが、難しいですね。

@plugin-developer Does anyone have a web proxy environment? We are struggling to solve the strange error when it is behind a web proxy with v5.6.2. Any help would be appreciated.

If you are in a web proxy, please try running this with NodeJS 18.18.2 + axios 1.4.0:

const axios = require('axios')
const { HttpsProxyAgent } = require('https-proxy-agent');
const { HttpProxyAgent } = require('http-proxy-agent');

const apiConfig= {
  baseURL: 'https://api.inkdrop.app/',
  proxy: undefined,
  httpsAgent: new HttpsProxyAgent('http://PROXY_SERVER_URL/'),
  httpAgent: new HttpProxyAgent('http://PROXY_SERVER_URL_FOR_HTTP_SITES/')
}
const apiClient = axios.create(apiConfig)
apiClient.get('/').then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.error(error);
  })

and if you could reproduce an error, please let me know a workaround.

よく分からないんですが、 proxy に指定するポート番号でリクエストが飛んでいるようなので
↓ で プロキシを経由しなくても外に出られる端末を経由して 443 に書き換える proxy 経由でリクエストすると https://api.inkdrop.app/ からは ok が返ってきました。

package main

import (
	"fmt"
	"log"
	"net/http"
    "net"
	"github.com/elazarl/goproxy"
)

func main() {
    proxy_port := ":3128"
	proxy := goproxy.NewProxyHttpServer()
	proxy.Verbose = true
	proxy.OnRequest().DoFunc(
        func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
            fmt.Println("---------------------------")
            fmt.Println(r.RequestURI)
            // URL から現在のホストとポートを取得
            host, _, err := net.SplitHostPort(r.URL.Host)
            if err != nil {
                // ポートが明示されていない場合は、err が発生する可能性があります
                host = r.URL.Host
            }
            // ポート番号を変更(例えば、8080 に変更)
            newPort := "443"
            r.URL.Host = net.JoinHostPort(host, newPort)

            // プロキシを通してリクエストを継続
            return r, nil
        })

    fmt.Println(proxy_port)
	log.Fatal(http.ListenAndServe(proxy_port, proxy))
}

ただ、Inkdrop からは 200 で返ってくるものの

read ECONNRESET Please check your system configuration or report the problem.

でエラーになりました。

proxy のログ

2023/11/24 19:15:55 [001] INFO: Got request /account api.inkdrop.app:3128 GET https://api.inkdrop.app:3128/account?dataVersion
=4.7.0&clientVersion=5.6.2&encrypt=true
---------------------------
https://api.inkdrop.app:3128/account?dataVersion=4.7.0&clientVersion=5.6.2&encrypt=true
2023/11/24 19:15:55 [001] INFO: Sending request GET https://api.inkdrop.app:443/account?dataVersion=4.7.0&clientVersion=5.6.2&
encrypt=true
2023/11/24 19:15:56 [001] INFO: Received response 200 OK
2023/11/24 19:15:56 [001] INFO: Copying response to client 200 OK [200]
2023/11/24 19:15:56 [001] INFO: Copied 1024 bytes to client error=<nil>
2023/11/24 19:15:56 [002] INFO: Got request /account/api-keys/_e2ee api.inkdrop.app:3128 PUT https://api.inkdrop.app:3128/acco
unt/api-keys/_e2ee
---------------------------
https://api.inkdrop.app:3128/account/api-keys/_e2ee
2023/11/24 19:15:56 [002] INFO: Sending request PUT https://api.inkdrop.app:443/account/api-keys/_e2ee
2023/11/24 19:15:57 [002] INFO: Received response 200 OK
2023/11/24 19:15:57 [002] INFO: Copying response to client 200 OK [200]
2023/11/24 19:15:57 [002] INFO: Copied 307 bytes to client error=<nil>

うーん

よく分からなくなってきたんですが・・・。

const proxy_url = "会社のプロキシ"
const axios = require("axios");
const { HttpsProxyAgent } = require("https-proxy-agent");
const { HttpProxyAgent } = require("http-proxy-agent");

// キャッシュを無効にするヘッダーを設定
const noCacheHeaders = {
  "Cache-Control": "no-cache, no-store, must-revalidate",
  Pragma: "no-cache",
  Expires: "0",
};

const apiConfig = {
  baseURL: "https://api.inkdrop.app:443/",
  proxy: undefined,
  httpsAgent: new HttpsProxyAgent(proxy_url),
  httpAgent: new HttpProxyAgent(proxy_url),
  headers: noCacheHeaders,
};
const apiClient = axios.create(apiConfig);
apiClient
  .get("/")
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.error(error);
  });
  1. Inkdrop を起動してコンソールから 実行 → NG
  2. ターミナルから node index.js で実行 → OK
  3. 再度、Inkdrop のコンソールから実行 → OK

どちらにしても Inkdrop にログインはできないんですけど。

わかったかも

Can you please try this patch?

  • Upgraded axios to latest
  • Do not use ProxyAgents but use the environment variables instead to configure the proxy for axios

https://inkdrop-dist.s3.ap-northeast-1.amazonaws.com/tmp/Inkdrop-5.6.2-Windows_patch-1.zip

I’ve tested it with a web proxy server in my network and confiemd that it works properly.

ダメでした・・・。

一回目のログイン

Error message:
  socket hang up Please check your system configuration or report the problem.
Status code:
  N/A

二回目以降のログイン

Error message:
  Request failed with status code 407 - Sorry, possible under maintenance. Please try again later. Check our twitter @inkdrop_app for the current status.
Status code:
  407

それは謎ですね🤔 手元のWindows 11環境では上手くproxy経由でアクセス出来ています。
今一度 config.json を確認、ターミナルから実行、proxy設定が効いていることを確認してください。
それでも動かない場合は、shimizuさんが書いたpythonのスクリプトで得たログを見せていただけますか?

(一旦、今の状況ですが)
以前と同じで、 go の ↓ なローカル実行のプロキシを通すと、今回の patch でログインできました。
http_proxy と https_proxy は環境変数にあります。

package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/elazarl/goproxy"
)

func main() {
	port := ":3128"
	proxy := goproxy.NewProxyHttpServer()
	proxy.Verbose = true
	proxy.OnRequest().DoFunc(
		func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
			return r, nil
		})
	fmt.Println(port)
	log.Fatal(http.ListenAndServe(":3128", proxy))
}

config.json

      "network": {
        "http_proxy": "http://localhost:3128",
        "https_proxy": "http://localhost:3128"
      },

ログイン後は今回のパッチ無し exe で
プロキシを通常の会社プロキシに戻してもノートの同期ができます。

↓ config.json を戻す

      "network": {
        "http_proxy": "http://あかうんと%40どめいん:ぱすわーど@プロキシサーバー:8080",
        "https_proxy": "http://あかうんと%40どめいん:ぱすわーど@プロキシサーバー:8080"
      },
      "themes": [

  • パッチ版 → goプロキシ → APIサーバ

では上手くログイン出来るという事ですね。
アプリとgoのリクエストの違いはなんだろう。
少なくとも手元では動いているので、環境依存の問題の可能性が高いです。
socket hang upになったり407が出たり結果が変わるって事は、プロキシサーバ自体に接続できたり出来なかったりしている?

データベースとの通信はaxiosではなくnode-fetchを使っています。こちらの挙動は問題なさそうですね。
axiosはこの辺の動作が不安定なので将来的には全部node-fetchに乗り換えたい所ですが、改修範囲が広いので中長期的な計画になりそうです。

  • パッチ版 → goプロキシ → 会社プロキシ → APIサーバ

になるかと。

node で実行した場合と、inkdrop のコンソールで実行した場合とで影響を与えあってるようにも見えるので環境っぽいのですが、謎ですねぇ・・・・。

もうちょっと見てみます。

なるほど・・
Inkdropからとgo経由のリクエストのヘッダやペイロードの違いが分かったら教えてください。

Inkdropは定期的にセッションの確認をしているので、しばらくすると(確か30日後)再度ログインが必要になると思います。

The current fix has been landed in v5.6.3-beta.0.
But the app will eventually migrate the API module from Axios to node-fetch in the future.

1 Like

同じくProxy環境で、ログイン不可です。
正確にどのバージョンからかは、失念しました。
v5.6 で再ログインが発生して、Failed to authorize your account. になります。
このテストプログラムを実行すると、code: 'ERR_BAD_REQUEST' というエラーになります。
shimizu_tatsuya さんの投稿と同様で、_header: 'GET https://api.inkdrop.app:8080/ HTTP/1.1 という接続の形跡があります。
テストプログラムの7行目にある proxy: undefinedproxy: false に変更すると、status: 200 に変わりました。
これで何か、ご調査が進みますでしょうか。
ログインできなくて、少々、困っております。

@q1701 調査報告助かります!

proxy: false 指定すると通るという事ですね。今日の午後に早速パッチを当ててビルドしてみます。

1 Like

@q1701 @shimizu_tatsuya
ビルドしました。こちら試してみてもらえますか? https://inkdrop-dist.s3.ap-northeast-1.amazonaws.com/tmp/Inkdrop-5.6.3-beta.0-Windows_patch1.zip

1 Like

@craftzdog
ログインと同期ができました!
早速ありがとうございました。

1 Like

おお!!!!!良かったです。確認ありがとうございます!
Cheers

1 Like

僕もログイン&同期できるようになりました!
ありがとうございます!
(調査しようと思いつつ忙により手つかずでした・・・)

2 Likes

This fix has been landed in v5.7.0 :tada:

Thank you guys for helping me fix it!

2 Likes