@bardioc/app-sdk 0.4.6 → 0.4.8
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/dev-proxy.d.ts +0 -2
- package/dist/dev-proxy.js +17 -8
- package/dist/vite.js +0 -1
- package/package.json +1 -1
package/dist/dev-proxy.d.ts
CHANGED
|
@@ -4,8 +4,6 @@ export interface DevAuthProxyOptions {
|
|
|
4
4
|
apiBaseUrl: string;
|
|
5
5
|
/** Dev secret copied from the backend. */
|
|
6
6
|
devSecret: string;
|
|
7
|
-
/** App slug stamped as `X-App-ID`, mirroring how the host identifies iframe apps. */
|
|
8
|
-
appId?: string;
|
|
9
7
|
/** Optional CORS origin (e.g. `*`). */
|
|
10
8
|
allowOrigin?: string;
|
|
11
9
|
}
|
package/dist/dev-proxy.js
CHANGED
|
@@ -31,9 +31,19 @@ function addDevSecretHeader(req, headers, devSecret) {
|
|
|
31
31
|
}
|
|
32
32
|
return headers;
|
|
33
33
|
}
|
|
34
|
+
// The BFF answers a bare 403 for any Origin outside its CORS allow-list, which no
|
|
35
|
+
// localhost dev server is in. Dropping Origin makes it a non-CORS request, and the
|
|
36
|
+
// dev-secret check then still passes via its Referer localhost fallback.
|
|
37
|
+
function dropOriginKeepReferer(headers) {
|
|
38
|
+
const origin = headers.get('Origin');
|
|
39
|
+
if (origin && !headers.has('Referer')) {
|
|
40
|
+
headers.set('Referer', `${origin}/`);
|
|
41
|
+
}
|
|
42
|
+
headers.delete('Origin');
|
|
43
|
+
}
|
|
34
44
|
export function createDevAuthProxyHandler(options) {
|
|
35
45
|
const apiBaseUrl = normalizeApiBaseUrl(options.apiBaseUrl);
|
|
36
|
-
const { devSecret, allowOrigin
|
|
46
|
+
const { devSecret, allowOrigin } = options;
|
|
37
47
|
return async (req, res) => {
|
|
38
48
|
const url = new URL(req.url ?? '/', `http://${req.headers.host ?? 'localhost'}`);
|
|
39
49
|
if (req.method === 'OPTIONS') {
|
|
@@ -49,8 +59,8 @@ export function createDevAuthProxyHandler(options) {
|
|
|
49
59
|
const upstreamPath = url.pathname.slice('/rest'.length) + url.search;
|
|
50
60
|
const upstreamUrl = `${apiBaseUrl}${upstreamPath}`;
|
|
51
61
|
const headers = new Headers();
|
|
52
|
-
// Forward headers from the browser so the BFF sees the same request the host would
|
|
53
|
-
// (cookies,
|
|
62
|
+
// Forward headers from the browser so the BFF sees the same request the host would
|
|
63
|
+
// relay (cookies, referer, etc.). Skip hop-by-hop headers; fetch sets Host from the URL.
|
|
54
64
|
const skipHeaders = new Set([
|
|
55
65
|
'connection',
|
|
56
66
|
'content-length',
|
|
@@ -74,11 +84,10 @@ export function createDevAuthProxyHandler(options) {
|
|
|
74
84
|
}
|
|
75
85
|
}
|
|
76
86
|
addDevSecretHeader(req, headers, devSecret);
|
|
77
|
-
|
|
78
|
-
// dev
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
87
|
+
dropOriginKeepReferer(headers);
|
|
88
|
+
// Dev auth is dev-secret only: never forward X-App-Id, so the BFF app-token
|
|
89
|
+
// exchange (which would also demand X-Scope-ID) can never be triggered here.
|
|
90
|
+
headers.delete('X-App-Id');
|
|
82
91
|
// BFF rejects /bardioc/ calls without this CSRF marker header; stamp it like the host does.
|
|
83
92
|
headers.set('X-Requested-With', 'XMLHttpRequest');
|
|
84
93
|
let body;
|
package/dist/vite.js
CHANGED