kopia lustrzana https://github.com/cloudflare/wildebeest
Return validation fails as errors w/ CORS headers
rodzic
cf15dcc56e
commit
9392e2595c
|
@ -1,5 +1,6 @@
|
||||||
import { ContextData } from 'wildebeest/backend/src/types/context'
|
import { ContextData } from 'wildebeest/backend/src/types/context'
|
||||||
import { cors } from 'wildebeest/backend/src/utils/cors'
|
import { cors } from 'wildebeest/backend/src/utils/cors'
|
||||||
|
import * as errors from 'wildebeest/backend/src/errors'
|
||||||
import type { JWK } from 'wildebeest/backend/src/webpush/jwk'
|
import type { JWK } from 'wildebeest/backend/src/webpush/jwk'
|
||||||
import type { Env } from 'wildebeest/backend/src/types/env'
|
import type { Env } from 'wildebeest/backend/src/types/env'
|
||||||
import { createClient } from 'wildebeest/backend/src/mastodon/client'
|
import { createClient } from 'wildebeest/backend/src/mastodon/client'
|
||||||
|
@ -26,19 +27,19 @@ export async function handleRequest(db: D1Database, request: Request, vapidKeys:
|
||||||
const body: AppsPost = await readBody<AppsPost>(request)
|
const body: AppsPost = await readBody<AppsPost>(request)
|
||||||
|
|
||||||
// Parameter validation according to https://github.com/mastodon/mastodon/blob/main/app/lib/application_extension.rb
|
// Parameter validation according to https://github.com/mastodon/mastodon/blob/main/app/lib/application_extension.rb
|
||||||
if ((body.client_name === undefined) || (body.client_name?.trim() === '')) {
|
if (body.client_name === undefined || body.client_name?.trim() === '') {
|
||||||
return new Response('Unprocessable entity: client_name cannot be an empty string', { status: 422 })
|
return errors.unprocessableEntity('client_name cannot be an empty string')
|
||||||
} else if ((body.client_name?.length > 60)) {
|
} else if (body.client_name?.length > 60) {
|
||||||
return new Response('Unprocessable entity: client_name cannot exceed 60 characters', { status: 422 })
|
return errors.unprocessableEntity('client_name cannot exceed 60 characters')
|
||||||
} else if ((body.redirect_uris === undefined) || (body.redirect_uris?.trim() === '')) {
|
} else if (body.redirect_uris === undefined || body.redirect_uris?.trim() === '') {
|
||||||
return new Response('Unprocessable entity: redirect_uris cannot be an empty string', { status: 422 })
|
return errors.unprocessableEntity('redirect_uris cannot be an empty string')
|
||||||
} else if ((body.redirect_uris?.length > 2000)) {
|
} else if (body.redirect_uris?.length > 2000) {
|
||||||
return new Response('Unprocessable entity: redirect_uris cannot exceed 2000 characters', { status: 422 })
|
return errors.unprocessableEntity('redirect_uris cannot exceed 2000 characters')
|
||||||
} else if (body.redirect_uris !== 'urn:ietf:wg:oauth:2.0:oob') {
|
} else if (body.redirect_uris !== 'urn:ietf:wg:oauth:2.0:oob') {
|
||||||
try {
|
try {
|
||||||
new URL("", body.redirect_uris);
|
new URL('', body.redirect_uris)
|
||||||
} catch {
|
} catch {
|
||||||
return new Response('Unprocessable entity: redirect_uris must be a valid URI', { status: 422 })
|
return errors.unprocessableEntity('redirect_uris must be a valid URI')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue