Skip to content

Commit

Permalink
When we do server-checks we naively assume that when requesting the r…
Browse files Browse the repository at this point in the history
…esource, we'll get a 200 response only when the resource was accessible.

But in actuallity it's normal for a 200 statusCode to be returned but it's actually an authentication page.

I added an additional check to re-request the resource with an accept-header, and check the absence of a loginUrl field on the JSON response.

If the response is not valid JSON this additional check is ignored, and the previously behavior is preserved.
  • Loading branch information
ndelangen committed May 6, 2022
1 parent 6c2a88c commit a0a8bfa
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
22 changes: 20 additions & 2 deletions lib/manager-webpack4/src/manager-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,26 @@ export const getAutoRefs = async (
};

const checkRef = (url: string) =>
fetch(`${url}/iframe.html`).then(
({ ok }) => ok,
fetch(`${url}/iframe.html`, {
headers: {
Accept: 'application/json',
},
}).then(
async ({ ok }) => {
if (ok) {
// so the status is ok, but if we'd ask for JSON we might get a response saying we need to authenticate.
const data = await fetch(`${url}/iframe.html`, {
headers: {
Accept: 'application/json',
},
});
// we might receive non-JSON as a response, because the service ignored our request for JSON response type.
if (data.ok && (await data.json().catch((e) => ({}))).loginUrl) {
return false;
}
}
return ok;
},
() => false
);

Expand Down
22 changes: 20 additions & 2 deletions lib/manager-webpack5/src/manager-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,26 @@ export const getAutoRefs = async (
};

const checkRef = (url: string) =>
fetch(`${url}/iframe.html`).then(
({ ok }) => ok,
fetch(`${url}/iframe.html`, {
headers: {
Accept: 'application/json',
},
}).then(
async ({ ok }) => {
if (ok) {
// so the status is ok, but if we'd ask for JSON we might get a response saying we need to authenticate.
const data = await fetch(`${url}/iframe.html`, {
headers: {
Accept: 'application/json',
},
});
// we might receive non-JSON as a response, because the service ignored our request for JSON response type.
if (data.ok && (await data.json().catch((e) => ({}))).loginUrl) {
return false;
}
}
return ok;
},
() => false
);

Expand Down

0 comments on commit a0a8bfa

Please sign in to comment.