Skip to content

Commit 8f353db

Browse files
authored
Disable webaudio whitelist and add pls files to blacklisted filetypes (#69)
* add convar and hook to disable whitelist and file checking * use hooks instead of convars for file content check * add new check to checkStreamContents * remove unused convars * return when onError called for checkStreamContents * include id in error message for checking stream content * whitespace changes * whitespace changes
1 parent 7a2bdb1 commit 8f353db

2 files changed

Lines changed: 30 additions & 9 deletions

File tree

lua/autorun/webaudio.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,9 @@ local function isWhitelistedURL(url)
681681
if not isstring(url) then return false end
682682
url = url:Trim()
683683

684+
local isWhitelisted = hook.Run("WA_IsWhitelistedURL", url)
685+
if isWhitelisted ~= nil then return isWhitelisted end
686+
684687
local relative = url:match("^https?://www%.(.*)") or url:match("^https?://(.*)")
685688
if not relative then return false end
686689

@@ -797,4 +800,4 @@ else
797800
include("webaudio/interface.lua")
798801
end
799802

800-
return WebAudio.Common
803+
return WebAudio.Common

lua/webaudio/receiver.lua

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,29 @@ timer.Create("wa_think", 100 / 1000, 0, function()
9090
end
9191
end)
9292

93+
---@param url string
94+
---@param onSuccess fun()
95+
---@param onError fun(err: string)
96+
local function checkStreamContents(url, onSuccess, onError)
97+
if hook.Run("WA_ShouldCheckStreamContent", url) == false then
98+
return onSuccess()
99+
end
100+
101+
http.Fetch(url, function(body, _, _)
102+
if body:find("#EXTM3U", 1, true) then
103+
return onError("Cannot create stream with unwhitelisted file format (m3u)")
104+
end
105+
106+
if body:find("[playlist]", 1, true) then
107+
return onError("Cannot create stream with unwhitelisted file format (pls)")
108+
end
109+
110+
onSuccess()
111+
end, function(err)
112+
onError("HTTP error:" .. err)
113+
end)
114+
end
115+
93116
net.Receive("wa_create", function(len)
94117
local id, url, owner = WebAudio.readID(), net.ReadString(), net.ReadEntity()
95118
local verbosity = Verbosity:GetInt()
@@ -141,12 +164,7 @@ net.Receive("wa_create", function(len)
141164

142165
notify("User %s(%s) created WebAudio object with url [%q]", owner:Nick(), owner:SteamID64() or "multirun", url)
143166

144-
http.Fetch(url, function(body, size, headers)
145-
if body:find("#EXTM3U", 1, true) then
146-
streamFailed()
147-
return warn("User %s(%s) tried to create WebAudio object with unwhitelisted file format (m3u)", owner:Nick(), owner:SteamID64() or "multirun")
148-
end
149-
167+
checkStreamContents(url, function()
150168
sound.PlayURL(url, "3d noblock noplay", function(bass, errid, errname)
151169
if errid then
152170
streamFailed()
@@ -209,7 +227,7 @@ net.Receive("wa_create", function(len)
209227
end)
210228
end, function(err)
211229
streamFailed()
212-
return warn("HTTP error when creating WebAudio receiver with id %d, Error [%q]", id, err)
230+
return warn("Error when creating WebAudio object with id: %s, User %s(%s), Error: %s", id, owner:Nick(), owner:SteamID64() or "multirun", err)
213231
end)
214232

215233
WebAudio.new(url, owner, nil, id) -- Register object
@@ -403,4 +421,4 @@ cvars.AddChangeCallback("wa_enable", function(convar, old, new)
403421
net.Start("wa_enable", true)
404422
net.WriteBool(enabled) -- Tell the server to subscribe/unsubscribe us from net messages
405423
net.SendToServer()
406-
end, "wa_enable")
424+
end, "wa_enable")

0 commit comments

Comments
 (0)