Skip to content

Commit 9254dd3

Browse files
bug: youtube error fix (#432)
* youtube error fix * implemented suggestions
1 parent 5ad87d5 commit 9254dd3

File tree

5 files changed

+38
-21
lines changed

5 files changed

+38
-21
lines changed

prod/nginx.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ http {
2929

3030
access_log /var/log/nginx/access.log private;
3131
error_log /var/log/nginx/error.log;
32-
add_header Referrer-Policy same-origin;
32+
add_header Referrer-Policy strict-origin-when-cross-origin;
3333

3434
gzip on;
3535
gzip_disable "msie6";

server/venueless/middleware.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
from django.utils.deprecation import MiddlewareMixin
22

3+
REFERRER_POLICY = "strict-origin-when-cross-origin"
4+
35

46
class XFrameOptionsMiddleware(MiddlewareMixin):
57
def process_response(self, request, response):
6-
# Don't set it if it's already in the response
7-
if response.get("X-Frame-Options") is not None:
8-
return response
9-
10-
# Don't set it if they used @xframe_options_exempt
11-
if getattr(response, "xframe_options_exempt", False):
12-
return response
8+
has_xfo = response.get("X-Frame-Options")
9+
is_exempt = getattr(response, "xframe_options_exempt", False)
10+
is_zoom = request.path.startswith("/zoom")
1311

14-
# Don't set for zoom app
15-
# We don't use xframe_options_exempt here since that doesn't catch error pages
16-
if request.path.startswith("/zoom"):
17-
return response
12+
if has_xfo is None and not is_exempt and not is_zoom:
13+
response["X-Frame-Options"] = "DENY"
1814

19-
response["X-Frame-Options"] = "DENY"
15+
if "Referrer-Policy" not in response:
16+
response["Referrer-Policy"] = REFERRER_POLICY
2017
return response

webapp/src/components/MediaSource.vue

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
janus-call(v-else-if="room && module.type === 'call.janus'", ref="janus", :room="room", :module="module", :background="background", :size="background ? 'tiny' : 'normal'", :key="`janus-${room.id}`")
1313
janus-channel-call(v-else-if="call", ref="janus", :call="call", :background="background", :size="background ? 'tiny' : 'normal'", :key="`call-${call.id}`", @close="$emit('close')")
1414
.iframe-error(v-if="iframeError") {{ $t('MediaSource:iframe-error:text') }}
15-
iframe#video-player-translation(v-if="languageIframeUrl", :src="languageIframeUrl", style="position: absolute; width: 50%; height: 100%; z-index: -1", frameborder="0", gesture="media", allow="autoplay; encrypted-media", allowfullscreen="true")
15+
iframe#video-player-translation(v-if="languageIframeUrl", :src="languageIframeUrl", style="position: absolute; width: 50%; height: 100%; z-index: -1", frameborder="0", gesture="media", allow="autoplay; encrypted-media", allowfullscreen="true", :referrerpolicy="referrerPolicy")
1616
</template>
1717
<script>
1818
// TODO functional component?
1919
import { mapState, mapGetters } from 'vuex'
2020
import isEqual from 'lodash/isEqual'
21-
import api from 'lib/api'
21+
import api, { REFERRER_POLICY } from 'lib/api'
2222
import JanusCall from 'components/JanusCall'
2323
import JanusChannelCall from 'components/JanusChannelCall'
2424
import Livestream from 'components/Livestream'
@@ -38,7 +38,8 @@ export default {
3838
iframeError: null,
3939
iframe: null, // Track the iframe element
4040
languageAudioUrl: null, // URL for the selected language audio
41-
languageIframeUrl: null // URL for the language iframe // Added languageIframeUrl to data
41+
languageIframeUrl: null, // URL for the language iframe // Added languageIframeUrl to data
42+
referrerPolicy: REFERRER_POLICY
4243
}
4344
},
4445
computed: {
@@ -125,6 +126,7 @@ export default {
125126
const iframe = document.createElement('iframe')
126127
iframe.src = iframeUrl
127128
iframe.classList.add('iframe-media-source')
129+
iframe.setAttribute('referrerpolicy', this.referrerPolicy)
128130
if (hideIfBackground) {
129131
iframe.classList.add('hide-if-background')
130132
}
@@ -169,7 +171,7 @@ export default {
169171
this.destroyIframe()
170172
this.initializeIframe(mute) // Initialize iframe with the appropriate mute state
171173
// Set the language iframe URL when language changes
172-
this.languageIframeUrl = this.getLanguageIframeUrl(languageUrl)
174+
this.languageIframeUrl = this.getLanguageIframeUrl(languageUrl, this.module?.config?.enablePrivacyEnhancedMode)
173175
},
174176
getYoutubeUrl(ytid, autoplay, mute, hideControls, noRelated, showinfo, disableKb, loop, modestBranding, enablePrivacyEnhancedMode) {
175177
const params = new URLSearchParams({
@@ -183,12 +185,16 @@ export default {
183185
modestbranding: modestBranding ? '1' : '0',
184186
playlist: ytid,
185187
})
188+
const origin = this.getPlayerOrigin()
189+
if (origin) {
190+
params.set('origin', origin)
191+
}
186192
187193
const domain = enablePrivacyEnhancedMode ? 'www.youtube-nocookie.com' : 'www.youtube.com'
188194
return `https://${domain}/embed/${ytid}?${params}`
189195
},
190196
// Added method to get the language iframe URL
191-
getLanguageIframeUrl(languageUrl, enablePrivacyEnhancedMode) {
197+
getLanguageIframeUrl(languageUrl, enablePrivacyEnhancedMode = false) {
192198
// Checks if the languageUrl is not provided the retun null
193199
if (!languageUrl) return null
194200
const params = new URLSearchParams({
@@ -202,9 +208,20 @@ export default {
202208
showinfo: '0',
203209
playlist: languageUrl,
204210
})
211+
const origin = this.getPlayerOrigin()
212+
if (origin) {
213+
params.set('origin', origin)
214+
}
205215
206216
const domain = enablePrivacyEnhancedMode ? 'www.youtube-nocookie.com' : 'www.youtube.com'
207217
return `https://${domain}/embed/${languageUrl}?${params}`
218+
},
219+
getPlayerOrigin() {
220+
try {
221+
return window.location.origin
222+
} catch (error) {
223+
return ''
224+
}
208225
}
209226
}
210227
}

webapp/src/lib/api.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import config from 'config'
33
import store from 'store'
44
import WebSocketClient from './WebSocketClient'
55

6+
export const REFERRER_POLICY = 'strict-origin-when-cross-origin'
7+
68
const api = Object.create(WebSocketClient.prototype)
79
api.connect = function({token, clientId, inviteToken}) {
810
if (api._socket) {

webapp/src/views/exhibitors/item.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ scrollbars.c-exhibitor(y)
44
.content
55
img.banner(:src="exhibitor.banner_detail", v-if="exhibitor.banner_detail && !bannerIsVideo && !bannerIsFrame")
66
.iframe-banner(v-else-if="bannerIsFrame")
7-
iframe(:src="bannerVideoSource", allowfullscreen, allow="fullscreen")
7+
iframe(:src="bannerVideoSource", allowfullscreen, allow="fullscreen", :referrerpolicy="referrerPolicy")
88
.video-banner(v-else-if="bannerIsVideo")
99
video(:src="exhibitor.banner_detail", autoplay, controls, loop)
1010
markdown-content.text(v-if="exhibitor.text_legacy", :markdown="exhibitor.text_legacy")
@@ -44,7 +44,7 @@ scrollbars.c-exhibitor(y)
4444
// TODO
4545
// - user action for staff list?
4646
import { mapState, mapGetters } from 'vuex'
47-
import api from 'lib/api'
47+
import api, { REFERRER_POLICY } from 'lib/api'
4848
import Avatar from 'components/Avatar'
4949
import ContactExhibitorPrompt from 'components/ContactExhibitorPrompt'
5050
import ChatUserCard from 'components/ChatUserCard'
@@ -64,7 +64,8 @@ export default {
6464
exhibitorApi: null,
6565
selectedUser: null,
6666
showContactPrompt: false,
67-
getIconByFileEnding
67+
getIconByFileEnding,
68+
referrerPolicy: REFERRER_POLICY
6869
}
6970
},
7071
computed: {

0 commit comments

Comments
 (0)