Browse Source

move blacklist checking into a function

main
Aaron Parecki 8 years ago
parent
commit
8cfd5f1d1e
3 changed files with 31 additions and 10 deletions
  1. +8
    -0
      controllers/API.php
  2. +1
    -10
      controllers/Controller.php
  3. +22
    -0
      lib/Telegraph/Webmention.php

+ 8
- 0
controllers/API.php View File

@ -84,6 +84,14 @@ class API {
]);
}
# Check the blacklist of domains that are known to not accept webmentions
if($target && !Telegraph\Webmention::isProbablySupported($target)) {
return $this->respond($response, 400, [
'error' => 'not_supported',
'error_description' => 'The target domain is known to not accept webmentions. If you believe this is in error, please file an issue at https://github.com/aaronpk/Telegraph/issues'
]);
}
# Synchronously check the source URL and verify that it actually contains
# a link to the target. This way we prevent this API from sending known invalid mentions.
$sourceData = $this->http->get($source);

+ 1
- 10
controllers/Controller.php View File

@ -213,16 +213,7 @@ class Controller {
$targetURL = $request->get('target');
// Reject links that are known to not accept webmentions
$host = str_replace('www.','',parse_url($targetURL, PHP_URL_HOST));
$unsupported = [
'twitter.com',
'instagram.com',
'facebook.com',
];
if(!$host || in_array($host, $unsupported) || preg_match('/.+\.amazonaws\.com/', $host)) {
if(!Telegraph\Webmention::isProbablySupported($targetURL)) {
$status = 'none';
$cached = -1;
} else {

+ 22
- 0
lib/Telegraph/Webmention.php View File

@ -7,6 +7,28 @@ class Webmention {
private static $http = false;
// Returns false if the target URL is known to not accept webmentions
public static function isProbablySupported($targetURL) {
// Reject links that are known to not accept webmentions
$host = str_replace('www.','',parse_url($targetURL, PHP_URL_HOST));
if(!$host) return false;
$unsupported = [
'twitter.com',
'instagram.com',
'facebook.com',
];
if(in_array($host, $unsupported))
return false;
if(preg_match('/.+\.amazonaws\.com/', $host))
return false;
return true;
}
private static function updateStatus($webmention, $http_code, $code, $raw=null) {
$status = ORM::for_table('webmention_status')->create();
$status->webmention_id = $webmention->id;

Loading…
Cancel
Save