-
Notifications
You must be signed in to change notification settings - Fork 13k
regression: parse urlencoded body as string when there is no specific key(payload) #35823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,7 +94,7 @@ async function executeIntegrationRest() { | |
| } | ||
| const content_raw = Buffer.concat(buffers).toString('utf8'); | ||
| const protocol = `${this.request.headers.get('x-forwarded-proto')}:` || 'http:'; | ||
| const url = new URL(this.request.url, `${protocol}//${this.request.headers.host}`); | ||
| const url = new URL(this.request.url, `${protocol}//${this.request.headers.get('host')}`); | ||
|
|
||
| const request = { | ||
| url: { | ||
|
|
@@ -325,13 +325,22 @@ const middleware = async (c, next) => { | |
| } | ||
|
|
||
| try { | ||
| const body = Object.fromEntries(new URLSearchParams(await req.raw.clone().text())); | ||
| if (!body || typeof body !== 'object' || !('payload' in body) || Object.keys(body).length !== 1) { | ||
| const content = await req.raw.clone().text(); | ||
| const body = Object.fromEntries(new URLSearchParams(content)); | ||
| if (!body || typeof body !== 'object' || Object.keys(body).length !== 1) { | ||
| return next(); | ||
| } | ||
|
|
||
| // need to compose the full payload in this weird way because body-parser thought it was a form | ||
| c.set('bodyParams-override', JSON.parse(body.payload)); | ||
| if (body.payload) { | ||
| // need to compose the full payload in this weird way because body-parser thought it was a form | ||
| c.set('bodyParams-override', JSON.parse(body.payload)); | ||
| return next(); | ||
| } | ||
| incomingLogger.debug({ | ||
| msg: 'Body received as application/x-www-form-urlencoded without the "payload" key, parsed as string', | ||
| content, | ||
| }); | ||
| c.set('bodyParams-override', JSON.parse(content)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. try {
const singleKey = Object.keys(body)[0];
const valueToParse = body[singleKey];
c.set('bodyParams-override', JSON.parse(valueToParse));
} catch (parseError) {
incomingLogger.error({ msg: 'Failed to parse form field value as JSON', key: Object.keys(body)[0], error: parseError });
c.body(JSON.stringify({ success: false, error: 'Invalid JSON in form field value' }), 400);
return; // Stop processing here
}Parsing the raw form content ( This issue appears in multiple locations:
Talk to Kody by mentioning @kody Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
Comment on lines
+336
to
+343
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. try {
const parsed = JSON.parse(body.payload);
c.set('bodyParams-override', parsed);
return next();
} catch (e) {
incomingLogger.error({ msg: 'Failed to parse payload as JSON', error: e });
c.body(JSON.stringify({ success: false, error: 'Invalid JSON payload' }), 400);
return;
}The This issue appears in multiple locations:
Talk to Kody by mentioning @kody Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction. |
||
| } catch (e) { | ||
| c.body(JSON.stringify({ success: false, error: e.message }), 400); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
this.request.headers.get('host')call might returnnull, leading to potential errors when constructing a URL with an invalid host part.This issue appears in multiple locations:
Please add validation for the 'host' header to ensure it is present and handle cases where it is missing to prevent errors in URL construction.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.