Skip to content

Commit 44c62cb

Browse files
authored
fix: support two versions of OO config JWT token (#4789)
## Summary PR #4781 switched the payload from `editor` to `editorConfig` for newer ONLYOFFICE versions. Add temporary ONLYOFFICE config compatibility by returning both editor config field names in the office open payload: - `editorConfig` for newer ONLYOFFICE versions - `editor` for older consumers Both fields are populated with the same values, and the JWT signing path sanitizes/signs both fields consistently.
2 parents 71c93be + d1acaa1 commit 44c62cb

2 files changed

Lines changed: 66 additions & 49 deletions

File tree

model/sharing/open_office.go

Lines changed: 62 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,51 @@ type apiOfficeURL struct {
2828
}
2929

3030
type onlyOffice struct {
31-
URL string `json:"url,omitempty"`
32-
Token string `json:"token,omitempty"`
33-
Type string `json:"documentType"`
34-
Doc struct {
35-
Filetype string `json:"filetype,omitempty"`
36-
Key string `json:"key"`
37-
Title string `json:"title,omitempty"`
38-
URL string `json:"url"`
39-
Info struct {
40-
Owner string `json:"owner,omitempty"`
41-
Uploaded string `json:"uploaded,omitempty"`
42-
} `json:"info"`
43-
} `json:"document"`
44-
Editor struct {
45-
Callback string `json:"callbackUrl"`
46-
Lang string `json:"lang,omitempty"`
47-
Mode string `json:"mode"`
48-
Custom struct {
49-
CompactHeader bool `json:"compactHeader"`
50-
Customer struct {
51-
Address string `json:"address"`
52-
Logo string `json:"logo"`
53-
Mail string `json:"mail"`
54-
Name string `json:"name"`
55-
WWW string `json:"www"`
56-
} `json:"customer"`
57-
Feedback bool `json:"feedback"`
58-
ForceSave bool `json:"forcesave"`
59-
GoBack bool `json:"goback"`
60-
} `json:"customization"`
61-
} `json:"editorConfig"`
31+
URL string `json:"url,omitempty"`
32+
Token string `json:"token,omitempty"`
33+
Type string `json:"documentType"`
34+
Doc onlyOfficeDoc `json:"document"`
35+
EditorConfig onlyOfficeEditor `json:"editorConfig"`
36+
Editor onlyOfficeEditor `json:"editor"`
37+
}
38+
39+
type onlyOfficeDoc struct {
40+
Filetype string `json:"filetype,omitempty"`
41+
Key string `json:"key"`
42+
Title string `json:"title,omitempty"`
43+
URL string `json:"url"`
44+
Info struct {
45+
Owner string `json:"owner,omitempty"`
46+
Uploaded string `json:"uploaded,omitempty"`
47+
} `json:"info"`
48+
}
49+
50+
type onlyOfficeEditor struct {
51+
Callback string `json:"callbackUrl"`
52+
Lang string `json:"lang,omitempty"`
53+
Mode string `json:"mode"`
54+
Custom struct {
55+
CompactHeader bool `json:"compactHeader"`
56+
Customer struct {
57+
Address string `json:"address"`
58+
Logo string `json:"logo"`
59+
Mail string `json:"mail"`
60+
Name string `json:"name"`
61+
WWW string `json:"www"`
62+
} `json:"customer"`
63+
Feedback bool `json:"feedback"`
64+
ForceSave bool `json:"forcesave"`
65+
GoBack bool `json:"goback"`
66+
} `json:"customization"`
67+
}
68+
69+
func (e *onlyOfficeEditor) sanitizeClaims() {
70+
e.Lang = ""
71+
e.Custom.Customer.Address = ""
72+
e.Custom.Customer.Logo = ""
73+
e.Custom.Customer.Mail = ""
74+
e.Custom.Customer.Name = ""
75+
e.Custom.Customer.WWW = ""
6276
}
6377

6478
func (o *apiOfficeURL) ID() string { return o.FileID }
@@ -83,12 +97,8 @@ func (o *apiOfficeURL) sign(cfg *config.Office) (string, error) {
8397
claims.Doc.Title = ""
8498
claims.Doc.Info.Owner = ""
8599
claims.Doc.Info.Uploaded = ""
86-
claims.Editor.Lang = ""
87-
claims.Editor.Custom.Customer.Address = ""
88-
claims.Editor.Custom.Customer.Logo = ""
89-
claims.Editor.Custom.Customer.Mail = ""
90-
claims.Editor.Custom.Customer.Name = ""
91-
claims.Editor.Custom.Customer.WWW = ""
100+
claims.EditorConfig.sanitizeClaims()
101+
claims.Editor.sanitizeClaims()
92102
token := jwt.NewWithClaims(jwt.SigningMethodHS256, &claims)
93103
return token.SignedString([]byte(cfg.InboxSecret))
94104
}
@@ -212,18 +222,21 @@ func (o *OfficeOpener) openLocalDocument(memberIndex int, readOnly bool) (*apiOf
212222
doc.OO.Doc.URL = download
213223
doc.OO.Doc.Info.Owner = publicName
214224
doc.OO.Doc.Info.Uploaded = uploadedDate(o.File)
215-
doc.OO.Editor.Callback = o.Inst.PageURL("/office/callback", nil)
216-
doc.OO.Editor.Lang = o.Inst.Locale
217-
doc.OO.Editor.Mode = mode
218-
doc.OO.Editor.Custom.CompactHeader = true
219-
doc.OO.Editor.Custom.Customer.Address = "\"Le Surena\" Face au 5 Quai Marcel Dassault 92150 Suresnes"
220-
doc.OO.Editor.Custom.Customer.Logo = o.Inst.FromURL(&url.URL{Path: "/assets/icon-192.png"})
221-
doc.OO.Editor.Custom.Customer.Mail = o.Inst.SupportEmailAddress()
222-
doc.OO.Editor.Custom.Customer.Name = "Twake Workplace"
223-
doc.OO.Editor.Custom.Customer.WWW = "cozy.io"
224-
doc.OO.Editor.Custom.Feedback = false
225-
doc.OO.Editor.Custom.ForceSave = true
226-
doc.OO.Editor.Custom.GoBack = false
225+
editor := onlyOfficeEditor{}
226+
editor.Callback = o.Inst.PageURL("/office/callback", nil)
227+
editor.Lang = o.Inst.Locale
228+
editor.Mode = mode
229+
editor.Custom.CompactHeader = true
230+
editor.Custom.Customer.Address = "\"Le Surena\" Face au 5 Quai Marcel Dassault 92150 Suresnes"
231+
editor.Custom.Customer.Logo = o.Inst.FromURL(&url.URL{Path: "/assets/icon-192.png"})
232+
editor.Custom.Customer.Mail = o.Inst.SupportEmailAddress()
233+
editor.Custom.Customer.Name = "Twake Workplace"
234+
editor.Custom.Customer.WWW = "cozy.io"
235+
editor.Custom.Feedback = false
236+
editor.Custom.ForceSave = true
237+
editor.Custom.GoBack = false
238+
doc.OO.EditorConfig = editor
239+
doc.OO.Editor = editor
227240

228241
token, err := doc.sign(cfg)
229242
if err != nil {

web/office/office_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ func TestOffice(t *testing.T) {
7575
editor.ValueEqual("mode", "edit")
7676
editor.Value("callbackUrl").String().HasSuffix("/office/callback")
7777

78+
legacyEditor := oo.Value("editor").Object()
79+
legacyEditor.ValueEqual("mode", "edit")
80+
legacyEditor.Value("callbackUrl").String().HasSuffix("/office/callback")
81+
7882
document := oo.Value("document").Object()
7983
key = document.Value("key").String().NotEmpty().Raw()
8084
})

0 commit comments

Comments
 (0)