Skip to content

Commit

Permalink
Merge develop 2023-08-08 (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
kphrx committed Aug 8, 2023
2 parents 2a78a45 + 4e355b8 commit 6c57967
Show file tree
Hide file tree
Showing 25 changed files with 420 additions and 10 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Removed
- BREAKING: Support for passwords generated with `crypt(3)` (Gnu Social migration artifact)

## 2.5.4

## Security
- Fix XML External Entity (XXE) loading vulnerability allowing to fetch arbitary files from the server's filesystem

## 2.5.3

### Security
- Emoji pack loader sanitizes pack names
- Reduced permissions of config files and directories, distros requiring greater permissions like group-read need to pre-create the directories

## 2.5.2

### Security
Expand Down
1 change: 1 addition & 0 deletions changelog.d/3801.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Filter context activities using Visibility.visible_for_user?
1 change: 1 addition & 0 deletions changelog.d/akkoma-xml-remote-entities.security
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix XML External Entity (XXE) loading vulnerability allowing to fetch arbitary files from the server's filesystem
1 change: 1 addition & 0 deletions changelog.d/attachment-type-check.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Restrict attachments to only uploaded files only
1 change: 1 addition & 0 deletions changelog.d/disable-xml-entity-resolution.security
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disable XML entity resolution completely to fix a dos vulnerability
1 change: 1 addition & 0 deletions changelog.d/emoji-pack-sanitization.security
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Emoji pack loader sanitizes pack names
Empty file.
1 change: 1 addition & 0 deletions changelog.d/otp_perms.security
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Reduced permissions of config files and directories, distros requiring greater permissions like group-read need to pre-create the directories
2 changes: 1 addition & 1 deletion docs/installation/gentoo_otp_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{! backend/installation/otp_vs_from_source.include !}

A [manual installation guide for gentoo](./gentoo_en.md) is also available.
This guide covers installation via Gentoo provided packaging. A [manual installation guide for gentoo](./gentoo_en.md) is also available.

## Installation

Expand Down
13 changes: 10 additions & 3 deletions lib/mix/tasks/pleroma/instance.ex
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,20 @@ defmodule Mix.Tasks.Pleroma.Instance do
config_dir = Path.dirname(config_path)
psql_dir = Path.dirname(psql_path)

# Note: Distros requiring group read (0o750) on those directories should
# pre-create the directories.
[config_dir, psql_dir, static_dir, uploads_dir]
|> Enum.reject(&File.exists?/1)
|> Enum.map(&File.mkdir_p!/1)
|> Enum.each(fn dir ->
File.mkdir_p!(dir)
File.chmod!(dir, 0o700)
end)

shell_info("Writing config to #{config_path}.")

# Sadly no fchmod(2) equivalent in Elixir…
File.touch!(config_path)
File.chmod!(config_path, 0o640)
File.write(config_path, result_config)
shell_info("Writing the postgres script to #{psql_path}.")
File.write(psql_path, result_psql)
Expand All @@ -290,8 +298,7 @@ defmodule Mix.Tasks.Pleroma.Instance do
else
shell_error(
"The task would have overwritten the following files:\n" <>
(Enum.map(will_overwrite, &"- #{&1}\n") |> Enum.join("")) <>
"Rerun with `--force` to overwrite them."
Enum.map_join(will_overwrite, &"- #{&1}\n") <> "Rerun with `--force` to overwrite them."
)
end
end
Expand Down
14 changes: 14 additions & 0 deletions lib/pleroma/config/release_runtime_provider.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ defmodule Pleroma.Config.ReleaseRuntimeProvider do

with_runtime_config =
if File.exists?(config_path) do
# <https://git.pleroma.social/pleroma/pleroma/-/issues/3135>
%File.Stat{mode: mode} = File.lstat!(config_path)

if Bitwise.band(mode, 0o007) > 0 do
raise "Configuration at #{config_path} has world-permissions, execute the following: chmod o= #{config_path}"
end

if Bitwise.band(mode, 0o020) > 0 do
raise "Configuration at #{config_path} has group-wise write permissions, execute the following: chmod g-w #{config_path}"
end

# Note: Elixir doesn't provides a getuid(2)
# so cannot forbid group-read only when config is owned by us

runtime_config = Config.Reader.read!(config_path)

with_defaults
Expand Down
2 changes: 2 additions & 0 deletions lib/pleroma/constants.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,6 @@ defmodule Pleroma.Constants do
const(mime_regex,
do: ~r/^[^[:cntrl:] ()<>@,;:\\"\/\[\]?=]+\/[^[:cntrl:] ()<>@,;:\\"\/\[\]?=]+(; .*)?$/
)

const(upload_object_types, do: ["Document", "Image"])
end
1 change: 1 addition & 0 deletions lib/pleroma/emoji/pack.ex
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ defmodule Pleroma.Emoji.Pack do

@spec load_pack(String.t()) :: {:ok, t()} | {:error, :file.posix()}
def load_pack(name) do
name = Path.basename(name)
pack_file = Path.join([emoji_path(), name, "pack.json"])

with {:ok, _} <- File.stat(pack_file),
Expand Down
22 changes: 22 additions & 0 deletions lib/pleroma/web/activity_pub/activity_pub.ex
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|> maybe_preload_objects(opts)
|> maybe_preload_bookmarks(opts)
|> maybe_set_thread_muted_field(opts)
|> restrict_unauthenticated(opts[:user])
|> restrict_blocked(opts)
|> restrict_blockers_visibility(opts)
|> restrict_recipients(recipients, opts[:user])
Expand Down Expand Up @@ -1211,6 +1212,27 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do

defp restrict_filtered(query, _), do: query

defp restrict_unauthenticated(query, nil) do
local = Config.restrict_unauthenticated_access?(:activities, :local)
remote = Config.restrict_unauthenticated_access?(:activities, :remote)

cond do
local and remote ->
from(activity in query, where: false)

local ->
from(activity in query, where: activity.local == false)

remote ->
from(activity in query, where: activity.local == true)

true ->
query
end
end

defp restrict_unauthenticated(query, _), do: query

defp exclude_poll_votes(query, %{include_poll_votes: true}), do: query

defp exclude_poll_votes(query, _) do
Expand Down
7 changes: 6 additions & 1 deletion lib/pleroma/web/common_api/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ defmodule Pleroma.Web.CommonAPI.Utils do
end

defp get_attachment(media_id) do
Repo.get(Object, media_id)
with %Object{data: data} = object <- Repo.get(Object, media_id),
%{"type" => type} when type in Pleroma.Constants.upload_object_types() <- data do
object
else
_ -> nil
end
end

@spec get_to_and_cc(ActivityDraft.t()) :: {list(String.t()), list(String.t())}
Expand Down
5 changes: 4 additions & 1 deletion lib/pleroma/web/xml.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ defmodule Pleroma.Web.XML do
{doc, _rest} =
text
|> :binary.bin_to_list()
|> :xmerl_scan.string(quiet: true)
|> :xmerl_scan.string(
quiet: true,
allow_entities: false
)

{:ok, doc}
rescue
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Pleroma.Mixfile do
def project do
[
app: :pleroma,
version: version("2.5.52"),
version: version("2.5.54"),
elixir: "~> 1.11",
elixirc_paths: elixirc_paths(Mix.env()),
compilers: [:phoenix] ++ Mix.compilers(),
Expand Down
15 changes: 15 additions & 0 deletions test/fixtures/xml_billion_laughs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<!DOCTYPE lolz [
<!ENTITY lol "lol">
<!ELEMENT lolz (#PCDATA)>
<!ENTITY lol1 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;">
<!ENTITY lol2 "&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;">
<!ENTITY lol3 "&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;">
<!ENTITY lol4 "&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;">
<!ENTITY lol5 "&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;">
<!ENTITY lol6 "&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;">
<!ENTITY lol7 "&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;">
<!ENTITY lol8 "&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;">
<!ENTITY lol9 "&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;">
]>
<lolz>&lol9;</lolz>
3 changes: 3 additions & 0 deletions test/fixtures/xml_external_entities.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [ <!ENTITY xxe SYSTEM "file:///etc/passwd"> ]>
<stockCheck><productId>&xxe;</productId></stockCheck>
7 changes: 7 additions & 0 deletions test/pleroma/config/release_runtime_provider_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ defmodule Pleroma.Config.ReleaseRuntimeProviderTest do
end

test "merged runtime config" do
assert :ok == File.chmod!("test/fixtures/config/temp.secret.exs", 0o640)

merged =
ReleaseRuntimeProvider.load([], config_path: "test/fixtures/config/temp.secret.exs")

Expand All @@ -25,6 +27,8 @@ defmodule Pleroma.Config.ReleaseRuntimeProviderTest do
end

test "merged exported config" do
assert :ok == File.chmod!("test/fixtures/config/temp.exported_from_db.secret.exs", 0o640)

ExUnit.CaptureIO.capture_io(fn ->
merged =
ReleaseRuntimeProvider.load([],
Expand All @@ -37,6 +41,9 @@ defmodule Pleroma.Config.ReleaseRuntimeProviderTest do
end

test "runtime config is merged with exported config" do
assert :ok == File.chmod!("test/fixtures/config/temp.secret.exs", 0o640)
assert :ok == File.chmod!("test/fixtures/config/temp.exported_from_db.secret.exs", 0o640)

merged =
ReleaseRuntimeProvider.load([],
config_path: "test/fixtures/config/temp.secret.exs",
Expand Down
4 changes: 4 additions & 0 deletions test/pleroma/emoji/pack_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,8 @@ defmodule Pleroma.Emoji.PackTest do

assert updated_pack.files_count == 1
end

test "load_pack/1 ignores path traversal in a forged pack name", %{pack: pack} do
assert {:ok, ^pack} = Pack.load_pack("../../../../../dump_pack")
end
end
11 changes: 8 additions & 3 deletions test/pleroma/web/common_api/utils_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
end

test "returns list attachments with desc" do
object = insert(:note)
object = insert(:attachment)
desc = Jason.encode!(%{object.id => "test-desc"})

assert Utils.attachments_from_ids_descs(["#{object.id}", "34"], desc) == [
Expand All @@ -603,7 +603,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do

describe "attachments_from_ids/1" do
test "returns attachments with descs" do
object = insert(:note)
object = insert(:attachment)
desc = Jason.encode!(%{object.id => "test-desc"})

assert Utils.attachments_from_ids(%{
Expand All @@ -615,13 +615,18 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
end

test "returns attachments without descs" do
object = insert(:note)
object = insert(:attachment)
assert Utils.attachments_from_ids(%{media_ids: ["#{object.id}"]}) == [object.data]
end

test "returns [] when not pass media_ids" do
assert Utils.attachments_from_ids(%{}) == []
end

test "checks that the object is of upload type" do
object = insert(:note)
assert Utils.attachments_from_ids(%{media_ids: ["#{object.id}"]}) == []
end
end

describe "maybe_add_list_data/3" do
Expand Down
Loading

0 comments on commit 6c57967

Please sign in to comment.