修正: 動画ビューア描画における123av用サンドボックス保護と透明広告リンク監視を追加
UnifiedHtmlRendererおよびLegacyのHtmlRendererにて、123av関連ドメイン接続時にiframeのsandbox属性(ポップアップ遮断・プレイヤー操作許可)を設定し、Plyrコントローラーに干渉せず外部遷移aタグのみを除去する監視処理を追加
This commit is contained in:
1 parent
0e805184d9
commit
210543ba1f
2 files changed
+56
-9
No files matched your search
@@ -1,4 +1,4 @@
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
using WebImageViewer.Class.Legacy.Models;
|
||||
|
||||
@@ -1720,8 +1720,6 @@ public static class HtmlRenderer
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
||||
""";
|
||||
}
|
||||
|
||||
@@ -2106,7 +2104,6 @@ public static class HtmlRenderer
|
||||
playerUrl ??= $"https://video.fc2.com/a/embed/player/{safeId}/";
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
siteDisplayName = !string.IsNullOrWhiteSpace(site) ? site.ToUpperInvariant() : "動画プレイヤー";
|
||||
badgeText = "WEB VIDEO";
|
||||
@@ -2117,10 +2114,19 @@ public static class HtmlRenderer
|
||||
break;
|
||||
}
|
||||
|
||||
bool is123Av = string.Equals(normalizedSite, "123av", StringComparison.OrdinalIgnoreCase) ||
|
||||
(!string.IsNullOrWhiteSpace(originalUrl) && originalUrl.Contains("123av.", StringComparison.OrdinalIgnoreCase)) ||
|
||||
(!string.IsNullOrWhiteSpace(playerUrl) && (playerUrl.Contains("123av.", StringComparison.OrdinalIgnoreCase) || playerUrl.Contains("jav-master", StringComparison.OrdinalIgnoreCase) || playerUrl.Contains("javplayer.cc", StringComparison.OrdinalIgnoreCase) || playerUrl.Contains("sadie-shop.site", StringComparison.OrdinalIgnoreCase)));
|
||||
|
||||
var effectivePlayerUrl = (!string.IsNullOrWhiteSpace(playerUrl) && is123Av && !playerUrl.StartsWith("/api/clean-embed", StringComparison.OrdinalIgnoreCase))
|
||||
? $"/api/clean-embed?url={Uri.EscapeDataString(playerUrl.Trim())}&referer={Uri.EscapeDataString(!string.IsNullOrWhiteSpace(originalUrl) ? originalUrl.Trim() : defaultOrigUrl)}"
|
||||
: (playerUrl ?? "");
|
||||
|
||||
var safeTitle = !string.IsNullOrWhiteSpace(title) ? Encoder.Encode(title) : $"{siteDisplayName} 動画プレイヤー ({safeId})";
|
||||
var safeOriginalUrl = !string.IsNullOrWhiteSpace(originalUrl) ? Encoder.Encode(originalUrl) : defaultOrigUrl;
|
||||
var safePlayerUrl = !string.IsNullOrWhiteSpace(playerUrl) ? Encoder.Encode(playerUrl) : "";
|
||||
var safePlayerUrl = !string.IsNullOrWhiteSpace(effectivePlayerUrl) ? Encoder.Encode(effectivePlayerUrl) : "";
|
||||
var safeStreamUrl = !string.IsNullOrWhiteSpace(streamUrl) ? Encoder.Encode(streamUrl) : "";
|
||||
var sandboxAttr = is123Av ? """sandbox="allow-scripts allow-same-origin allow-forms allow-presentation" """ : "";
|
||||
|
||||
bool hasStream = !string.IsNullOrEmpty(safeStreamUrl);
|
||||
bool hasPlayer = !string.IsNullOrEmpty(safePlayerUrl);
|
||||
@@ -2413,7 +2419,7 @@ public static class HtmlRenderer
|
||||
<iframe
|
||||
id="videoIframe"
|
||||
src="{{safePlayerUrl}}"
|
||||
class="player-iframe"
|
||||
{{sandboxAttr}}class="player-iframe"
|
||||
frameborder="0"
|
||||
scrolling="no"
|
||||
referrerpolicy="no-referrer-when-downgrade"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
using WebImageViewer.Class.Unified.Models;
|
||||
using WebImageViewer.Class.Unified.Services;
|
||||
|
||||
namespace WebImageViewer.Class.Unified.Renderers;
|
||||
|
||||
@@ -565,11 +566,17 @@ public static class UnifiedHtmlRenderer
|
||||
/// </summary>
|
||||
public static string RenderVideoViewer(UnifiedVideoItem video)
|
||||
{
|
||||
bool is123Av = UnifiedEmbedSanitizer.Is123AvDomain(video.Site, video.OriginalUrl, video.EmbedUrl);
|
||||
var effectiveEmbedUrl = (!string.IsNullOrWhiteSpace(video.EmbedUrl) && is123Av)
|
||||
? UnifiedEmbedSanitizer.ToCleanEmbedUrl(video.EmbedUrl, video.OriginalUrl)
|
||||
: (video.EmbedUrl ?? "");
|
||||
|
||||
var safeTitle = Encoder.Encode(video.Title);
|
||||
var safeOrigUrl = Encoder.Encode(video.OriginalUrl);
|
||||
var safeEmbedUrl = !string.IsNullOrWhiteSpace(video.EmbedUrl) ? Encoder.Encode(video.EmbedUrl) : "";
|
||||
var safeEmbedUrl = !string.IsNullOrWhiteSpace(effectiveEmbedUrl) ? Encoder.Encode(effectiveEmbedUrl) : "";
|
||||
var safeStreamUrl = !string.IsNullOrWhiteSpace(video.StreamUrl) ? Encoder.Encode(video.StreamUrl) : "";
|
||||
var safePoster = !string.IsNullOrWhiteSpace(video.PosterUrl) ? Encoder.Encode(video.PosterUrl) : "";
|
||||
var sandboxAttr = is123Av ? """sandbox="allow-scripts allow-same-origin allow-forms allow-presentation" """ : "";
|
||||
|
||||
bool hasStream = !string.IsNullOrEmpty(safeStreamUrl);
|
||||
bool hasEmbed = !string.IsNullOrEmpty(safeEmbedUrl);
|
||||
@@ -729,7 +736,7 @@ public static class UnifiedHtmlRenderer
|
||||
<iframe
|
||||
id="videoIframe"
|
||||
src="{{safeEmbedUrl}}"
|
||||
class="player-iframe"
|
||||
{{sandboxAttr}}class="player-iframe"
|
||||
frameborder="0"
|
||||
scrolling="no"
|
||||
referrerpolicy="no-referrer-when-downgrade"
|
||||
@@ -808,6 +815,40 @@ public static class UnifiedHtmlRenderer
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 123av ドメイン接続時の透明リンクエリア・外部リンク除去バックアップ監視
|
||||
const is123AvDomain = {{(is123Av ? "true" : "false")}};
|
||||
const videoIframe = document.getElementById('videoIframe');
|
||||
if (is123AvDomain) {
|
||||
try {
|
||||
Object.defineProperty(window, 'open', {
|
||||
value: function() { return null; },
|
||||
writable: false,
|
||||
configurable: false
|
||||
});
|
||||
} catch (e) {
|
||||
window.open = function() { return null; };
|
||||
}
|
||||
|
||||
if (videoIframe) {
|
||||
const cleanIframeOverlays = () => {
|
||||
try {
|
||||
const doc = videoIframe.contentDocument || (videoIframe.contentWindow && videoIframe.contentWindow.document);
|
||||
if (!doc) return;
|
||||
const links = doc.querySelectorAll('body > a, a[target="_blank"], a[style*="999999"], ins');
|
||||
links.forEach(el => {
|
||||
el.removeAttribute('href');
|
||||
el.removeAttribute('target');
|
||||
el.style.setProperty('pointer-events', 'none', 'important');
|
||||
el.style.setProperty('display', 'none', 'important');
|
||||
el.remove();
|
||||
});
|
||||
} catch (e) {}
|
||||
};
|
||||
videoIframe.addEventListener('load', cleanIframeOverlays);
|
||||
setInterval(cleanIframeOverlays, 250);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in new issue
Block a user