Don't try generating link previews for debuglogs.org

This commit is contained in:
Evan Hahn 2022-03-08 14:04:44 -06:00 committed by GitHub
parent 4e48d7792b
commit efee887135
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 21 deletions

View file

@ -2212,7 +2212,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
(item: typeof window.WhatIsThis) => (item: typeof window.WhatIsThis) =>
(item.image || item.title) && (item.image || item.title) &&
urls.includes(item.url) && urls.includes(item.url) &&
LinkPreview.isLinkSafeToPreview(item.url) LinkPreview.shouldPreviewHref(item.url)
); );
if (preview.length < incomingPreview.length) { if (preview.length < incomingPreview.length) {
log.info( log.info(

View file

@ -5,37 +5,41 @@ import { assert } from 'chai';
import { import {
findLinks, findLinks,
isLinkSafeToPreview, shouldPreviewHref,
isLinkSneaky, isLinkSneaky,
} from '../../types/LinkPreview'; } from '../../types/LinkPreview';
describe('Link previews', () => { describe('Link previews', () => {
describe('#isLinkSafeToPreview', () => { describe('#shouldPreviewHref', () => {
it('returns false for invalid URLs', () => { it('returns false for invalid URLs', () => {
assert.isFalse(isLinkSafeToPreview('')); assert.isFalse(shouldPreviewHref(''));
assert.isFalse(isLinkSafeToPreview('https')); assert.isFalse(shouldPreviewHref('https'));
assert.isFalse(isLinkSafeToPreview('https://')); assert.isFalse(shouldPreviewHref('https://'));
assert.isFalse(isLinkSafeToPreview('https://bad url')); assert.isFalse(shouldPreviewHref('https://bad url'));
assert.isFalse(isLinkSafeToPreview('example.com')); assert.isFalse(shouldPreviewHref('example.com'));
}); });
it('returns false for non-HTTPS URLs', () => { it('returns false for non-HTTPS URLs', () => {
assert.isFalse(isLinkSafeToPreview('http://example.com')); assert.isFalse(shouldPreviewHref('http://example.com'));
assert.isFalse(isLinkSafeToPreview('ftp://example.com')); assert.isFalse(shouldPreviewHref('ftp://example.com'));
assert.isFalse(isLinkSafeToPreview('file://example')); assert.isFalse(shouldPreviewHref('file://example'));
}); });
it('returns false if the link is "sneaky"', () => { it('returns false if the link is "sneaky"', () => {
// See `isLinkSneaky` tests below for more thorough checking. // See `isLinkSneaky` tests below for more thorough checking.
assert.isFalse(isLinkSafeToPreview('https://user:pass@example.com')); assert.isFalse(shouldPreviewHref('https://user:pass@example.com'));
assert.isFalse(isLinkSafeToPreview('https://aquí.example')); assert.isFalse(shouldPreviewHref('https://aquí.example'));
assert.isFalse(isLinkSafeToPreview('https://aqu%C3%AD.example')); assert.isFalse(shouldPreviewHref('https://aqu%C3%AD.example'));
});
it('returns false for skipped domains', () => {
assert.isFalse(shouldPreviewHref('https://debuglogs.org'));
}); });
it('returns true for "safe" urls', () => { it('returns true for "safe" urls', () => {
assert.isTrue(isLinkSafeToPreview('https://example.com')); assert.isTrue(shouldPreviewHref('https://example.com'));
assert.isTrue( assert.isTrue(
isLinkSafeToPreview('https://example.com/foo/bar?query=string#hash') shouldPreviewHref('https://example.com/foo/bar?query=string#hash')
); );
}); });
}); });

View file

@ -28,9 +28,14 @@ export type LinkPreviewWithDomain = {
const linkify = LinkifyIt(); const linkify = LinkifyIt();
export function isLinkSafeToPreview(href: string): boolean { export function shouldPreviewHref(href: string): boolean {
const url = maybeParseUrl(href); const url = maybeParseUrl(href);
return Boolean(url && url.protocol === 'https:' && !isLinkSneaky(href)); return Boolean(
url &&
url.protocol === 'https:' &&
url.hostname !== 'debuglogs.org' &&
!isLinkSneaky(href)
);
} }
export function isStickerPack(link = ''): boolean { export function isStickerPack(link = ''): boolean {

View file

@ -2999,7 +2999,7 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
const link = links.find( const link = links.find(
item => item =>
LinkPreview.isLinkSafeToPreview(item) && LinkPreview.shouldPreviewHref(item) &&
!this.excludedPreviewUrls.includes(item) !this.excludedPreviewUrls.includes(item)
); );
if (!link) { if (!link) {
@ -3226,7 +3226,7 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
} }
// This is already checked elsewhere, but we want to be extra-careful. // This is already checked elsewhere, but we want to be extra-careful.
if (!LinkPreview.isLinkSafeToPreview(url)) { if (!LinkPreview.shouldPreviewHref(url)) {
return null; return null;
} }
@ -3241,7 +3241,7 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
const { title, imageHref, description, date } = linkPreviewMetadata; const { title, imageHref, description, date } = linkPreviewMetadata;
let image; let image;
if (imageHref && LinkPreview.isLinkSafeToPreview(imageHref)) { if (imageHref && LinkPreview.shouldPreviewHref(imageHref)) {
let objectUrl: void | string; let objectUrl: void | string;
try { try {
const fullSizeImage = const fullSizeImage =