-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lack of Anti-CSRF Protection in OpenWRT – /ubus Accepts Unauthorized Requests #7635
Comments
The CSRF would be difficult to add, especially given that requests order may be different, and may break many things. The LUCI admin panel usually is accessed only from LAN so if an attacker stole the sessionId it also needs to get into a local network. |
Also note that So in conclusion:
According to my understanding, CSRF protection generally should be employed for endpoints that receive authenticated requests where the browser will automatically send authentication credentials along with it, so primarily basic-auth and cookie protected endpoints. Considering this, it should be sufficient to drop the fallback to cookie provided session id in order to address this weakness: diff --git a/modules/luci-base/ucode/controller/admin/index.uc b/modules/luci-base/ucode/controller/admin/index.uc
index d433e1161e..471be0aaf6 100644
--- a/modules/luci-base/ucode/controller/admin/index.uc
+++ b/modules/luci-base/ucode/controller/admin/index.uc
@@ -56,9 +56,6 @@ function ubus_request(req) {
if (type(arg) != 'object' || exists(arg, 'ubus_rpc_session'))
return ubus_reply(req.id, null, -32602, 'Invalid parameters');
- if (sid == '00000000000000000000000000000000' && ctx.authsession)
- sid = ctx.authsession;
-
if (!ubus_access(sid, obj, fun))
return ubus_reply(req.id, null, -32002, 'Access denied');
After that, malicious actors would need to extract the proper session ID from the page source, which would require an XSS vulnerability or some other kind of exfiltration vector. If such a vulnerability is present, the malicious actor could also extract the proper CSRF token. |
Is there an existing issue for this?
screenshots or captures
Actual behaviour
During security testing with OWASP ZAP, an alert was triggered indicating Absence of Anti-CSRF Tokens in OpenWRT's
/ubus
API.The issue was classified as Risk: Medium with Confidence: Low by OWASP ZAP.
Upon further manual verification, it was confirmed that no CSRF protection mechanism is enforced, allowing API calls to be executed with just a valid
sessionid
.L.env
), bothsessionid
andtoken
are present.token
is never sent in any POST requests, meaning the API does not check for CSRF protection./ubus
are processed successfully as long as the attacker possesses thesessionid
.✅ Proof of Concept (PoC)
I successfully executed the following PowerShell script CSRF TEST:
🔹 Note: Replace SESSION_ID in the script above with the actual value of sessionid, which can be found in OpenWRT’s JavaScript frontend (L.env) or extracted from the sysauth_https session cookie in the browser.
As a result, the /etc/sysupgrade.conf file was modified, confirming that no CSRF validation occurs.
The tests were conducted both with and without an Nginx proxy, and the results remained the same.
Regardless of whether requests were sent directly to OpenWRT or proxied through Nginx, the API did not enforce CSRF protection.
If I misunderstood anything about the authentication or security model, please feel free to correct me. I appreciate any feedback!
Expected behaviour
/ubus
API should require a CSRF token to prevent unauthorized actions.Access Denied
.sessionid
should not be enough to execute API requests without additional verification.Steps to reproduce
1️⃣ Log into OpenWRT Web UI.
2️⃣ Open Developer Tools (
F12
) and locatesessionid
using one of the following methods:sessionid
inside the JavaScript objectL = new LuCI({...})
.LuCI
object wheresessionid
andtoken
are defined.3️⃣ Execute the PowerShell script above, replacing
SESSION_ID
with the extracted value.4️⃣ The request succeeds, modifying the router’s configuration with ## CSRF TEST.
Additional Information
What browsers do you see the problem on?
Firefox, Chrome, Microsoft Edge
Relevant log output
The text was updated successfully, but these errors were encountered: