File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -187,6 +187,12 @@ public function publish(Request $request): Response
187
187
188
188
$ content = new models \Content ($ url );
189
189
190
+ if (!$ content ->isAllowed ()) {
191
+ return Response::badRequest ('requests/error.txt ' , [
192
+ 'errors ' => ["url \"{$ url }\" is not authorized " ],
193
+ ]);
194
+ }
195
+
190
196
$ errors = $ content ->validate ();
191
197
if ($ errors ) {
192
198
return Response::badRequest ('requests/error.txt ' , [
Original file line number Diff line number Diff line change 4
4
5
5
use Minz \Database ;
6
6
use Minz \Validable ;
7
+ use Webubbub \utils ;
7
8
8
9
/**
9
10
* Represent a content created by publishers, it is delivered to subscribers.
@@ -85,6 +86,14 @@ public function deliver(): void
85
86
$ this ->status = 'delivered ' ;
86
87
}
87
88
89
+ /**
90
+ * Return wheter a content is allowed on the hub or not.
91
+ */
92
+ public function isAllowed (): bool
93
+ {
94
+ return utils \AllowedOriginHelper::isOriginAllowed ($ this ->url );
95
+ }
96
+
88
97
/**
89
98
* Delete the Contents that can be deleted and return the number of
90
99
* deletions.
Original file line number Diff line number Diff line change @@ -251,6 +251,22 @@ public function testPublishWithSameUrlAndFetchedStatus(): void
251
251
$ this ->assertSame (2 , models \Content::count ());
252
252
}
253
253
254
+ public function testPublishFailsIfUrlIsNotAuthorized (): void
255
+ {
256
+ \Webubbub \Configuration::$ application ['allowed_topic_origins ' ] = 'https://allowed.1.com,https://allowed.2.com ' ;
257
+
258
+ $ response = $ this ->appRun ('CLI ' , '/requests/publish ' , [
259
+ 'hub_url ' => 'https://not.allowed.com ' ,
260
+ ]);
261
+
262
+ \Webubbub \Configuration::$ application ['allowed_topic_origins ' ] = '' ;
263
+
264
+ $ this ->assertResponseCode ($ response , 400 );
265
+ $ this ->assertResponseContains ($ response , 'url "https://not.allowed.com" is not authorized ' );
266
+ $ this ->assertResponseHeaders ($ response , ['Content-Type ' => 'text/plain ' ]);
267
+ $ this ->assertSame (0 , models \Content::count ());
268
+ }
269
+
254
270
#[\PHPUnit \Framework \Attributes \DataProvider('invalidUrlProvider ' )]
255
271
public function testPublishFailsIfUrlIsInvalid (string $ invalid_url ): void
256
272
{
You can’t perform that action at this time.
0 commit comments