@lango-project/lango-server 0.2.4 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -5
- package/dist/body_reader.mjs.map +1 -1
- package/dist/builder.mjs.map +1 -1
- package/dist/cli/server.mjs +3 -838
- package/dist/cli/server.mjs.map +1 -1
- package/dist/client_identity.mjs.map +1 -1
- package/dist/database.mjs.map +1 -1
- package/dist/database_action.mjs.map +1 -1
- package/dist/database_options.mjs.map +1 -1
- package/dist/database_scope.mjs.map +1 -1
- package/dist/endpoint.mjs.map +1 -1
- package/dist/error_details.mjs.map +1 -1
- package/dist/execution_failure.mjs.map +1 -1
- package/dist/execution_identity.mjs.map +1 -1
- package/dist/execution_log.mjs.map +1 -1
- package/dist/execution_runtime.mjs.map +1 -1
- package/dist/execution_worker.mjs.map +1 -1
- package/dist/executor.mjs.map +1 -1
- package/dist/group.mjs.map +1 -1
- package/dist/http_failure.mjs.map +1 -1
- package/dist/job_configuration.mjs.map +1 -1
- package/dist/job_context.mjs.map +1 -1
- package/dist/library.mjs.map +1 -1
- package/dist/longpoll_broker.mjs.map +1 -1
- package/dist/longpoll_options.mjs.map +1 -1
- package/dist/longpoll_session.mjs.map +1 -1
- package/dist/middleware.mjs.map +1 -1
- package/dist/module_loader.mjs.map +1 -1
- package/dist/options.mjs.map +1 -1
- package/dist/origin.mjs.map +1 -1
- package/dist/policy.mjs.map +1 -1
- package/dist/postgres_adapter.mjs.map +1 -1
- package/dist/postgres_worker.mjs.map +1 -1
- package/dist/queue_provider.mjs.map +1 -1
- package/dist/request_identity.mjs.map +1 -1
- package/dist/response.mjs +1 -1
- package/dist/response.mjs.map +1 -1
- package/dist/route_info.mjs +5 -1
- package/dist/route_info.mjs.map +1 -1
- package/dist/route_pattern.mjs.map +1 -1
- package/dist/routes.mjs +27 -4
- package/dist/routes.mjs.map +1 -1
- package/dist/runtime.mjs +66 -11
- package/dist/runtime.mjs.map +1 -1
- package/dist/server.mjs +2 -1
- package/dist/server.mjs.map +1 -1
- package/dist/server_context.mjs.map +1 -1
- package/dist/sqlite_adapter.mjs.map +1 -1
- package/dist/static_files.mjs.map +1 -1
- package/dist/token.mjs.map +1 -1
- package/dist/tokens.mjs +4 -1
- package/dist/tokens.mjs.map +1 -1
- package/dist/trace.mjs +6 -1
- package/dist/trace.mjs.map +1 -1
- package/dist/worker.mjs.map +1 -1
- package/docs/browser-sessions.md +96 -0
- package/examples/security/package.json +1 -1
- package/package.json +8 -5
- package/src/response.lango +1 -1
- package/src/route_info.lango +5 -2
- package/src/routes.lango +20 -3
- package/src/runtime.lango +56 -11
- package/src/server.lango +3 -2
- package/src/tokens.lango +4 -0
- package/src/trace.lango +5 -2
- package/dist/cli/.lango/bignumber.mjs +0 -3119
- package/dist/cli/.lango/localization.mjs +0 -108
- package/dist/cli/.lango/runtime.mjs +0 -725
- package/dist/cli/.lango/vendor/i18next.LICENSE +0 -21
- package/dist/cli/.lango/vendor/i18next.mjs +0 -2434
- package/dist/cli/.lango/xmldom/conventions.js +0 -429
- package/dist/cli/.lango/xmldom/dom-parser.js +0 -591
- package/dist/cli/.lango/xmldom/dom.js +0 -3759
- package/dist/cli/.lango/xmldom/entities.js +0 -2171
- package/dist/cli/.lango/xmldom/errors.js +0 -205
- package/dist/cli/.lango/xmldom/grammar.js +0 -559
- package/dist/cli/.lango/xmldom/index.js +0 -41
- package/dist/cli/.lango/xmldom/package.json +0 -1
- package/dist/cli/.lango/xmldom/sax.js +0 -983
- package/dist/cli/.lango/xmldom.LICENSE.md +0 -8
- package/dist/cli/body_reader.mjs +0 -180
- package/dist/cli/body_reader.mjs.map +0 -1
- package/dist/cli/client_identity.mjs +0 -250
- package/dist/cli/client_identity.mjs.map +0 -1
- package/dist/cli/database.mjs +0 -116
- package/dist/cli/database.mjs.map +0 -1
- package/dist/cli/database_options.mjs +0 -83
- package/dist/cli/database_options.mjs.map +0 -1
- package/dist/cli/database_scope.mjs +0 -93
- package/dist/cli/database_scope.mjs.map +0 -1
- package/dist/cli/endpoint.mjs +0 -50
- package/dist/cli/endpoint.mjs.map +0 -1
- package/dist/cli/error_details.mjs +0 -45
- package/dist/cli/error_details.mjs.map +0 -1
- package/dist/cli/longpoll_broker.mjs +0 -215
- package/dist/cli/longpoll_broker.mjs.map +0 -1
- package/dist/cli/longpoll_options.mjs +0 -103
- package/dist/cli/longpoll_options.mjs.map +0 -1
- package/dist/cli/longpoll_session.mjs +0 -136
- package/dist/cli/longpoll_session.mjs.map +0 -1
- package/dist/cli/middleware.mjs +0 -25
- package/dist/cli/middleware.mjs.map +0 -1
- package/dist/cli/options.mjs +0 -214
- package/dist/cli/options.mjs.map +0 -1
- package/dist/cli/origin.mjs +0 -87
- package/dist/cli/origin.mjs.map +0 -1
- package/dist/cli/policy.mjs +0 -121
- package/dist/cli/policy.mjs.map +0 -1
- package/dist/cli/postgres_adapter.mjs +0 -178
- package/dist/cli/postgres_adapter.mjs.map +0 -1
- package/dist/cli/route_pattern.mjs +0 -129
- package/dist/cli/route_pattern.mjs.map +0 -1
- package/dist/cli/routes.mjs +0 -360
- package/dist/cli/routes.mjs.map +0 -1
- package/dist/cli/sqlite_adapter.mjs +0 -163
- package/dist/cli/sqlite_adapter.mjs.map +0 -1
- package/dist/cli/static_files.mjs +0 -224
- package/dist/cli/static_files.mjs.map +0 -1
- package/dist/cli/trace.mjs +0 -53
- package/dist/cli/trace.mjs.map +0 -1
package/src/runtime.lango
CHANGED
|
@@ -133,11 +133,17 @@ Runtime:prepareRoute(pending, route)
|
|
|
133
133
|
then(handler)
|
|
134
134
|
capture route
|
|
135
135
|
middleware = null
|
|
136
|
+
bootstrap = false
|
|
136
137
|
name = route.middleware
|
|
137
138
|
if name != null
|
|
138
139
|
if !Object/hasOwn(@middlewares, name)
|
|
139
140
|
throw "Middleware is not registered: ${name}"
|
|
140
141
|
middleware = @middlewares[name]
|
|
142
|
+
specs = @definition.middlewares
|
|
143
|
+
spec = specs[name]
|
|
144
|
+
bootstrap = spec.bootstrap == true
|
|
145
|
+
if bootstrap and (route.policy != "anonymous" or route.reauthSeconds > 0 or route.path.includes("*") or route.path.includes("{") or route.path.includes("}"))
|
|
146
|
+
throw "Bootstrap middleware requires an exact anonymous endpoint without reauthentication"
|
|
141
147
|
@routes.add({
|
|
142
148
|
path: route.path
|
|
143
149
|
pattern: routePattern(route.path)
|
|
@@ -147,6 +153,7 @@ Runtime:prepareRoute(pending, route)
|
|
|
147
153
|
legacyAuth: route.legacyAuth
|
|
148
154
|
handler: handler
|
|
149
155
|
middleware: middleware
|
|
156
|
+
bootstrap: bootstrap
|
|
150
157
|
})
|
|
151
158
|
return null
|
|
152
159
|
|
|
@@ -190,19 +197,31 @@ Runtime:handle(task)
|
|
|
190
197
|
context log
|
|
191
198
|
if !originAllowed(@definition.settings.origin, request)
|
|
192
199
|
return failure(403, "OriginRejected")
|
|
193
|
-
|
|
200
|
+
matched = match(request.path)
|
|
201
|
+
bootstrap = false
|
|
202
|
+
if matched != null
|
|
203
|
+
selectedRoute = matched.route
|
|
204
|
+
bootstrap = selectedRoute.bootstrap == true
|
|
205
|
+
authorization = request.headers.authorization
|
|
206
|
+
hint = request.headers["x-lango-startup-token"]
|
|
207
|
+
if authorization == null and bootstrap and @clients == null and hint != null
|
|
208
|
+
authorization = "Bearer ${hint}"
|
|
209
|
+
fresh = authorization == null
|
|
194
210
|
claims = null
|
|
195
211
|
try
|
|
196
212
|
if !fresh
|
|
197
|
-
claims = @tokens.read(
|
|
213
|
+
claims = @tokens.read(authorization)
|
|
198
214
|
catch error
|
|
215
|
+
if error == "TokenExpired"
|
|
216
|
+
return expiredSession()
|
|
199
217
|
log.warn("[${request.id}] ${request.method} ${request.path} Authorization rejected before handler: ${errorMessage(error)}")
|
|
200
218
|
return failure(401, "Unauthorized")
|
|
201
|
-
matched = match(request.path)
|
|
202
219
|
if matched == null
|
|
203
220
|
trace("[${request.id}] No route matched ${request.path}")
|
|
204
221
|
return failure(404, "RouteNotFound")
|
|
205
222
|
route = matched.route
|
|
223
|
+
if hint != null and !bootstrap
|
|
224
|
+
return failure(400, "InvalidStartupRequest")
|
|
206
225
|
metadata = routeInfo([route])
|
|
207
226
|
selected = Object/freeze(metadata[0])
|
|
208
227
|
context request = Object/freeze(Object/assign({}, request, {
|
|
@@ -226,6 +245,10 @@ Runtime:handle(task)
|
|
|
226
245
|
try
|
|
227
246
|
if @clients != null
|
|
228
247
|
context clientIdentity = @clients.begin(claims, @tokens)
|
|
248
|
+
if bootstrap and !clientIdentity.fresh
|
|
249
|
+
clientIdentity.claims = @tokens.create(clientIdentity.claims.clientId)
|
|
250
|
+
clientIdentity.claims.clientProof = clientIdentity.hash
|
|
251
|
+
clientIdentity.restored = true
|
|
229
252
|
claims = clientIdentity.claims
|
|
230
253
|
fresh = clientIdentity.fresh
|
|
231
254
|
restored = clientIdentity.restored
|
|
@@ -358,7 +381,9 @@ Runtime:process(task, route, input, claims, fresh, restored)
|
|
|
358
381
|
closeScope(db, false)
|
|
359
382
|
if is_kindof(error, HttpFailure)
|
|
360
383
|
return error.result()
|
|
361
|
-
if error == "TokenExpired"
|
|
384
|
+
if error == "TokenExpired"
|
|
385
|
+
return expiredSession()
|
|
386
|
+
if is_object(error) and error.status == 401
|
|
362
387
|
log.warn("${requestIdentity(request.id, token)} ${request.method} ${request.path} Authorization or validation rejected: Unauthorized")
|
|
363
388
|
return failure(401, "Unauthorized")
|
|
364
389
|
log.err("${requestIdentity(request.id, token)} Request failed: ${errorDetails(error)}")
|
|
@@ -405,11 +430,10 @@ Runtime:refreshOne(pending, results, encoded, owner, child)
|
|
|
405
430
|
capture encoded
|
|
406
431
|
capture owner
|
|
407
432
|
capture child
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
return failure(401, "Unauthorized")
|
|
433
|
+
read = readRefreshToken(encoded)
|
|
434
|
+
if read.rejection != null
|
|
435
|
+
return read.rejection
|
|
436
|
+
checked = read.claims
|
|
413
437
|
if checked.clientId != owner
|
|
414
438
|
return failure(401, "Unauthorized")
|
|
415
439
|
return handle({
|
|
@@ -423,13 +447,29 @@ Runtime:refreshOne(pending, results, encoded, owner, child)
|
|
|
423
447
|
updated = null
|
|
424
448
|
if result.status < 400
|
|
425
449
|
updated = result.headers["x-lango-token"]
|
|
426
|
-
|
|
450
|
+
item = {
|
|
427
451
|
previous: encoded
|
|
428
452
|
token: updated
|
|
429
453
|
status: result.status
|
|
430
|
-
}
|
|
454
|
+
}
|
|
455
|
+
if result.headers["x-lango-session"] == "expired"
|
|
456
|
+
item.reason = "SessionExpired"
|
|
457
|
+
results.add(item)
|
|
431
458
|
return null
|
|
432
459
|
|
|
460
|
+
Runtime:readRefreshToken(encoded)
|
|
461
|
+
try
|
|
462
|
+
return {
|
|
463
|
+
claims: @tokens.read("Bearer ${encoded}")
|
|
464
|
+
}
|
|
465
|
+
catch error
|
|
466
|
+
rejected = failure(401, "Unauthorized")
|
|
467
|
+
if error == "TokenExpired"
|
|
468
|
+
rejected = expiredSession()
|
|
469
|
+
return {
|
|
470
|
+
rejection: rejected
|
|
471
|
+
}
|
|
472
|
+
|
|
433
473
|
Runtime:event(name, input)
|
|
434
474
|
if !(name in @events)
|
|
435
475
|
return null
|
|
@@ -540,6 +580,11 @@ failure(status, code)
|
|
|
540
580
|
})
|
|
541
581
|
}
|
|
542
582
|
|
|
583
|
+
expiredSession()
|
|
584
|
+
result = failure(401, "SessionExpired")
|
|
585
|
+
result.headers["x-lango-session"] = "expired"
|
|
586
|
+
return result
|
|
587
|
+
|
|
543
588
|
stampValidation(claims, validatedAt)
|
|
544
589
|
claims.validatedAt = validatedAt
|
|
545
590
|
return null
|
package/src/server.lango
CHANGED
|
@@ -2,7 +2,7 @@ import "./policy"
|
|
|
2
2
|
resolvePolicies(routes, registry)
|
|
3
3
|
import "./trace"
|
|
4
4
|
trace(message)
|
|
5
|
-
responseLog(id, method, path, status)
|
|
5
|
+
responseLog(id, method, path, status, session = null)
|
|
6
6
|
import "./longpoll_broker"
|
|
7
7
|
class LongpollBroker
|
|
8
8
|
import "./longpoll_session"
|
|
@@ -255,7 +255,7 @@ Server:trackResponse(req, res)
|
|
|
255
255
|
return null
|
|
256
256
|
state.done = true
|
|
257
257
|
if res.writableFinished
|
|
258
|
-
responseLog(res.langoRequestId, req.method, target, res.statusCode)
|
|
258
|
+
responseLog(res.langoRequestId, req.method, target, res.statusCode, res.langoSession)
|
|
259
259
|
else
|
|
260
260
|
trace("HTTP ${req.method} ${target} connection closed before response completed")
|
|
261
261
|
record.active = record.active - 1
|
|
@@ -580,6 +580,7 @@ write(res, result)
|
|
|
580
580
|
if res.destroyed or res.writableEnded
|
|
581
581
|
return null
|
|
582
582
|
try
|
|
583
|
+
res.langoSession = result.headers["x-lango-session"]
|
|
583
584
|
res.writeHead(result.status, result.headers)
|
|
584
585
|
res.end(result.body)
|
|
585
586
|
catch error
|
package/src/tokens.lango
CHANGED
|
@@ -51,10 +51,12 @@ Tokens:read(header)
|
|
|
51
51
|
keys = settings.keys
|
|
52
52
|
if !Object/hasOwn(keys, head.kid)
|
|
53
53
|
throw "InvalidToken"
|
|
54
|
+
# Classify expiration only after verifying the signature, issuer and audience.
|
|
54
55
|
claims = jwt/default/verify(encoded, keys[head.kid], {
|
|
55
56
|
algorithms: ["HS256"]
|
|
56
57
|
issuer: settings.issuer
|
|
57
58
|
audience: settings.audience
|
|
59
|
+
ignoreExpiration: true
|
|
58
60
|
})
|
|
59
61
|
if !is_object(claims) or !is_string(claims.clientId) or claims.clientId == "" or !is_string(claims.auth)
|
|
60
62
|
throw "InvalidToken"
|
|
@@ -62,6 +64,8 @@ Tokens:read(header)
|
|
|
62
64
|
throw "InvalidToken"
|
|
63
65
|
if !Number/isSafeInteger(claims.validatedAt) or claims.validatedAt < 0 or claims.validatedAt > Date/now()
|
|
64
66
|
throw "InvalidToken"
|
|
67
|
+
if claims.exp * 1000 <= Date/now()
|
|
68
|
+
throw "TokenExpired"
|
|
65
69
|
return claims
|
|
66
70
|
|
|
67
71
|
Tokens:renew(claims)
|
package/src/trace.lango
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export trace(message)
|
|
2
|
-
export responseLog(id, method, path, status)
|
|
2
|
+
export responseLog(id, method, path, status, session = null)
|
|
3
3
|
|
|
4
4
|
trace(message)
|
|
5
5
|
context log
|
|
@@ -8,11 +8,14 @@ trace(message)
|
|
|
8
8
|
return null
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
responseLog(id, method, path, status)
|
|
11
|
+
responseLog(id, method, path, status, session = null)
|
|
12
12
|
context log
|
|
13
13
|
message = "HTTP ${method} ${path} completed status=${status}"
|
|
14
14
|
if id != null
|
|
15
15
|
message = "[${id}] ${message}"
|
|
16
|
+
if status == 401 and session == "expired"
|
|
17
|
+
log.info("${message} reason=SessionExpired")
|
|
18
|
+
return null
|
|
16
19
|
if status >= 500
|
|
17
20
|
log.err(message)
|
|
18
21
|
else
|