mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
🐛 Fixed fallback to bookmark card when pasting localhost Ghost url
no issue - localhost check was causing an immediate "no provider" error when fetching oembed for a localhost url and bypassing the bookmark fallback even when the configured site lives on localhost - allow `localhost:port` through in oembed endpoints when it matches the configured url
This commit is contained in:
parent
ce8bc9d4bf
commit
e0d1763424
2 changed files with 20 additions and 6 deletions
|
@ -1,10 +1,11 @@
|
|||
const {i18n} = require('../../lib/common');
|
||||
const errors = require('@tryghost/errors');
|
||||
const {extract, hasProvider} = require('oembed-parser');
|
||||
const Promise = require('bluebird');
|
||||
const externalRequest = require('../../lib/request-external');
|
||||
const cheerio = require('cheerio');
|
||||
const _ = require('lodash');
|
||||
const config = require('../../../shared/config');
|
||||
const {i18n} = require('../../lib/common');
|
||||
const externalRequest = require('../../lib/request-external');
|
||||
|
||||
async function fetchBookmarkData(url, html) {
|
||||
const metascraper = require('metascraper')([
|
||||
|
@ -97,7 +98,13 @@ function isIpOrLocalhost(url) {
|
|||
const IPV6_REGEX = /:/; // fqdns will not have colons
|
||||
const HTTP_REGEX = /^https?:/i;
|
||||
|
||||
const {protocol, hostname} = new URL(url);
|
||||
const siteUrl = new URL(config.get('url'));
|
||||
const {protocol, hostname, host} = new URL(url);
|
||||
|
||||
// allow requests to Ghost's own url through
|
||||
if (siteUrl.host === host) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!HTTP_REGEX.test(protocol) || hostname === 'localhost' || IPV4_REGEX.test(hostname) || IPV6_REGEX.test(hostname)) {
|
||||
return true;
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
const {i18n} = require('../../lib/common');
|
||||
const errors = require('@tryghost/errors');
|
||||
const {extract, hasProvider} = require('oembed-parser');
|
||||
const Promise = require('bluebird');
|
||||
const externalRequest = require('../../lib/request-external');
|
||||
const cheerio = require('cheerio');
|
||||
const _ = require('lodash');
|
||||
const config = require('../../../shared/config');
|
||||
const {i18n} = require('../../lib/common');
|
||||
const externalRequest = require('../../lib/request-external');
|
||||
|
||||
const findUrlWithProvider = (url) => {
|
||||
let provider;
|
||||
|
@ -51,7 +52,13 @@ function isIpOrLocalhost(url) {
|
|||
const IPV6_REGEX = /:/; // fqdns will not have colons
|
||||
const HTTP_REGEX = /^https?:/i;
|
||||
|
||||
const {protocol, hostname} = new URL(url);
|
||||
const siteUrl = new URL(config.get('url'));
|
||||
const {protocol, hostname, host} = new URL(url);
|
||||
|
||||
// allow requests to Ghost's own url through
|
||||
if (siteUrl.host === host) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!HTTP_REGEX.test(protocol) || hostname === 'localhost' || IPV4_REGEX.test(hostname) || IPV6_REGEX.test(hostname)) {
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue