@lowdefy/api 7.0.0 → 7.2.0
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/dist/context/createAuthorizeOutcome.js +1 -1
- package/dist/context/createEvaluateOperators.js +2 -1
- package/dist/context/isWebSocketOriginAllowed.js +3 -1
- package/dist/context/readMemberships.js +10 -4
- package/dist/context/resolveAuthentication.js +95 -21
- package/dist/email/renderAuthEmail.js +3 -2
- package/dist/index.js +7 -1
- package/dist/response/redactErrorResponse.js +8 -4
- package/dist/routes/agent/callAgent.js +20 -2
- package/dist/routes/agent/redactMessages.js +136 -0
- package/dist/routes/auth/createAuthLogger.js +23 -6
- package/dist/routes/auth/createMcpAccessTokenClaims.js +8 -6
- package/dist/routes/auth/createOnAPIError.js +15 -5
- package/dist/routes/auth/createSendEmail.js +15 -5
- package/dist/routes/auth/getBetterAuth.js +3 -3
- package/dist/routes/auth/getBetterAuthConfig.js +163 -92
- package/dist/routes/auth/hooks/buildEngineHooks.js +15 -1
- package/dist/routes/auth/hooks/createUserAfterHook.js +17 -2
- package/dist/routes/auth/hooks/createUserBeforeHook.js +20 -4
- package/dist/routes/auth/mobile/buildBearerPlugin.js +45 -0
- package/dist/routes/auth/mobile/buildOneTimeTokenPlugin.js +50 -0
- package/dist/routes/auth/mobile/createCodeVerifierCheck.js +57 -0
- package/dist/routes/auth/mobile/createKnownDeviceHook.js +76 -0
- package/dist/routes/auth/mobile/createMobileAuthPageResponse.js +79 -0
- package/dist/routes/auth/mobile/createMobileSessionCreateHook.js +41 -0
- package/dist/routes/auth/mobile/createMobileSessionRefreshHook.js +40 -0
- package/dist/routes/auth/mobile/createMobileSignInCsrfToken.js +32 -0
- package/dist/routes/auth/mobile/createPhoneSession.js +59 -0
- package/dist/routes/auth/mobile/escapeHtml.js +26 -0
- package/dist/routes/auth/mobile/getCodeHolderIdentifier.js +20 -0
- package/dist/routes/auth/mobile/getKnownDeviceIdentifier.js +20 -0
- package/dist/routes/auth/mobile/getMobileSessionExpiry.js +18 -0
- package/dist/routes/auth/mobile/getMobileSignInReturnUrl.js +31 -0
- package/dist/routes/auth/mobile/getOneTimeTokenIdentifiers.js +26 -0
- package/dist/routes/auth/mobile/handleMobileSignIn.js +303 -0
- package/dist/routes/auth/mobile/handleMobileSignInCallback.js +30 -0
- package/dist/routes/auth/mobile/isNativeAuthRequest.js +33 -0
- package/dist/routes/auth/mobile/matchesCodeChallenge.js +29 -0
- package/dist/routes/auth/mobile/mintOneTimeToken.js +41 -0
- package/dist/routes/auth/mobile/readDeviceKeyHash.js +34 -0
- package/dist/routes/auth/mobile/readMobileSignInParams.js +90 -0
- package/dist/routes/auth/mobile/sha256Base64Url.js +22 -0
- package/dist/routes/auth/mobile/storeCodeChallenge.js +29 -0
- package/dist/routes/auth/organizations/buildOrganizationPlugin.js +43 -6
- package/dist/routes/auth/organizations/createAcceptExistingMemberHook.js +7 -2
- package/dist/routes/auth/organizations/createActiveOrgPolicyHook.js +41 -189
- package/dist/routes/auth/organizations/createAdmissionGateHook.js +5 -5
- package/dist/routes/auth/organizations/createBeforeCreateInvitationHook.js +62 -0
- package/dist/routes/auth/organizations/createBeforeUpdateMemberRoleHook.js +45 -0
- package/dist/routes/auth/organizations/createSuspendedMemberGate.js +146 -0
- package/dist/routes/auth/organizations/createSuspendedOrganizationsFilter.js +44 -0
- package/dist/routes/auth/organizations/ensureAuthIndexes.js +11 -10
- package/dist/routes/auth/organizations/getOrganizationBinding.js +4 -2
- package/dist/routes/auth/organizations/isActiveMember.js +26 -0
- package/dist/routes/auth/organizations/isEmailAdmitted.js +12 -5
- package/dist/routes/auth/organizations/memberRowsLimit.js +19 -0
- package/dist/routes/auth/organizations/mintOrganization.js +258 -0
- package/dist/routes/auth/organizations/organizationAccessControl.js +5 -1
- package/dist/routes/auth/organizations/provisionOrganization.js +117 -0
- package/dist/routes/auth/organizations/readSuspendedOrganizationIds.js +36 -0
- package/dist/routes/auth/requestHooks/buildRequestHooks.js +72 -0
- package/dist/routes/auth/requestHooks/createEmailCodeHolderGate.js +58 -0
- package/dist/routes/auth/requestHooks/createEmailSendLimit.js +116 -0
- package/dist/routes/auth/requestHooks/createSignInRefusedRedirectHook.js +75 -0
- package/dist/routes/auth/requestHooks/holdEmailCode.js +80 -0
- package/dist/routes/auth/requestHooks/reserveSendSlot.js +70 -0
- package/dist/routes/auth/runReportingFaults.js +32 -0
- package/dist/routes/connections/resolveUnwalledReach.js +14 -16
- package/dist/routes/endpoints/callEndpoint.js +6 -3
- package/dist/routes/endpoints/control/controlFor.js +9 -6
- package/dist/routes/endpoints/control/controlIf.js +8 -3
- package/dist/routes/endpoints/control/controlLog.js +3 -1
- package/dist/routes/endpoints/control/controlParallelFor.js +9 -6
- package/dist/routes/endpoints/control/controlReturn.js +3 -2
- package/dist/routes/endpoints/control/controlSetState.js +1 -1
- package/dist/routes/endpoints/control/controlSwitch.js +6 -3
- package/dist/routes/endpoints/control/controlWhile.js +6 -3
- package/dist/routes/endpoints/createLinkAnswer.js +76 -0
- package/dist/routes/endpoints/dispatchDetached.js +38 -0
- package/dist/routes/endpoints/forwardScheduledEndpoint.js +32 -11
- package/dist/routes/endpoints/handleAgentCall.js +1 -1
- package/dist/routes/endpoints/handleAuthStep.js +19 -4
- package/dist/routes/endpoints/handleEndpointCall.js +6 -4
- package/dist/routes/endpoints/handleRequest.js +3 -2
- package/dist/routes/endpoints/handleValidateDynamic.js +1 -1
- package/dist/routes/endpoints/matchLinkEndpoint.js +30 -0
- package/dist/routes/endpoints/runLinkEndpoint.js +148 -0
- package/dist/routes/endpoints/runRoutine.js +5 -5
- package/dist/routes/endpoints/scheduleBackground.js +13 -11
- package/dist/routes/endpoints/test/runTest.js +30 -11
- package/dist/routes/mcp/createMcpServer.js +2 -7
- package/dist/routes/mcp/runAfterToolCall.js +9 -3
- package/dist/routes/mobile/createAppleAppSiteAssociation.js +51 -0
- package/dist/routes/mobile/createAssetLinks.js +38 -0
- package/dist/routes/mobile/filterMobileMenus.js +31 -0
- package/dist/routes/mobile/getMobileAppEvents.js +23 -0
- package/dist/routes/mobile/getMobileRootConfig.js +109 -0
- package/dist/routes/mobile/getOpenablePageIds.js +21 -0
- package/dist/routes/page/dynamic/policy/checkAction.js +67 -2
- package/dist/routes/page/dynamic/policy/checkEvents.js +8 -2
- package/dist/routes/page/dynamic/policy/checkPolicy.js +86 -6
- package/dist/routes/page/dynamic/policy/checkValue.js +97 -6
- package/dist/routes/page/dynamic/policy/collectSchemaKinds.js +173 -0
- package/dist/routes/page/dynamic/policy/findDataRows.js +94 -0
- package/dist/routes/page/dynamic/policy/findEmbeddedUrls.js +24 -12
- package/dist/routes/page/dynamic/policy/findHtmlUrls.js +64 -0
- package/dist/routes/page/dynamic/policy/overlapsStatePath.js +28 -0
- package/dist/routes/page/dynamic/resolveDynamicContent.js +23 -17
- package/dist/routes/page/getPageConfig.js +25 -1
- package/dist/routes/request/callRequestResolver.js +29 -36
- package/dist/routes/request/stampTypedError.js +37 -0
- package/dist/routes/request/summarisedError.js +62 -0
- package/dist/routes/request/wrapResolverError.js +61 -0
- package/dist/routes/websocket/createChannelRegistry.js +13 -15
- package/dist/routes/websocket/createWebSocketConnection.js +5 -8
- package/dist/test/createMemoryAuth.js +125 -0
- package/package.json +20 -22
- package/dist/routes/page/dynamic/policy/collectUrlKinds.js +0 -117
- package/dist/routes/request/maskCredentialProperties.js +0 -34
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
// The schemas that can describe a value: the schema itself and its oneOf,
|
|
17
|
+
// anyOf and allOf branches, however nested.
|
|
18
|
+
function expandSchema(schema) {
|
|
19
|
+
const schemas = [];
|
|
20
|
+
const pending = [
|
|
21
|
+
schema
|
|
22
|
+
];
|
|
23
|
+
while(pending.length > 0){
|
|
24
|
+
const candidate = pending.pop();
|
|
25
|
+
if (type.isObject(candidate)) {
|
|
26
|
+
schemas.push(candidate);
|
|
27
|
+
[
|
|
28
|
+
...candidate.oneOf ?? [],
|
|
29
|
+
...candidate.anyOf ?? [],
|
|
30
|
+
...candidate.allOf ?? []
|
|
31
|
+
].forEach((branch)=>pending.push(branch));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return schemas;
|
|
35
|
+
}
|
|
36
|
+
function childSchemas({ schemas, key }) {
|
|
37
|
+
return schemas.flatMap((schema)=>{
|
|
38
|
+
if (type.isObject(schema.properties?.[key])) {
|
|
39
|
+
return [
|
|
40
|
+
schema.properties[key]
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
if (type.isObject(schema.additionalProperties)) {
|
|
44
|
+
return [
|
|
45
|
+
schema.additionalProperties
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
return [];
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
// The kind the schemas give a value under keyword: a string when one marks it,
|
|
52
|
+
// null when one opts it out with false, undefined when none says.
|
|
53
|
+
function findKind({ schemas, keyword }) {
|
|
54
|
+
const marked = schemas.find((candidate)=>type.isString(candidate[keyword]));
|
|
55
|
+
if (marked) {
|
|
56
|
+
return marked[keyword];
|
|
57
|
+
}
|
|
58
|
+
if (schemas.some((candidate)=>candidate[keyword] === false)) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
// A 'data' value with dataWith is data only beside a string at that sibling
|
|
64
|
+
// key: an option value is drawn in place of a missing label. Without it the
|
|
65
|
+
// value is unmarked, so it keeps every check.
|
|
66
|
+
function applyDataWith({ kind, schemas, parent }) {
|
|
67
|
+
if (kind !== 'data') {
|
|
68
|
+
return kind;
|
|
69
|
+
}
|
|
70
|
+
const withKey = schemas.find((candidate)=>type.isString(candidate.dataWith))?.dataWith;
|
|
71
|
+
if (type.isUndefined(withKey) || type.isString(parent?.[withKey])) {
|
|
72
|
+
return kind;
|
|
73
|
+
}
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
// Records, by path, the kind a block schema gives the value there under each
|
|
77
|
+
// keyword, so the policy judges a value by what its property is, not by what it
|
|
78
|
+
// is called. A marked array holds one value of that kind per item; false records
|
|
79
|
+
// null; a value no schema marks either way is not recorded. Returns a Map per
|
|
80
|
+
// keyword; one walk reads them all, since it runs on every Dynamic block.
|
|
81
|
+
//
|
|
82
|
+
// urlKind marks URL-valued properties ('url' and 'href' navigate, 'url' the way
|
|
83
|
+
// the engine's link resolver does; 'src' loads; 'srcSet' lists sources), and
|
|
84
|
+
// urlKind: false a property whose name looks like a URL key but whose value is
|
|
85
|
+
// not a URL. textKind marks how a block draws a string: 'html' through
|
|
86
|
+
// renderHtml (sanitised HTML, never markdown or a link), 'text' as escaped
|
|
87
|
+
// text, and 'data' a value the block stores or compares but never draws (an
|
|
88
|
+
// option value), so every string in it, however nested, is text. dataWith
|
|
89
|
+
// names a sibling key the value is data only beside (applyDataWith). Values
|
|
90
|
+
// neither marks fall back to the key-name and text rules.
|
|
91
|
+
function collectSchemaKinds({ value, schema, path, keywords }) {
|
|
92
|
+
const kindsByKeyword = Object.fromEntries(keywords.map((keyword)=>[
|
|
93
|
+
keyword,
|
|
94
|
+
new Map()
|
|
95
|
+
]));
|
|
96
|
+
const pending = [
|
|
97
|
+
{
|
|
98
|
+
value,
|
|
99
|
+
schema,
|
|
100
|
+
path,
|
|
101
|
+
keywords
|
|
102
|
+
}
|
|
103
|
+
];
|
|
104
|
+
while(pending.length > 0){
|
|
105
|
+
const item = pending.pop();
|
|
106
|
+
const schemas = expandSchema(item.schema);
|
|
107
|
+
// The keywords a mark has not settled here, read again in the children.
|
|
108
|
+
const open = item.keywords.filter((keyword)=>{
|
|
109
|
+
const kinds = kindsByKeyword[keyword];
|
|
110
|
+
const kind = applyDataWith({
|
|
111
|
+
kind: findKind({
|
|
112
|
+
schemas,
|
|
113
|
+
keyword
|
|
114
|
+
}),
|
|
115
|
+
schemas,
|
|
116
|
+
parent: item.parent
|
|
117
|
+
});
|
|
118
|
+
if (kind === null) {
|
|
119
|
+
// Another schema branch may already have marked it.
|
|
120
|
+
if (!kinds.has(item.path)) {
|
|
121
|
+
kinds.set(item.path, null);
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
if (type.isString(kind) && type.isArray(item.value)) {
|
|
126
|
+
item.value.forEach((_, index)=>kinds.set(`${item.path}.${index}`, kind));
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
if (type.isString(kind) && !type.isObject(item.value)) {
|
|
130
|
+
kinds.set(item.path, kind);
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
if (type.isObject(item.value)) {
|
|
134
|
+
// An object under a branch that marks strings is an operator, which the
|
|
135
|
+
// policy judges by a urlKind mark (it must be literal), or an object
|
|
136
|
+
// whose properties other branches mark (an option that is a string or a
|
|
137
|
+
// { label, value } object), so it is walked too.
|
|
138
|
+
if (type.isString(kind)) {
|
|
139
|
+
kinds.set(item.path, kind);
|
|
140
|
+
}
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
return type.isArray(item.value);
|
|
144
|
+
});
|
|
145
|
+
if (open.length === 0) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
if (type.isArray(item.value)) {
|
|
149
|
+
const itemSchemas = schemas.map((candidate)=>candidate.items).filter(type.isObject);
|
|
150
|
+
item.value.forEach((child, index)=>itemSchemas.forEach((itemSchema)=>pending.push({
|
|
151
|
+
value: child,
|
|
152
|
+
schema: itemSchema,
|
|
153
|
+
path: `${item.path}.${index}`,
|
|
154
|
+
keywords: open
|
|
155
|
+
})));
|
|
156
|
+
} else {
|
|
157
|
+
Object.keys(item.value).forEach((key)=>{
|
|
158
|
+
childSchemas({
|
|
159
|
+
schemas,
|
|
160
|
+
key
|
|
161
|
+
}).forEach((childSchema)=>pending.push({
|
|
162
|
+
value: item.value[key],
|
|
163
|
+
schema: childSchema,
|
|
164
|
+
path: `${item.path}.${key}`,
|
|
165
|
+
parent: item.value,
|
|
166
|
+
keywords: open
|
|
167
|
+
}));
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return kindsByKeyword;
|
|
172
|
+
}
|
|
173
|
+
export default collectSchemaKinds;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { get, type } from '@lowdefy/helpers';
|
|
16
|
+
// Every column a columns list holds, column groups' children included.
|
|
17
|
+
function flattenColumns({ columns, mark }) {
|
|
18
|
+
return (columns ?? []).flatMap((column)=>{
|
|
19
|
+
if (type.isObject(column) && type.isArray(column[mark.children])) {
|
|
20
|
+
return [
|
|
21
|
+
column,
|
|
22
|
+
...flattenColumns({
|
|
23
|
+
columns: column[mark.children],
|
|
24
|
+
mark
|
|
25
|
+
})
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
return [
|
|
29
|
+
column
|
|
30
|
+
];
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function drawsAsText({ column, mark }) {
|
|
34
|
+
if (type.isString(column)) {
|
|
35
|
+
return mark.textTypes.includes(mark.defaultType);
|
|
36
|
+
}
|
|
37
|
+
if (!type.isObject(column)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
// A column group draws no cells of its own.
|
|
41
|
+
if (type.isArray(column[mark.children]) && type.isNone(column[mark.type])) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
// A cell option that reads another row field into the cell, such as a
|
|
45
|
+
// colour, draws that field as more than text.
|
|
46
|
+
const cell = column[mark.cell];
|
|
47
|
+
if (type.isObject(cell) && mark.cellRowKeys.some((key)=>!type.isNone(cell[key]))) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return mark.textTypes.includes(column[mark.type] ?? mark.defaultType);
|
|
51
|
+
}
|
|
52
|
+
function isDataRows({ properties, key, mark }) {
|
|
53
|
+
if (!type.isArray(properties[key])) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
if (mark.drawnBy.some((drawnBy)=>!type.isNone(get(properties, drawnBy)))) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
const columns = properties[mark.columns];
|
|
60
|
+
if (!type.isNone(columns) && !type.isArray(columns)) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
return flattenColumns({
|
|
64
|
+
columns,
|
|
65
|
+
mark
|
|
66
|
+
}).every((column)=>drawsAsText({
|
|
67
|
+
column,
|
|
68
|
+
mark
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
// Returns the paths of row lists that are data: a top-level property whose
|
|
72
|
+
// schema marks it with rowsKind, holding an array, where every column of the
|
|
73
|
+
// sibling columns property draws its cell as text and nothing else draws the
|
|
74
|
+
// rows. A column whose type draws a link, an image or HTML, or whose cell
|
|
75
|
+
// options read a row field into the cell, leaves the rows to every check.
|
|
76
|
+
// rowsKind names the columns property; a column's type, children and cell
|
|
77
|
+
// options keys; the type a column without one has; the text types; the cell
|
|
78
|
+
// options that read a row field; and the properties (dot paths) that draw rows
|
|
79
|
+
// themselves when set:
|
|
80
|
+
// { columns, type, children, cell, cellRowKeys, drawnBy, defaultType, textTypes }.
|
|
81
|
+
function findDataRows({ properties, schema, path }) {
|
|
82
|
+
if (!type.isObject(properties) || !type.isObject(schema?.properties)) {
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
return Object.keys(schema.properties).filter((key)=>{
|
|
86
|
+
const mark = schema.properties[key].rowsKind;
|
|
87
|
+
return type.isObject(mark) && isDataRows({
|
|
88
|
+
properties,
|
|
89
|
+
key,
|
|
90
|
+
mark
|
|
91
|
+
});
|
|
92
|
+
}).map((key)=>`${path}.${key}`);
|
|
93
|
+
}
|
|
94
|
+
export default findDataRows;
|
|
@@ -14,12 +14,22 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import normalizeUrlText from './normalizeUrlText.js';
|
|
16
16
|
// Returns every URL a string can make the client load or navigate to that is
|
|
17
|
-
// not given by its key: a
|
|
18
|
-
// parser reads it), markdown link
|
|
19
|
-
// url()/image-set()/src() arguments after
|
|
20
|
-
|
|
21
|
-
//
|
|
22
|
-
|
|
17
|
+
// not given by its key: a whole value with a scheme the browser loads or runs,
|
|
18
|
+
// or a protocol-relative one (read as the URL parser reads it), markdown link
|
|
19
|
+
// and image targets, and CSS url()/image-set()/src() arguments after
|
|
20
|
+
// unescaping. A word such as "INC:42" or "HH:mm" has the shape of a scheme but
|
|
21
|
+
// names none the browser acts on, so it is text.
|
|
22
|
+
//
|
|
23
|
+
// The caller turns off the scans that cannot apply to how the value is drawn: a
|
|
24
|
+
// property drawn as text or HTML renders no markdown, and is no link, so neither
|
|
25
|
+
// the whole value, a markdown target nor a protocol-relative word in it is a URL;
|
|
26
|
+
// CSS url() only loads in text that can carry a style.
|
|
27
|
+
// An allowlist of schemes, not a scheme-shaped pattern: any word may hold a colon.
|
|
28
|
+
const LOADED_SCHEME = /^(https?|ftp|wss?|file|blob|filesystem):\S/i;
|
|
29
|
+
// Script and data schemes keep whatever follows them, spaces included.
|
|
30
|
+
const SCRIPT_SCHEME = /^(javascript|vbscript|data):/i;
|
|
31
|
+
// The URL parser reads a backslash as a slash, so "\\host" is protocol-relative too.
|
|
32
|
+
const PROTOCOL_RELATIVE = /^[\\/][\\/]/;
|
|
23
33
|
const MARKDOWN_INLINE = /\]\(\s*<?([^)\s>]+)/g;
|
|
24
34
|
const MARKDOWN_REFERENCE = /^\s*\[[^\]]+\]:\s*<?([^\s>]+)/gm;
|
|
25
35
|
const CSS_FUNCTION = /(url|src|image-set)\(([^)]*)\)/gi;
|
|
@@ -27,16 +37,18 @@ const QUOTED = /(['"])(.*?)\1/g;
|
|
|
27
37
|
function unescapeCss(value) {
|
|
28
38
|
return value.replace(/\\([0-9a-fA-F]{1,6})\s?/g, (_, hex)=>String.fromCodePoint(parseInt(hex, 16))).replace(/\\(.)/g, '$1');
|
|
29
39
|
}
|
|
30
|
-
function findEmbeddedUrls(value) {
|
|
40
|
+
function findEmbeddedUrls({ value, wholeValue = true, markdown = true, css = true }) {
|
|
31
41
|
const urls = [];
|
|
32
42
|
const text = normalizeUrlText(value);
|
|
33
|
-
const isUrlText = !/\s/.test(text) && (
|
|
34
|
-
if (isUrlText || SCRIPT_SCHEME.test(text)) {
|
|
43
|
+
const isUrlText = !/\s/.test(text) && (LOADED_SCHEME.test(text) || PROTOCOL_RELATIVE.test(text));
|
|
44
|
+
if (wholeValue && (isUrlText || SCRIPT_SCHEME.test(text))) {
|
|
35
45
|
urls.push(text);
|
|
36
46
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
47
|
+
if (markdown) {
|
|
48
|
+
for (const match of value.matchAll(MARKDOWN_INLINE))urls.push(match[1]);
|
|
49
|
+
for (const match of value.matchAll(MARKDOWN_REFERENCE))urls.push(match[1]);
|
|
50
|
+
}
|
|
51
|
+
if (css && value.includes('(')) {
|
|
40
52
|
for (const match of unescapeCss(value).matchAll(CSS_FUNCTION)){
|
|
41
53
|
const argument = match[2].trim();
|
|
42
54
|
const quoted = [
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ // Returns every URL an HTML string can make the client load or navigate to
|
|
16
|
+
// through an attribute, as { url, navigation }. With tags allowed, DOMPurify
|
|
17
|
+
// keeps <a href> and <img src>, so these are judged as links and sources.
|
|
18
|
+
//
|
|
19
|
+
// Attributes are matched anywhere in the string, not only inside a tag: a ">"
|
|
20
|
+
// in a quoted attribute value would end a tag pattern early and hide the
|
|
21
|
+
// attributes after it, and text that only looks like an attribute fails safe.
|
|
22
|
+
const ATTRIBUTE = /(?:^|[\s/"'])(href|xlink:href|action|formaction|src|poster|background|srcset)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+))/gi;
|
|
23
|
+
const NAVIGATION_ATTRIBUTES = new Set([
|
|
24
|
+
'href',
|
|
25
|
+
'xlink:href',
|
|
26
|
+
'action',
|
|
27
|
+
'formaction'
|
|
28
|
+
]);
|
|
29
|
+
// The named references that spell the characters a URL's scheme and host turn
|
|
30
|
+
// on; the browser decodes these before it reads the URL.
|
|
31
|
+
const NAMED_REFERENCES = {
|
|
32
|
+
amp: '&',
|
|
33
|
+
colon: ':',
|
|
34
|
+
sol: '/',
|
|
35
|
+
bsol: '\\',
|
|
36
|
+
tab: '\t',
|
|
37
|
+
newline: '\n'
|
|
38
|
+
};
|
|
39
|
+
const REFERENCE = /&(?:#x([0-9a-f]+)|#(\d+)|([a-z]+));?/gi;
|
|
40
|
+
function decodeReferences(value) {
|
|
41
|
+
return value.replace(REFERENCE, (match, hex, decimal, name)=>{
|
|
42
|
+
if (hex) return String.fromCodePoint(parseInt(hex, 16));
|
|
43
|
+
if (decimal) return String.fromCodePoint(parseInt(decimal, 10));
|
|
44
|
+
return NAMED_REFERENCES[name.toLowerCase()] ?? match;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function findHtmlUrls({ value }) {
|
|
48
|
+
const urls = [];
|
|
49
|
+
for (const match of value.matchAll(ATTRIBUTE)){
|
|
50
|
+
const name = match[1].toLowerCase();
|
|
51
|
+
const attribute = decodeReferences(match[2] ?? match[3] ?? match[4]);
|
|
52
|
+
const navigation = NAVIGATION_ATTRIBUTES.has(name);
|
|
53
|
+
// srcset lists "url descriptor" pairs.
|
|
54
|
+
const entries = name === 'srcset' ? attribute.split(',').map((entry)=>entry.trim().split(/\s+/)[0]) : [
|
|
55
|
+
attribute
|
|
56
|
+
];
|
|
57
|
+
entries.forEach((url)=>urls.push({
|
|
58
|
+
url,
|
|
59
|
+
navigation
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
return urls;
|
|
63
|
+
}
|
|
64
|
+
export default findHtmlUrls;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ // Whether two state paths name the same value or one holds the other. A "$"
|
|
16
|
+
// segment (an id inside a list) matches any segment.
|
|
17
|
+
function overlapsStatePath({ key, id }) {
|
|
18
|
+
const keyParts = key.split('.');
|
|
19
|
+
const idParts = id.split('.');
|
|
20
|
+
const length = Math.min(keyParts.length, idParts.length);
|
|
21
|
+
for(let index = 0; index < length; index += 1){
|
|
22
|
+
const keyPart = keyParts[index];
|
|
23
|
+
const idPart = idParts[index];
|
|
24
|
+
if (keyPart !== idPart && keyPart !== '$' && idPart !== '$') return false;
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
export default overlapsStatePath;
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
-
import { ConfigError } from '@lowdefy/errors';
|
|
16
|
+
import { ConfigError, isExpectedError } from '@lowdefy/errors';
|
|
17
17
|
import createEvaluateOperators from '../../../context/createEvaluateOperators.js';
|
|
18
18
|
import invokeEndpoint from '../../endpoints/invokeEndpoint.js';
|
|
19
19
|
import checkDynamicContent from './checkDynamicContent.js';
|
|
@@ -65,9 +65,9 @@ async function resolveDynamicBlock(context, { block, depth, shared }) {
|
|
|
65
65
|
// blocks of a ValidateDynamic step that passed with this policy may come
|
|
66
66
|
// back as config, and the policy is checked again on the final content.
|
|
67
67
|
const policy = type.isNone(block.properties.policy) ? null : shared.artifacts.dynamicPolicies[block.properties.policy];
|
|
68
|
-
//
|
|
69
|
-
//
|
|
70
|
-
//
|
|
68
|
+
// An error the routine returns was logged and marked handled where it was raised
|
|
69
|
+
// (a failed ValidateDynamic step, a :reject, a :throw) or by runRoutine: an
|
|
70
|
+
// expected outcome as a warning, a fault through handleError.
|
|
71
71
|
let loggedByRoutine = false;
|
|
72
72
|
try {
|
|
73
73
|
if (depth >= MAX_DYNAMIC_DEPTH) {
|
|
@@ -94,7 +94,7 @@ async function resolveDynamicBlock(context, { block, depth, shared }) {
|
|
|
94
94
|
'error',
|
|
95
95
|
'reject'
|
|
96
96
|
].includes(status)) {
|
|
97
|
-
loggedByRoutine = error?.
|
|
97
|
+
loggedByRoutine = error?.handled === true;
|
|
98
98
|
throw error ?? new ConfigError(`Dynamic block "${block.blockId}" on page "${shared.pageId}" endpoint "${endpointId}" failed with status "${status}".`, {
|
|
99
99
|
configKey: block['~k']
|
|
100
100
|
});
|
|
@@ -156,19 +156,25 @@ async function resolveDynamicBlock(context, { block, depth, shared }) {
|
|
|
156
156
|
});
|
|
157
157
|
}
|
|
158
158
|
if (!loggedByRoutine) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
// A UserError is an expected outcome, not a fault.
|
|
168
|
-
if (error.name === 'UserError') {
|
|
169
|
-
logger.warn(entry, message);
|
|
159
|
+
if (isExpectedError(error)) {
|
|
160
|
+
logger.warn({
|
|
161
|
+
event: 'dynamic_block_error',
|
|
162
|
+
blockId: block.blockId,
|
|
163
|
+
endpointId,
|
|
164
|
+
pageId: shared.pageId,
|
|
165
|
+
err: error
|
|
166
|
+
}, `Dynamic block "${block.blockId}" on page "${shared.pageId}" failed to resolve: ${error.message}`);
|
|
170
167
|
} else {
|
|
171
|
-
|
|
168
|
+
// The fallback renders, but the failure is a fault: it is located at the Dynamic block
|
|
169
|
+
// and reported like any other.
|
|
170
|
+
if (error instanceof Object && !error.configKey) {
|
|
171
|
+
error.configKey = block['~k'];
|
|
172
|
+
}
|
|
173
|
+
// The log line and the Sentry tags name the block that fell back.
|
|
174
|
+
if (error instanceof Object && type.isNone(error.blockId)) {
|
|
175
|
+
error.blockId = block.blockId;
|
|
176
|
+
}
|
|
177
|
+
await context.handleError(error);
|
|
172
178
|
}
|
|
173
179
|
}
|
|
174
180
|
const fallbackBlocks = block.slots?.fallback?.blocks ?? [];
|
|
@@ -32,11 +32,24 @@ import resolveDynamicContent from './dynamic/resolveDynamicContent.js';
|
|
|
32
32
|
// means you are signed in - and every app's 404 page stops needing to serve a
|
|
33
33
|
// signed-out visitor who was refused a protected page.
|
|
34
34
|
//
|
|
35
|
+
// - wrong_surface: the page is for the other surface. A shell (surface
|
|
36
|
+
// "mobile", sent as x-lowdefy-shell) opens only pages whose target is mobile
|
|
37
|
+
// or both; a browser (surface "web") never opens a mobile-only page. Checked
|
|
38
|
+
// once access is allowed, so the gate never reveals a page the caller may not
|
|
39
|
+
// open. It serves the user's experience, not security: the header is set by
|
|
40
|
+
// the client, and page access stays with auth.pages.
|
|
41
|
+
//
|
|
35
42
|
// The default is a build-resolved boolean, coarser than the glob lists that
|
|
36
43
|
// produced it on purpose: an id absent from the build could still match a
|
|
37
44
|
// declared pattern, and matching globs on the request path to change the answer
|
|
38
45
|
// for URLs that are wrong anyway is a cost the artifact exists to avoid.
|
|
39
|
-
|
|
46
|
+
function servesSurface({ target, surface }) {
|
|
47
|
+
if (surface === 'mobile') {
|
|
48
|
+
return target === 'mobile' || target === 'both';
|
|
49
|
+
}
|
|
50
|
+
return target !== 'mobile';
|
|
51
|
+
}
|
|
52
|
+
async function getPageConfig(context, { path, urlQuery, surface = 'web' }) {
|
|
40
53
|
const routes = await context.readConfigFile('routes.json');
|
|
41
54
|
const match = matchPagePath({
|
|
42
55
|
routes,
|
|
@@ -60,6 +73,17 @@ async function getPageConfig(context, { path, urlQuery }) {
|
|
|
60
73
|
if (outcome === 'allow') {
|
|
61
74
|
// eslint-disable-next-line no-unused-vars
|
|
62
75
|
const { auth, ...rest } = pageConfig;
|
|
76
|
+
if (!servesSurface({
|
|
77
|
+
target: rest.target,
|
|
78
|
+
surface
|
|
79
|
+
})) {
|
|
80
|
+
return {
|
|
81
|
+
status: 'wrong_surface',
|
|
82
|
+
pageId,
|
|
83
|
+
pathParams,
|
|
84
|
+
surface: rest.target
|
|
85
|
+
};
|
|
86
|
+
}
|
|
63
87
|
if (rest.dynamic !== true) {
|
|
64
88
|
// Use serializer.serialize to ensure ~k keys (non-enumerable after deserialize)
|
|
65
89
|
// are made enumerable again for JSON transfer to client
|
|
@@ -12,11 +12,12 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/ import {
|
|
15
|
+
*/ import { UserError } from '@lowdefy/errors';
|
|
16
16
|
import getCurrentEnvironment from '../../context/getCurrentEnvironment.js';
|
|
17
17
|
import createWalledResolver from './createWalledResolver.js';
|
|
18
18
|
import invokeEndpoint from '../endpoints/invokeEndpoint.js';
|
|
19
|
-
import
|
|
19
|
+
import stampTypedError from './stampTypedError.js';
|
|
20
|
+
import wrapResolverError from './wrapResolverError.js';
|
|
20
21
|
async function callRequestResolver(context, { agent = null, connectionProperties, endpointDepth, requestConfig, requestProperties, requestResolver, routineContext, tenant, tenantGuard }) {
|
|
21
22
|
const { blockId, endpointId, logger, pageId, payload, signal } = context;
|
|
22
23
|
// stepId for endpoint steps (after build), requestId for page requests
|
|
@@ -87,13 +88,24 @@ async function callRequestResolver(context, { agent = null, connectionProperties
|
|
|
87
88
|
});
|
|
88
89
|
return response;
|
|
89
90
|
} catch (error) {
|
|
90
|
-
// Add configKey to any error for location tracing
|
|
91
|
-
|
|
91
|
+
// Add configKey to any error for location tracing. A thrown string or null takes no
|
|
92
|
+
// property, and the TypeError assigning one raises would quote the string.
|
|
93
|
+
if (error instanceof Object && !error.configKey) {
|
|
92
94
|
error.configKey = requestConfig['~k'];
|
|
93
95
|
}
|
|
94
|
-
//
|
|
95
|
-
//
|
|
96
|
-
|
|
96
|
+
// stepId, not requestId: on an error requestId is the HTTP request's id (context.rid)
|
|
97
|
+
// everywhere else.
|
|
98
|
+
const fields = {
|
|
99
|
+
endpointId: requestConfig.endpointId ?? endpointId,
|
|
100
|
+
stepId: stepOrRequestId,
|
|
101
|
+
connectionId: requestConfig.connectionId
|
|
102
|
+
};
|
|
103
|
+
// Lowdefy errors are not re-wrapped - re-wrapping every boundary would nest causes and
|
|
104
|
+
// truncate the deepest (most informative) frame.
|
|
105
|
+
if (error?.isLowdefyError) {
|
|
106
|
+
stampTypedError(error, {
|
|
107
|
+
fields
|
|
108
|
+
});
|
|
97
109
|
logger.debug({
|
|
98
110
|
params: {
|
|
99
111
|
id: stepOrRequestId,
|
|
@@ -105,7 +117,7 @@ async function callRequestResolver(context, { agent = null, connectionProperties
|
|
|
105
117
|
}
|
|
106
118
|
// The client left before the resolver finished and the resolver stopped on the
|
|
107
119
|
// signal: the cancellation is the caller's doing, not a fault in the request.
|
|
108
|
-
if (signal?.reason?.name === 'AbortError' && error
|
|
120
|
+
if (signal?.reason?.name === 'AbortError' && error?.name === 'AbortError') {
|
|
109
121
|
const cancelled = new UserError(signal.reason.message, {
|
|
110
122
|
cause: error
|
|
111
123
|
});
|
|
@@ -118,41 +130,22 @@ async function callRequestResolver(context, { agent = null, connectionProperties
|
|
|
118
130
|
}, cancelled.message);
|
|
119
131
|
throw cancelled;
|
|
120
132
|
}
|
|
121
|
-
//
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
service: requestConfig.connectionId,
|
|
126
|
-
configKey: requestConfig['~k']
|
|
127
|
-
});
|
|
128
|
-
logger.debug({
|
|
129
|
-
params: {
|
|
130
|
-
id: stepOrRequestId,
|
|
131
|
-
type: requestConfig.type
|
|
132
|
-
},
|
|
133
|
-
err: serviceError
|
|
134
|
-
}, serviceError.message);
|
|
135
|
-
throw serviceError;
|
|
136
|
-
}
|
|
137
|
-
// Wrap other errors in RequestError (request/connection logic error)
|
|
138
|
-
const requestError = new RequestError(error.message, {
|
|
139
|
-
cause: error,
|
|
140
|
-
typeName: requestConfig.type,
|
|
141
|
-
received: maskCredentialProperties({
|
|
142
|
-
requestProperties,
|
|
143
|
-
requestResolver
|
|
144
|
-
}),
|
|
133
|
+
// A ServiceError for a network failure, timeout, 5xx or 429; a RequestError otherwise.
|
|
134
|
+
const wrapped = wrapResolverError(error, {
|
|
135
|
+
configKey: requestConfig['~k'],
|
|
136
|
+
fields,
|
|
145
137
|
location: `${requestConfig.connectionId}/${stepOrRequestId}`,
|
|
146
|
-
|
|
138
|
+
service: requestConfig.connectionId,
|
|
139
|
+
typeName: requestConfig.type
|
|
147
140
|
});
|
|
148
141
|
logger.debug({
|
|
149
142
|
params: {
|
|
150
143
|
id: stepOrRequestId,
|
|
151
144
|
type: requestConfig.type
|
|
152
145
|
},
|
|
153
|
-
err:
|
|
154
|
-
},
|
|
155
|
-
throw
|
|
146
|
+
err: wrapped
|
|
147
|
+
}, wrapped.message);
|
|
148
|
+
throw wrapped;
|
|
156
149
|
}
|
|
157
150
|
}
|
|
158
151
|
export default callRequestResolver;
|