Skip to content
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

Disable webaudio whitelist and add pls files to blacklisted filetypes #69

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lua/autorun/webaudio.lua
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,9 @@ local function isWhitelistedURL(url)
if not isstring(url) then return false end
url = url:Trim()

local isWhitelisted = hook.Run("WA_IsWhitelistedURL", url)
Vurv78 marked this conversation as resolved.
Show resolved Hide resolved
if isWhitelisted ~= nil then return isWhitelisted end

local relative = url:match("^https?://www%.(.*)") or url:match("^https?://(.*)")
if not relative then return false end

Expand Down Expand Up @@ -797,4 +800,4 @@ else
include("webaudio/interface.lua")
end

return WebAudio.Common
return WebAudio.Common
34 changes: 26 additions & 8 deletions lua/webaudio/receiver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,29 @@ timer.Create("wa_think", 100 / 1000, 0, function()
end
end)

---@param url string
---@param onSuccess fun()
---@param onError fun(err: string)
local function checkStreamContents(url, onSuccess, onError)
if hook.Run("WA_ShouldCheckStreamContent", url) == false then
return onSuccess()
end

http.Fetch(url, function(body, _, _)
if body:find("#EXTM3U", 1, true) then
return onError("Cannot create stream with unwhitelisted file format (m3u)")
end

if body:find("[playlist]", 1, true) then
return onError("Cannot create stream with unwhitelisted file format (pls)")
end

onSuccess()
end, function(err)
onError("HTTP error:" .. err)
end)
end

net.Receive("wa_create", function(len)
local id, url, owner = WebAudio.readID(), net.ReadString(), net.ReadEntity()
local verbosity = Verbosity:GetInt()
Expand Down Expand Up @@ -141,12 +164,7 @@ net.Receive("wa_create", function(len)

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

http.Fetch(url, function(body, size, headers)
if body:find("#EXTM3U", 1, true) then
streamFailed()
return warn("User %s(%s) tried to create WebAudio object with unwhitelisted file format (m3u)", owner:Nick(), owner:SteamID64() or "multirun")
end

checkStreamContents(url, function()
sound.PlayURL(url, "3d noblock noplay", function(bass, errid, errname)
if errid then
streamFailed()
Expand Down Expand Up @@ -209,7 +227,7 @@ net.Receive("wa_create", function(len)
end)
end, function(err)
streamFailed()
return warn("HTTP error when creating WebAudio receiver with id %d, Error [%q]", id, err)
return warn("Error when creating WebAudio object with id: %s, User %s(%s), Error: %s", id, owner:Nick(), owner:SteamID64() or "multirun", err)
end)

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