Skip to content

Commit 10919e4

Browse files
authored
Help the dataproxy cleaning its data (#4483)
2 parents f2093b6 + df20ecc commit 10919e4

File tree

8 files changed

+99
-35
lines changed

8 files changed

+99
-35
lines changed

assets/templates/login.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,6 @@ <h1 class="h4 h2-md mb-0 text-center">{{.Title}}</h1>
124124
<script src="{{asset .Domain "/scripts/password-helpers.js"}}"></script>
125125
<script src="{{asset .Domain "/scripts/password-visibility.js"}}"></script>
126126
<script src="{{asset .Domain "/scripts/login.js"}}"></script>
127+
<iframe src="{{.DataProxyCleanURL}}"></iframe>
127128
</body>
128129
</html>

docs/settings.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ an HTML error page will appears.
158158

159159
```http
160160
HTTP/1.1 307 Temporary Redirect
161-
Location: http://alice-settings.cozy.localhost:8080
161+
Location: http://alice-settings.cozy.localhost:8080
162162
```
163163

164164

@@ -367,7 +367,7 @@ route is necessary to actually update the passphrase. See below.
367367
A `"force": true` parameter can be added in the JSON to force a passphrase on a
368368
Cozy where authentication by password is disabled and the vault is empty. It
369369
allows to use Cozy Pass when the authentication on the Cozy is delegated via
370-
OIDC. When forcing a password reset, you need to regenerate the
370+
OIDC. When forcing a password reset, you need to regenerate the
371371

372372
* public and private keys
373373
* encryption key
@@ -923,6 +923,37 @@ Content-Type: application/json
923923
This route requires the application to have permissions on the
924924
`io.cozy.sessions` doctype with the `GET` verb.
925925

926+
### GET /settings/sessions/current
927+
928+
This route returns information about the current session.
929+
930+
```
931+
GET /settings/sessions/current HTTP/1.1
932+
Host: cozy.example.org
933+
Cookie: ...
934+
Authorization: Bearer ...
935+
```
936+
937+
```http
938+
HTTP/1.1 200 OK
939+
Content-Type: application/json
940+
```
941+
942+
```json
943+
{
944+
"data": {
945+
"id": "...",
946+
"attributes": {
947+
"last_seen": "",
948+
"long_run": true
949+
},
950+
"meta": {
951+
"rev": "..."
952+
}
953+
}
954+
}
955+
```
956+
926957
## OAuth 2 clients
927958

928959
### GET /settings/clients

model/instance/instance.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,14 @@ func (i *Instance) ChangePasswordURL() string {
546546
return u.String()
547547
}
548548

549+
// DataProxyCleanURL returns the URL of the DataProxy iframe for cleaning
550+
// PouchDB.
551+
func (i *Instance) DataProxyCleanURL() string {
552+
u := i.SubDomain(consts.DataProxySlug)
553+
u.Path = "/reset"
554+
return u.String()
555+
}
556+
549557
// FromURL normalizes a given url with the scheme and domain of the instance.
550558
func (i *Instance) FromURL(u *url.URL) string {
551559
u2 := url.URL{

pkg/consts/consts.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ const (
2121
// PassSlug is the slug of cozy-pass webapp, which is used by the stack for
2222
// linking the bitwarden OAuth clients.
2323
PassSlug = "passwords"
24+
// DataProxySlug is the slug of the dataproxy webapp, which is used for
25+
// embedding a PouchDB in the client (used by the search for example).
26+
DataProxySlug = "dataproxy"
2427
)
2528

2629
const (

web/apps/serve.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@ func ServeAppFile(c echo.Context, i *instance.Instance, fs appfs.FileServer, web
261261
handleIntent(c, i, slug, intentID)
262262
}
263263

264+
if route.Public && slug == consts.DataProxySlug {
265+
// Allow to dataproxy to be embedded in a iframe from the login page of the
266+
// stack for cleaning.
267+
middlewares.AppendCSPRule(c, "frame-ancestors", i.PageURL("/", nil))
268+
}
269+
264270
// For index file, we inject the locale, the stack domain, and a token if the
265271
// user is connected
266272
content, err := fs.Open(slug, version, shasum, filepath)

web/auth/auth.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ func renderLoginForm(c echo.Context, i *instance.Instance, code int, credsErrors
207207
magicLink = false
208208
}
209209

210+
dataProxyCleanURL := i.DataProxyCleanURL()
211+
csp := c.Response().Header().Get(echo.HeaderContentSecurityPolicy)
212+
csp = strings.Replace(csp, "frame-src 'none'", "frame-src "+dataProxyCleanURL+" ", 1)
213+
c.Response().Header().Set(echo.HeaderContentSecurityPolicy, csp)
214+
210215
return c.Render(code, "login.html", echo.Map{
211216
"TemplateTitle": i.TemplateTitle(),
212217
"Domain": i.ContextualDomain(),
@@ -226,6 +231,7 @@ func renderLoginForm(c echo.Context, i *instance.Instance, code int, credsErrors
226231
"MagicLink": magicLink,
227232
"OAuth": hasOAuth,
228233
"FranceConnect": hasFranceConnect,
234+
"DataProxyCleanURL": dataProxyCleanURL,
229235
})
230236
}
231237

web/settings/settings.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ func (h *HTTPHandler) getSessions(c echo.Context) error {
6969
return jsonapi.DataList(c, http.StatusOK, objs, nil)
7070
}
7171

72+
func (h *HTTPHandler) getCurrentSession(c echo.Context) error {
73+
sess, ok := middlewares.GetSession(c)
74+
if !ok {
75+
return jsonapi.NotFound(errors.New("no current session"))
76+
}
77+
return jsonapi.Data(c, http.StatusOK, &apiSession{sess}, nil)
78+
}
79+
7280
func (h *HTTPHandler) listWarnings(c echo.Context) error {
7381
inst := middlewares.GetInstance(c)
7482

@@ -276,6 +284,7 @@ func (h *HTTPHandler) Register(router *echo.Group) {
276284
router.GET("/flags", h.getFlags)
277285

278286
router.GET("/sessions", h.getSessions)
287+
router.GET("/sessions/current", h.getCurrentSession)
279288

280289
router.GET("/clients", h.listClients)
281290
router.DELETE("/clients/:id", h.revokeClient)

web/statik/statik.go

Lines changed: 33 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)