T09 · Insecure Skill Coding Practices
- Location
bin/_mfds_common.sh:45- Finding
Unrestricted Endpoint Override Exposes API Credentials and Sensitive Query Data
- Content
View full analysis
Vulnerability Details
File Location:
bin/_mfds_common.sh:45-47, 96; affected call sites includebin/drug.sh:33-47,bin/drug-easy.sh:33-49,bin/dur.sh:53-65, andbin/recall.sh:29-42
Vulnerability Type: Arbitrary destination credential forwarding and insecure transport
Risk Level: HighVulnerable Code
The shared argument parser accepts an arbitrary endpoint:
bash --endpoint) ENDPOINT="$2"; shift 2 ;;The shared request function sends the complete query string to that endpoint:
bash local body body="$(curl -fsSL --max-time 30 "${url}?${qs}")" || { echo "mfds-cli: request failed for $url" >&2 exit 1 }Every command constructs its URL from the unrestricted override and includes the API key in the query. For example, the DUR command contains:
bash URL="${ENDPOINT:-https://apis.data.go.kr/1471000/DURPrdlstInfoService03/$SUB}" QS="$(mfds_qs \ "serviceKey=$KEY" \ "pageNo=$PAGE" \ "numOfRows=$ROWS" \ "type=json" \ "itemName=${NAME}" \ "ingrName=${INGREDIENT}" \ "typeName=${TYPE_NAME}" \ )" mfds_request "$URL" "$QS" "dur"The other wrappers follow the same pattern:
bash URL="${ENDPOINT:-https://apis.data.go.kr/...}" QS="$(mfds_qs \ "serviceKey=$KEY" \ ... )" mfds_request "$URL" "$QS" "<record-type>"Technical Analysis
The
--endpointoption accepts any URL without validating its scheme, hostname, port, or trust relationship. The commands then automatically append the MFDS API key and all supplied search parameters to that URL.This permits an untrusted endpoint to receive:
- The user's
MFDS_API_KEY. - Drug and ingredient search terms.
- DUR queries that may expose health-related medication context.
- Product, manufacturer, and business-registration filters.
Because non-HTTPS URLs are not rejected, the same information can also be exposed through interception or modification on an untrusted network.
The arbitrary endpoint additionally creates a data-integrity pr ...[truncated 2403 chars]
- The user's
- Remediation
View remediation
Remediation Suggestions
-
Remove the endpoint override if it is not essential. Fixed official MFDS HTTPS endpoints provide the strongest least-privilege design.
-
If overrides are required, enforce an explicit allowlist. Parse the URL and require:
- Scheme exactly equal to
https. - Hostname exactly equal to
apis.data.go.kr. - No embedded username or password.
- No URL fragment.
- Only the expected port.
- A path matching an approved MFDS service prefix.
- Scheme exactly equal to
-
Do not forward
MFDS_API_KEYto nonstandard destinations. If development against a custom server is necessary, require a separate explicit test credential and a clearly named unsafe-development option. -
Fail closed on validation errors. Do not silently accept malformed URLs, redirects to untrusted hosts, or unsupported schemes.
-
Constrain redirects. Since
curl -Lfollows redirects, validate redirect destinations or disable redirects unless required. A trusted initial endpoint must not be allowed to redirect the credential-bearing request to an untrusted host. -
Reduce credential exposure in URLs where supported. Prefer an authorization header when the upstream API supports one. If MFDS requires a query parameter, ensure URLs are not logged and sanitize error reporting.
-
Separate request data by sensitivity. Warn users that medication names are transmitted to MFDS and advise against including patient names or other identifying data in search fields.
-
Authenticate data provenance where practical. Restricting the destination to the official HTTPS host is essential because normalized output may feed medication-safety decisions.
-
Add regression tests confirming rejection of:
http://endpoints.- Lookalike domains such as
apis.data.go.kr.attacker.example. - URLs with embedded credentials.
- Unexpected ports.
- Redirects to external hosts.
- Arbitrary attacker-controlled domains.
-
