Skip to content

feat: support configuring the linuxdo endpoint via environment variables - #2237

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:feature/linux-do-settings
Nov 16, 2025
Merged

feat: support configuring the linuxdo endpoint via environment variables#2237
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:feature/linux-do-settings

Conversation

@seefs001

@seefs001 seefs001 commented Nov 16, 2025

Copy link
Copy Markdown
Collaborator

#2197

Summary by CodeRabbit

  • Chores
    • LinuxDo OAuth endpoints are now configurable through environment variables, providing deployment flexibility while maintaining existing default values.

@coderabbitai

coderabbitai Bot commented Nov 16, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes externalize hard-coded Linux DO OAuth endpoints to environment variables. Two new configuration options are added to .env.example, and the linuxdo.go controller is updated to read these values from the environment with sensible defaults instead of using inline URLs.

Changes

Cohort / File(s) Summary
Environment Configuration
.env.example
Adds two new environment variables: LINUX_DO_TOKEN_ENDPOINT and LINUX_DO_USER_ENDPOINT for configuring Linux DO OAuth endpoints.
OAuth Controller
controller/linuxdo.go
Replaces hard-coded OAuth endpoint URLs with environment variable lookups using GetEnvOrDefaultString, defaulting to the original hard-coded values if not set.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Verify environment variable names match between .env.example and controller implementation
  • Confirm default values in the controller align with original hard-coded URLs
  • Check that GetEnvOrDefaultString function handles missing environment variables gracefully

Poem

🐰 Configuration hops and bounds,
No more hardcoded rounds,
Environment winds set the course,
Flexibility gains the force!
OAuth endpoints, now so free,

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: making LinuxDo endpoints configurable via environment variables, which aligns perfectly with the modifications in both .env.example and controller/linuxdo.go.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
.env.example (1)

70-72: Maintain consistency with the file's commenting pattern.

All other optional environment variables in this file are commented out (lines 1-69). The new Linux DO configuration should follow the same pattern to remain consistent.

Apply this diff:

 # LinuxDo相关配置
-LINUX_DO_TOKEN_ENDPOINT=https://connect.linux.do/oauth2/token
-LINUX_DO_USER_ENDPOINT=https://connect.linux.do/api/user
+# LINUX_DO_TOKEN_ENDPOINT=https://connect.linux.do/oauth2/token
+# LINUX_DO_USER_ENDPOINT=https://connect.linux.do/api/user
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 196fa13 and b6217b2.

📒 Files selected for processing (2)
  • .env.example (1 hunks)
  • controller/linuxdo.go (2 hunks)
🔇 Additional comments (1)
controller/linuxdo.go (1)

132-132: Implementation looks good.

The user endpoint configuration follows the same pattern as the token endpoint (line 87). The default value is appropriate and matches the configuration in .env.example.

Comment thread controller/linuxdo.go

// Get access token using Basic auth
tokenEndpoint := "https://connect.linux.do/oauth2/token"
tokenEndpoint := common.GetEnvOrDefaultString("LINUX_DO_TOKEN_ENDPOINT", "https://connect.linux.do/oauth2/token")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Consider the security implications of configurable OAuth endpoints.

The implementation correctly externalizes the token endpoint. However, allowing OAuth endpoints to be configured via environment variables means that anyone with access to modify these variables could redirect authentication flows to malicious servers.

This is acceptable for deployment-time configuration in trusted environments, but ensure that:

  • Access to environment variables is restricted to authorized personnel
  • Documentation warns about the security implications
  • Consider adding URL validation to ensure HTTPS is used

🌐 Web query:

Are there security best practices for configurable OAuth endpoints in Go applications?

💡 Result:

Yes — treat configurable OAuth endpoints as a high-risk configuration and apply defensive controls. Concise checklist for Go apps (with concrete mitigations):

  1. Require HTTPS and validate TLS (no plain HTTP). Enforce modern TLS ciphers and validate certs on outgoing requests. [1]
  2. Whitelist endpoints — do not accept arbitrary user-supplied discovery/redirect/resource URLs. Match redirect_uri exactly (no wildcards or relaxed rules). Store allowed endpoints in config or DB and validate at runtime. [1][2]
  3. Avoid untrusted dynamic discovery/registration unless the issuer is trusted; if you support it, restrict which hosts can be discovered and sanitize all returned endpoints to prevent SSRF, open-redirects, and unexpected callbacks. (Malicious-endpoint attacks are documented.) [3]
  4. Defend against SSRF/SSDT: validate/normalize URLs, restrict outbound targets by allowlist (hosts/IPs), block private-network IPs, and set short HTTP timeouts and size limits for requests to configured endpoints. [2][3]
  5. Enforce OAuth best practices: use Authorization Code + PKCE for public clients, short-lived access tokens, refresh-token rotation, scope least-privilege, and token introspection/revocation where appropriate. [1][2]
  6. Protect client credentials and tokens: store secrets in secure vaults or environment variables (never in code/repo), mark cookies HttpOnly/Secure/SameSite when used, avoid logging tokens, and rotate secrets periodically. [1][2]
  7. Authenticate and authorize endpoint changes: require strong admin auth/MFA, use RBAC for config edits, log and alert on configuration changes, and require review/approval for new endpoints. [2]
  8. Validate and sanitize all input returned by endpoints (JSON metadata, JWKS URLs, redirect URIs); verify JWT issuer/audience/signature and enforce expected token type and audience. Cache and validate JWKs with expiry/rotation checks. [1][2]
  9. Rate-limit and monitor: rate-limit auth/token endpoints and outbound discovery calls; collect telemetry and alert on unusual patterns (mass discovery, repeated failures, token reuse). [2]
  10. Use well-maintained libraries and follow platform guidance (e.g., golang.org/x/oauth2); keep dependencies up to date and audit them. Add unit/integration tests for config validation and adversarial endpoint values. [4]

Key references:

  • RFC 6819 — OAuth 2.0 Threat Model & Security Considerations. [1]
  • OWASP / API security guidance (whitelisting, SSRF, config hardening, least privilege). [2]
  • "Malicious Endpoints" attacks on OIDC/OpenID Connect (discovery/dynamic registration risks). [3]
  • Go oauth2 package repo / docs (use maintained libs). [4]

If you want, I can: (a) translate these into a Go implementation checklist/code snippets (URL validation, allowlist enforcement, SSRF-safe HTTP client), or (b) review a sample config file and point out issues. Which would you prefer?


🏁 Script executed:

#!/bin/bash
# Examine controller/linuxdo.go for OAuth endpoint handling
echo "=== Checking lines 70-150 in controller/linuxdo.go ==="
cat controller/linuxdo.go | head -150 | tail -80

Length of output: 2318


🏁 Script executed:

#!/bin/bash
# Check GetEnvOrDefaultString implementation in common package
echo "=== Finding GetEnvOrDefaultString implementation ==="
find . -type f -name "*.go" | xargs grep -l "GetEnvOrDefaultString" | head -5
echo ""
echo "=== Common package location ==="
find . -path "*/common/*.go" -type f | head -3

Length of output: 230


🏁 Script executed:

#!/bin/bash
# Examine GetEnvOrDefaultString implementation
echo "=== common/env.go content ==="
cat common/env.go

Length of output: 903


Add URL validation and HTTPS enforcement for OAuth endpoints.

The implementation exposes a critical security vulnerability: configurable OAuth endpoints are accepted from environment variables with no validation. This allows anyone with env var access to redirect authentication flows to malicious servers and intercept credentials.

Required fixes (lines 87 & 132 in controller/linuxdo.go):

  • Enforce HTTPS for all endpoints (reject http://)
  • Validate endpoint URLs match an allowlist of trusted hosts (e.g., connect.linux.do only)
  • Add SSRF defenses: block requests to private/internal IPs (127.0.0.1, 10.0.0.0/8, etc.)

This aligns with OAuth 2.0 security best practices (RFC 6819) and OWASP guidance. Deployment flexibility should not come at the cost of credential theft vulnerability.

🤖 Prompt for AI Agents
In controller/linuxdo.go around lines 87 and 132, the environment-provided OAuth
endpoints are used without validation; update both places to (1) parse the
environment value as a URL and require scheme == "https", (2) enforce an
allowlist for the host (exact match or safe subdomain policy, e.g.
"connect.linux.do" only), (3) reject raw IP literals and perform DNS resolution
of the hostname and validate all resolved IPs are not in private, loopback,
link-local, or other reserved ranges (e.g. 127.0.0.0/8, 10.0.0.0/8,
172.16.0.0/12, 192.168.0.0/16, ::1, fc00::/7, fe80::/10), and (4) return an
error (and fail startup or skip the override) when any of these checks fail so
only HTTPS allowlisted public endpoints are accepted.

@Calcium-Ion
Calcium-Ion merged commit 68777bf into QuantumNous:main Nov 16, 2025
1 check passed
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
…ttings

feat: support configuring the linuxdo endpoint via environment variables
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
…ttings

feat: support configuring the linuxdo endpoint via environment variables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants