Skip to content
Open
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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ The server binary supports various options to customize your instance. Each of t

- `host` (default: `localhost:9159`) -- the hostname the server should listen on.
- `token` (default: `<blank>`) -- the proxy Access Token used to restrict access to the server (feature disabled if left blank).
- `base-url` (default: `https://hoppscotch.io/`) -- the url of the hoppscotch instance (if the request origin is not an allowed origin, there is a redirect to hoppscotch base-url).
- `allowed-origins` (default: `*`) -- a comma separated list of allowed origins (for the Access-Control-Allow-... (CORS) headers) (use * to permit any)
- `banned-outputs` (default: `<blank>`) -- a comma separated list of values to redact from responses (feature disabled if left blank).
- `banned-dests` (default: `<blank>`) -- a comma separated list of destination hosts to prevent access to (feature disabled if left blank).
Expand All @@ -105,6 +106,7 @@ The container exposes the proxy through port `9159`.

Environment Variables the container accepts:
- `PROXYSCOTCH_TOKEN` (default: `<blank>`) -- the proxy Access Token used to restrict access to the server (feature disabled if left blank).
- `PROXYSCOTCH_BASE_URL` (default: `https://hoppscotch.io/`) -- the url of the hoppscotch instance (if the request origin is not an allowed origin, there is a redirect to hoppscotch base-url)
- `PROXYSCOTCH_ALLOWED_ORIGINS` (default: `*`) -- a comma separated list of allowed origins (for the Access-Control-Allow-... (CORS) headers) (use * to permit any)
- `PROXYSCOTCH_BANNED_OUTPUTS` (default: `<blank>`) -- a comma separated list of values to redact from responses (feature disabled if left blank).
- `PROXYSCOTCH_BANNED_DESTS` (default: `<blank>`) -- a comma separated list of destination hosts to prevent access to (feature disabled if left blank).
Expand All @@ -115,14 +117,15 @@ You can provide these values to the container as follows:
```sh
docker run -d \
-e PROXYSCOTCH_TOKEN=<token> \
-e PROXYSCOTCH_BASE_URL=<base_url> \
-e PROXYSCOTCH_ALLOWED_ORIGINS=<allowed_origins> \
-e PROXYSCOTCH_BANNED_OUTPUTS=<banned_outputs> \
-e PROXYSCOTCH_BANNED_DESTS=<banned_dests> \
-p <host_port>:9159 \
hoppscotch/proxyscotch:v0.1.4
```

- Via `docker-commpose`:
- Via `docker-compose`:
```yaml
# docker-compose.yml

Expand Down
11 changes: 10 additions & 1 deletion container_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Default values
DEFAULT_TOKEN=""
DEFAULT_BASE_URL="https://hoppscotch.io/"
DEFAULT_ALLOWED_ORIGINS="*"
DEFAULT_BANNED_OUTPUTS=""
DEFAULT_BANNED_DESTS=""
Expand All @@ -24,6 +25,14 @@ elif [ -n "${DEFAULT_TOKEN}" ]; then
TOKEN_ARG="--token=${DEFAULT_TOKEN}"
fi

# Process base-url of hoppscotch instance
BASE_URL_ARG=""
if [ -n "${PROXYSCOTCH_BASE_URL}" ]; then
BASE_URL_ARG="--base-url=${PROXYSCOTCH_BASE_URL}"
else
BASE_URL_ARG="--base-url=${DEFAULT_BASE_URL}"
fi

# Process allowed-origins - Support both ALLOWED_ORIGINS and PROXYSCOTCH_ALLOWED_ORIGINS
if [ -n "${ALLOWED_ORIGINS}" ]; then
ORIGINS_ARG="--allowed-origins=${ALLOWED_ORIGINS}"
Expand All @@ -50,4 +59,4 @@ elif [ -n "${DEFAULT_BANNED_DESTS}" ]; then
fi

# Execute the command with the arguments
proxyscotch $HOST_ARG $TOKEN_ARG $ORIGINS_ARG $BANNED_OUTPUTS_ARG $BANNED_DESTS_ARG
proxyscotch $HOST_ARG $TOKEN_ARG $BASE_URL_ARG $ORIGINS_ARG $BANNED_OUTPUTS_ARG $BANNED_DESTS_ARG
5 changes: 4 additions & 1 deletion libproxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type statusChangeFunction func(status string, isListening bool)

var (
accessToken string
baseUrl string
sessionFingerprint string
allowedOrigins []string
bannedOutputs []string
Expand Down Expand Up @@ -186,6 +187,7 @@ func isAllowedOrigin(origin string) bool {
func Initialize(
initialAccessToken string,
proxyURL string,
initialBaseURL string,
initialAllowedOrigins string,
initialBannedOutputs string,
initialBannedDests string,
Expand Down Expand Up @@ -237,6 +239,7 @@ func Initialize(
}

accessToken = initialAccessToken
baseUrl = initialBaseURL
sessionFingerprint = uuid.New().String()

InfoLogger.Println("Starting proxy server...")
Expand Down Expand Up @@ -421,7 +424,7 @@ func proxyHandler(response http.ResponseWriter, request *http.Request) {
return
}

response.Header().Add("Location", "https://hoppscotch.io/")
response.Header().Add("Location", baseUrl)
response.WriteHeader(301)
InfoLogger.Printf("Redirected request from %s with disallowed origin: %s", clientIP, sanitizeLogInput(origin))
return
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func onExit() {
}

func runHoppscotchProxy() {
libproxy.Initialize("hoppscotch", "127.0.0.1:9159", "https://hoppscotch.io", "", "", onProxyStateChange, true, nil)
libproxy.Initialize("hoppscotch", "127.0.0.1:9159", "https://hoppscotch.io/", "https://hoppscotch.io", "", "", onProxyStateChange, true, nil)
}

func onProxyStateChange(status string, isListening bool) {
Expand Down
3 changes: 2 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import (
func main() {
hostPtr := flag.String("host", "localhost:9159", "the hostname that the server should listen on.")
tokenPtr := flag.String("token", "", "the Proxy Access Token used to restrict access to the server.")
baseUrlPtr := flag.String("base-url", "https://hoppscotch.io/", "the url of the hoppscotch instance.")
allowedOriginsPtr := flag.String("allowed-origins", "*", "a comma separated list of allowed origins.")
bannedOutputsPtr := flag.String("banned-outputs", "", "a comma separated list of banned outputs.")
bannedDestsPtr := flag.String("banned-dests", "", "a comma separated list of banned proxy destinations.")

flag.Parse()

finished := make(chan bool)
libproxy.Initialize(*tokenPtr, *hostPtr, *allowedOriginsPtr, *bannedOutputsPtr, *bannedDestsPtr, onProxyStateChangeServer, false, finished)
libproxy.Initialize(*tokenPtr, *hostPtr, *baseUrlPtr, *allowedOriginsPtr, *bannedOutputsPtr, *bannedDestsPtr, onProxyStateChangeServer, false, finished)

<-finished
}
Expand Down
Loading