Ensure Gun is Gone
[akkoma] / lib / pleroma / web / pipelines.ex
1 defmodule Pleroma.Web.Pipelines do
2 def common do
3 quote do
4 pipeline :accepts_html do
5 plug(:accepts, ["html"])
6 end
7
8 pipeline :accepts_html_xml do
9 plug(:accepts, ["html", "xml", "rss", "atom"])
10 end
11
12 pipeline :accepts_html_json do
13 plug(:accepts, ["html", "activity+json", "json"])
14 end
15
16 pipeline :accepts_html_xml_json do
17 plug(:accepts, ["html", "xml", "rss", "atom", "activity+json", "json"])
18 end
19
20 pipeline :accepts_xml_rss_atom do
21 plug(:accepts, ["xml", "rss", "atom"])
22 end
23
24 pipeline :browser do
25 plug(:accepts, ["html"])
26 plug(:fetch_session)
27 end
28
29 pipeline :oauth do
30 plug(:fetch_session)
31 plug(Pleroma.Web.Plugs.OAuthPlug)
32 plug(Pleroma.Web.Plugs.UserEnabledPlug)
33 plug(Pleroma.Web.Plugs.EnsureUserTokenAssignsPlug)
34 end
35
36 # Note: expects _user_ authentication (user-unbound app-bound tokens don't qualify)
37 pipeline :expect_user_authentication do
38 plug(Pleroma.Web.Plugs.ExpectAuthenticatedCheckPlug)
39 end
40
41 # Note: expects public instance or _user_ authentication (user-unbound tok ens don't qualify)
42 pipeline :expect_public_instance_or_user_authentication do
43 plug(Pleroma.Web.Plugs.ExpectPublicOrAuthenticatedCheckPlug)
44 end
45
46 pipeline :authenticate do
47 plug(Pleroma.Web.Plugs.OAuthPlug)
48 plug(Pleroma.Web.Plugs.BasicAuthDecoderPlug)
49 plug(Pleroma.Web.Plugs.UserFetcherPlug)
50 plug(Pleroma.Web.Plugs.AuthenticationPlug)
51 end
52
53 pipeline :after_auth do
54 plug(Pleroma.Web.Plugs.UserEnabledPlug)
55 plug(Pleroma.Web.Plugs.SetUserSessionIdPlug)
56 plug(Pleroma.Web.Plugs.EnsureUserTokenAssignsPlug)
57 plug(Pleroma.Web.Plugs.UserTrackingPlug)
58 end
59
60 pipeline :base_api do
61 plug(:accepts, ["json"])
62 plug(:fetch_session)
63 plug(:authenticate)
64 plug(OpenApiSpex.Plug.PutApiSpec, module: Pleroma.Web.ApiSpec)
65 end
66
67 pipeline :no_auth_or_privacy_expectations_api do
68 plug(:base_api)
69 plug(:after_auth)
70 plug(Pleroma.Web.Plugs.IdempotencyPlug)
71 end
72
73 # Pipeline for app-related endpoints (no user auth checks — app-bound toke ns must be supported)
74 pipeline :app_api do
75 plug(:no_auth_or_privacy_expectations_api)
76 end
77
78 pipeline :api do
79 plug(:expect_public_instance_or_user_authentication)
80 plug(:no_auth_or_privacy_expectations_api)
81 end
82
83 pipeline :authenticated_api do
84 plug(:expect_user_authentication)
85 plug(:no_auth_or_privacy_expectations_api)
86 plug(Pleroma.Web.Plugs.EnsureAuthenticatedPlug)
87 end
88
89 pipeline :admin_api do
90 plug(:expect_user_authentication)
91 plug(:base_api)
92 plug(Pleroma.Web.Plugs.AdminSecretAuthenticationPlug)
93 plug(:after_auth)
94 plug(Pleroma.Web.Plugs.EnsureAuthenticatedPlug)
95 plug(Pleroma.Web.Plugs.UserIsStaffPlug)
96 plug(Pleroma.Web.Plugs.IdempotencyPlug)
97 end
98
99 pipeline :require_privileged_staff do
100 plug(Pleroma.Web.Plugs.EnsureStaffPrivilegedPlug)
101 end
102
103 pipeline :require_admin do
104 plug(Pleroma.Web.Plugs.UserIsAdminPlug)
105 end
106
107 pipeline :pleroma_html do
108 plug(:browser)
109 plug(:authenticate)
110 plug(Pleroma.Web.Plugs.EnsureUserTokenAssignsPlug)
111 end
112
113 pipeline :well_known do
114 plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"])
115 end
116
117 pipeline :config do
118 plug(:accepts, ["json", "xml"])
119 plug(OpenApiSpex.Plug.PutApiSpec, module: Pleroma.Web.ApiSpec)
120 end
121
122 pipeline :pleroma_api do
123 plug(:accepts, ["html", "json"])
124 plug(OpenApiSpex.Plug.PutApiSpec, module: Pleroma.Web.ApiSpec)
125 end
126
127 pipeline :mailbox_preview do
128 plug(:accepts, ["html"])
129
130 plug(:put_secure_browser_headers, %{
131 "content-security-policy" =>
132 "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' 'unsafe-eval'"
133 })
134 end
135
136 pipeline :http_signature do
137 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
138 plug(Pleroma.Web.Plugs.MappedSignatureToIdentityPlug)
139 end
140
141 pipeline :static_fe do
142 plug(Pleroma.Web.Plugs.StaticFEPlug)
143 end
144 end
145 end
146
147 defmacro __using__(which) when is_atom(which) do
148 apply(__MODULE__, which, [])
149 end
150 end