T09 · Insecure Skill Coding Practices
- Location
scripts/moodle_client.py:55- Finding
Moodle access token may be exposed through insecure URL configuration and query-string authentication
- Content
View full analysis
None: self.base_url = self.base_url.rstrip("/") if not self.base_url: raise ValueError("base_url must not be empty") if not self.token: raise ValueError("token must not be empty") @classmethod def from_env( cls, rate_limit_seconds: float = 15.0, timeout_seconds: float = 30.0, ) -> "MoodleClient": base_url = os.environ.get("MOODLE_URL", "").strip() token = os.environ.get("MOODLE_TOKEN", "").strip() if not base_url: raise ValueError("MOODLE_URL is required") if not token: raise ValueError("MOODLE_TOKEN is required") return cls( base_url=base_url, token=token, rate_limit_seconds=rate_limit_seconds, timeout_seconds=timeout_seconds, ) @property def endpoint(self) -> str: return f"{self.base_url}/webservice/rest/server.php" def call(self, function: str, params: dict[str, Any] | None = None) -> Any: if not function: raise ValueError("function is required") request_params: dict[str, Any] = { "wstoken": self.token, "wsfunction": function, "moodlewsrestformat": "json", } request_params.update(flatten_params(params)) response = self.session.get( self.endpoint, params=request_params, timeout=self.timeout_seconds, ) ``` ### Technical Analysis The client accepts any nonempty `MOODLE_URL`; it does not parse the URL, require HTTPS, reject embedded credentials, or constrain the destination to a trusted Moodle host. The Moodle access token is then placed in the `wstoken` query parameter of an HTTP GET request. Consequently, the complete request URL contains the secret token. Query strings are commonly recorded by reve ...[truncated 2354 chars]- Remediation
View remediation
