Skip to content

Commit 975768f

Browse files
committed
Merge branch 'release-0.24'
2 parents 00bf1ef + 6e96755 commit 975768f

File tree

17 files changed

+221
-95
lines changed

17 files changed

+221
-95
lines changed

Makefile.am

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ install:
124124
@echo "Installing static resources to: $(SHARE)"
125125
$(INSTALL) -d $(BIN)
126126
$(INSTALL) -d $(SHARE)/www/html
127+
$(INSTALL) -d $(SHARE)/www/html/sandboxes
127128
$(INSTALL) -d $(SHARE)/www/static
128129
$(INSTALL) -d $(SHARE)/www/static/img
129130
$(INSTALL) -d $(SHARE)/www/static/sounds
@@ -133,7 +134,8 @@ install:
133134
$(INSTALL) -d $(SHARE)/www/static/js/libs/pdf
134135
$(INSTALL) -d $(SHARE)/www/static/js/sandboxes
135136
$(INSTALL) bin/$(EXENAME) $(BIN)
136-
$(INSTALL) html/* $(SHARE)/www/html
137+
$(INSTALL) html/*.html $(SHARE)/www/html
138+
$(INSTALL) html/sandboxes/*.html $(SHARE)/www/html/sandboxes
137139
$(INSTALL) static/img/* $(SHARE)/www/static/img
138140
$(INSTALL) static/sounds/* $(SHARE)/www/static/sounds
139141
$(INSTALL) static/fonts/* $(SHARE)/www/static/fonts

build/build.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@
5050
]
5151
},
5252
{
53-
name: 'base',
54-
include: [
55-
'pdf.compatibility'
56-
]
53+
name: 'base'
5754
},
5855
{
5956
name: 'app',
@@ -64,14 +61,21 @@
6461
inlineText: true,
6562
},
6663
{
67-
name: 'pdf',
64+
name: 'libs/pdf/pdf',
6865
dir: './out/libs/pdf',
69-
exclude: [
70-
'base'
71-
]
66+
override: {
67+
skipModuleInsertion: true
68+
}
69+
},
70+
{
71+
name: 'libs/pdf/compatibility',
72+
dir: './out/libs/compatibility',
73+
override: {
74+
skipModuleInsertion: true
75+
}
7276
},
7377
{
74-
name: 'pdf.worker',
78+
name: 'libs/pdf/pdf.worker',
7579
dir: './out/libs/pdf',
7680
override: {
7781
skipModuleInsertion: true

debian/changelog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
spreed-webrtc-server (0.24.1) precise; urgency=low
2+
3+
* Load sandboxes on demand, generated by server.
4+
* ODF and PDF sandboxes now use CSP from HTTP response header.
5+
* No longer include obsolete sandbox stuff in base scripts.
6+
* Sandbox iframes are now always created on demand.
7+
* Don't return users twice in "Welcome" from global room.
8+
9+
-- Simon Eisenmann <[email protected]> Fri, 03 Jul 2015 11:43:56 +0200
10+
111
spreed-webrtc-server (0.24.0) precise; urgency=low
212

313
* Added hover actions on buddy picture in group chat.

static/partials/odfcanvas_sandbox.html renamed to html/sandboxes/odfcanvas_sandbox.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html>
33
<head>
44
<title>WebODF Sandbox</title>
5-
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src __PARENT_ORIGIN__; img-src data:; style-src 'unsafe-inline'">
5+
<base href="<%.Cfg.B%>">
66
<style type="text/css">
77
html, body {
88
height:100%;
@@ -35,6 +35,6 @@
3535
<div id="container">
3636
<div id="odfcanvas"></div>
3737
</div>
38-
<script src="__WEBODF_SANDBOX_JS_URL__" data-parent-origin="__PARENT_ORIGIN__" data-webodf-url="__WEBODF_URL__"></script>
38+
<script src="<%.Cfg.S%>/js/sandboxes/webodf.js" data-parent-origin="<%.Origin%>" data-webodf-url="<%.Cfg.S%>/js/libs/webodf.js"></script>
3939
</body>
4040
</html>

static/partials/pdfcanvas_sandbox.html renamed to html/sandboxes/pdfcanvas_sandbox.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html>
33
<head>
44
<title>pdf.js Sandbox</title>
5-
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src __PARENT_ORIGIN__ 'unsafe-eval'; img-src 'self'; style-src 'unsafe-inline'">
5+
<base href="<%.Cfg.B%>">
66
<style type="text/css">
77
html, body {
88
height:100%;
@@ -29,6 +29,6 @@
2929
<div id="container">
3030
<canvas id="canvas0"></canvas><canvas id="canvas1"></canvas>
3131
</div>
32-
<script src="__PDFJS_SANDBOX_JS_URL__" data-parent-origin="__PARENT_ORIGIN__" data-pdfjs-url="__PDFJS_URL__" data-pdfjs-worker-url="__PDFJS_WORKER_URL__" data-pdfjs-compatibility-url="__PDFJS_COMPATIBILITY_URL__"></script>
32+
<script src="<%.Cfg.S%>/js/sandboxes/pdf.js" data-parent-origin="<%.Origin%>" data-pdfjs-url="<%.Cfg.S%>/js/libs/pdf/pdf.js" data-pdfjs-worker-url="<%.Cfg.S%>/js/libs/pdf/pdf.worker.js" data-pdfjs-compatibility-url="<%.Cfg.S%>/js/libs/pdf/compatibility.js"></script>
3333
</body>
3434
</html>

static/partials/youtubevideo_sandbox.html renamed to html/sandboxes/youtubevideo_sandbox.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<html>
33
<head>
44
<title>YouTube Player Sandbox</title>
5-
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src __PARENT_ORIGIN__ https://www.youtube.com https://s.ytimg.com 'unsafe-eval'; frame-src https://www.youtube.com; style-src 'unsafe-inline'">
5+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src <%.Origin%> https://www.youtube.com https://s.ytimg.com 'unsafe-eval'; frame-src https://www.youtube.com; style-src 'unsafe-inline'">
6+
<base href="<%.Cfg.B%>">
67
<style type="text/css">
78
html, body {
89
height:100%;
@@ -22,6 +23,6 @@
2223
</head>
2324
<body>
2425
<div id="youtubeplayer"></div>
25-
<script src="__YOUTUBE_SANDBOX_JS_URL__" data-parent-origin="__PARENT_ORIGIN__"></script>
26+
<script src="<%.Cfg.S%>/js/sandboxes/youtube.js" data-parent-origin="<%.Origin%>"></script>
2627
</body>
2728
</html>

src/app/spreed-webrtc-server/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ type Context struct {
3030
Languages []string
3131
Room string `json:"-"`
3232
Scheme string `json:"-"`
33+
Origin string `json:",omitempty"`
3334
}

src/app/spreed-webrtc-server/main.go

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ import (
3636
"log"
3737
"net/http"
3838
_ "net/http/pprof"
39+
"net/url"
3940
"os"
4041
"path"
42+
"path/filepath"
4143
goruntime "runtime"
4244
"strconv"
45+
"strings"
4346
"syscall"
4447
"time"
4548
)
@@ -75,6 +78,20 @@ func roomHandler(w http.ResponseWriter, r *http.Request) {
7578

7679
}
7780

81+
func sandboxHandler(w http.ResponseWriter, r *http.Request) {
82+
83+
vars := mux.Vars(r)
84+
// NOTE(longsleep): origin_scheme is window.location.protocol (eg. https:, http:).
85+
originURL, err := url.Parse(fmt.Sprintf("%s//%s", vars["origin_scheme"], vars["origin_host"]))
86+
if err != nil || originURL.Scheme == "" || originURL.Host == "" {
87+
http.Error(w, "Invalid origin path", http.StatusBadRequest)
88+
return
89+
}
90+
origin := fmt.Sprintf("%s://%s", originURL.Scheme, originURL.Host)
91+
handleSandboxView(vars["sandbox"], origin, w, r)
92+
93+
}
94+
7895
func makeImageHandler(buddyImages ImageCache, expires time.Duration) http.HandlerFunc {
7996

8097
return func(w http.ResponseWriter, r *http.Request) {
@@ -158,6 +175,42 @@ func handleRoomView(room string, w http.ResponseWriter, r *http.Request) {
158175

159176
}
160177

178+
func handleSandboxView(sandbox string, origin string, w http.ResponseWriter, r *http.Request) {
179+
180+
w.Header().Set("Content-Type", "text/html; charset=UTF-8")
181+
w.Header().Set("Expires", "-1")
182+
w.Header().Set("Cache-Control", "private, max-age=0")
183+
184+
sandboxTemplateName := fmt.Sprintf("%s_sandbox.html", sandbox)
185+
186+
// Prepare context to deliver to HTML..
187+
if t := templates.Lookup(sandboxTemplateName); t != nil {
188+
189+
// CSP support for sandboxes.
190+
var csp string
191+
switch sandbox {
192+
case "odfcanvas":
193+
csp = fmt.Sprintf("default-src 'none'; script-src %s; img-src data: blob:; style-src 'unsafe-inline'", origin)
194+
case "pdfcanvas":
195+
csp = fmt.Sprintf("default-src 'none'; script-src %s 'unsafe-eval'; img-src 'self' data: blob:; style-src 'unsafe-inline'", origin)
196+
default:
197+
csp = "default-src 'none'"
198+
}
199+
w.Header().Set("Content-Security-Policy", csp)
200+
201+
// Prepare context to deliver to HTML..
202+
context := &Context{Cfg: config, Origin: origin, Csp: true}
203+
err := t.Execute(w, &context)
204+
if err != nil {
205+
http.Error(w, err.Error(), http.StatusInternalServerError)
206+
}
207+
208+
} else {
209+
http.Error(w, "404 Unknown Sandbox", http.StatusNotFound)
210+
}
211+
212+
}
213+
161214
func runner(runtime phoenix.Runtime) error {
162215

163216
log.SetFlags(log.LstdFlags | log.Lmicroseconds)
@@ -257,10 +310,21 @@ func runner(runtime phoenix.Runtime) error {
257310
config = NewConfig(runtime, tokenProvider != nil)
258311

259312
// Load templates.
260-
tt := template.New("")
261-
tt.Delims("<%", "%>")
262-
263-
templates, err = tt.ParseGlob(path.Join(rootFolder, "html", "*.html"))
313+
templates = template.New("")
314+
templates.Delims("<%", "%>")
315+
316+
// Load html templates folder
317+
err = filepath.Walk(path.Join(rootFolder, "html"), func(path string, info os.FileInfo, err error) error {
318+
if err == nil {
319+
if strings.HasSuffix(path, ".html") {
320+
_, err = templates.ParseFiles(path)
321+
if err != nil {
322+
return err
323+
}
324+
}
325+
}
326+
return nil
327+
})
264328
if err != nil {
265329
return fmt.Errorf("Failed to load templates: %s", err)
266330
}
@@ -335,7 +399,7 @@ func runner(runtime phoenix.Runtime) error {
335399
runtime.DefaultHTTPSHandler(r)
336400
}
337401

338-
// Add handlers.
402+
// Prepare services.
339403
buddyImages := NewImageCache()
340404
codec := NewCodec(incomingCodecLimit)
341405
roomManager := NewRoomManager(config, codec)
@@ -344,6 +408,8 @@ func runner(runtime phoenix.Runtime) error {
344408
sessionManager := NewSessionManager(config, tickets, hub, roomManager, roomManager, buddyImages, sessionSecret)
345409
statsManager := NewStatsManager(hub, roomManager, sessionManager)
346410
channellingAPI := NewChannellingAPI(config, roomManager, tickets, sessionManager, statsManager, hub, hub, hub)
411+
412+
// Add handlers.
347413
r.HandleFunc("/", httputils.MakeGzipHandler(mainHandler))
348414
r.Handle("/static/img/buddy/{flags}/{imageid}/{idx:.*}", http.StripPrefix(config.B, makeImageHandler(buddyImages, time.Duration(24)*time.Hour)))
349415
r.Handle("/static/{path:.*}", http.StripPrefix(config.B, httputils.FileStaticServer(http.Dir(rootFolder))))
@@ -354,6 +420,9 @@ func runner(runtime phoenix.Runtime) error {
354420
// Simple room handler.
355421
r.HandleFunc("/{room}", httputils.MakeGzipHandler(roomHandler))
356422

423+
// Sandbox handler.
424+
r.HandleFunc("/sandbox/{origin_scheme}/{origin_host}/{sandbox}.html", httputils.MakeGzipHandler(sandboxHandler))
425+
357426
// Add API end points.
358427
api := sloth.NewAPI()
359428
api.SetMux(r.PathPrefix("/api/v1/").Subrouter())

src/app/spreed-webrtc-server/roomworker.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,12 @@ func (r *roomWorker) GetUsers() []*DataSession {
207207
}
208208
}
209209
r.mutex.RUnlock()
210-
// Include connections to global room.
211-
for _, ec := range r.manager.GlobalUsers() {
212-
if !appender(ec) {
213-
break
210+
if r.id != r.manager.globalRoomID {
211+
// Include connections to global room.
212+
for _, ec := range r.manager.GlobalUsers() {
213+
if !appender(ec) {
214+
break
215+
}
214216
}
215217
}
216218

static/js/directives/odfcanvas.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121

2222
"use strict";
23-
define(['require', 'underscore', 'jquery', 'text!partials/odfcanvas_sandbox.html'], function(require, _, $, sandboxTemplate) {
23+
define(['require', 'underscore', 'jquery'], function(require, _, $) {
2424

2525
return ["$window", "$compile", "$http", "translation", "safeApply", "restURL", "sandbox", function($window, $compile, $http, translation, safeApply, restURL, sandbox) {
2626

@@ -31,14 +31,13 @@ define(['require', 'underscore', 'jquery', 'text!partials/odfcanvas_sandbox.html
3131
var controller = ['$scope', '$element', '$attrs', function($scope, $element, $attrs) {
3232

3333
var container = $($element);
34-
3534
var odfCanvas;
36-
37-
var template = sandboxTemplate;
38-
template = template.replace(/__PARENT_ORIGIN__/g, $window.location.protocol + "//" + $window.location.host);
39-
template = template.replace(/__WEBODF_SANDBOX_JS_URL__/g, restURL.createAbsoluteUrl(require.toUrl('sandboxes/webodf') + ".js"));
40-
template = template.replace(/__WEBODF_URL__/g, restURL.createAbsoluteUrl(require.toUrl('webodf') + ".js"));
41-
var sandboxApi = sandbox.createSandbox($("iframe", container)[0], template);
35+
var url = restURL.sandbox("odfcanvas");
36+
var sandboxApi = sandbox.createSandbox(container, null, url, "allow-scripts", null, {
37+
allowfullscreen: true,
38+
mozallowfullscreen: true,
39+
webkitallowfullscreen: true
40+
});
4241

4342
sandboxApi.e.on("message", function(event, message) {
4443
var msg = message.data;
@@ -231,7 +230,7 @@ define(['require', 'underscore', 'jquery', 'text!partials/odfcanvas_sandbox.html
231230
return {
232231
restrict: 'E',
233232
replace: true,
234-
template: '<div class="canvasContainer odfcontainer"><iframe allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" sandbox="allow-scripts"></iframe></div>',
233+
template: '<div class="canvasContainer odfcontainer"></div>',
235234
controller: controller
236235
};
237236

0 commit comments

Comments
 (0)