mirror of
https://github.com/Av0idD4rk/firegex.git
synced 2026-10-23 16:31:00 +00:00
Stop a non-string filter code from crashing the nfproxy page
`genericapi` ran every response body through `JSON.parse`, falling back to
the raw text only when that threw. The nfproxy filter source is served as a
PlainTextResponse, so a filter file that happens to be valid JSON came back
as a number/array/object. Mantine's CodeHighlight then calls `code.trim()`
on it, which throws and takes the whole page down with it. `42`, `"abc"`,
`[1,2]` and `{"a":1}` are all both valid JSON and valid Python, so they
pass the upload validation and leave the service page unreachable.
Responses declaring text/plain are no longer parsed, and the render site
type-checks the code before handing it to CodeHighlight.
This commit is contained in:
parent
090d117115
commit
ba2703d4bf
@ -111,7 +111,11 @@ export async function genericapi(method:string,path:string,data:any = undefined,
|
|||||||
const errorDefault = res.statusText
|
const errorDefault = res.statusText
|
||||||
return res.json().then( res => reject(getErrorMessageFromServerResponse(res, errorDefault)) ).catch( _err => reject(errorDefault))
|
return res.json().then( res => reject(getErrorMessageFromServerResponse(res, errorDefault)) ).catch( _err => reject(errorDefault))
|
||||||
}
|
}
|
||||||
|
// text/plain bodies (the nfproxy filter source) stay strings: a source file that
|
||||||
|
// happens to be valid JSON must not be parsed into a number/array/object
|
||||||
|
const isPlainText = (res.headers.get("content-type") ?? "").startsWith("text/plain")
|
||||||
res.text().then(t => {
|
res.text().then(t => {
|
||||||
|
if (isPlainText) return resolve(t)
|
||||||
try{
|
try{
|
||||||
resolve(JSON.parse(t))
|
resolve(JSON.parse(t))
|
||||||
}catch(e){
|
}catch(e){
|
||||||
|
|||||||
@ -207,7 +207,7 @@ export default function ServiceDetailsNFProxy() {
|
|||||||
</Group>
|
</Group>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
{filterCode.data ? <>
|
{typeof filterCode.data === "string" && filterCode.data ? <>
|
||||||
<Group justify="center" gap="xs" mt="xl">
|
<Group justify="center" gap="xs" mt="xl">
|
||||||
<ThemeIcon radius="md" size="md" variant="light" color="yellow"><FaPython size={16} /></ThemeIcon>
|
<ThemeIcon radius="md" size="md" variant="light" color="yellow"><FaPython size={16} /></ThemeIcon>
|
||||||
<Title order={3}>Filter code</Title>
|
<Title order={3}>Filter code</Title>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user