Skip to content
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

fix: return http 415 if unsuporrted content type #1313

Merged
21 changes: 15 additions & 6 deletions packages/node/src/transport/HttpInboundTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type { Server } from 'http'
import { DidCommMimeType, AriesFrameworkError, TransportService, utils, MessageReceiver } from '@aries-framework/core'
import express, { text } from 'express'

const supportedContentTypes: string[] = [DidCommMimeType.V0, DidCommMimeType.V1]

export class HttpInboundTransport implements InboundTransport {
public readonly app: Express
private port: number
Expand All @@ -22,12 +24,19 @@ export class HttpInboundTransport implements InboundTransport {
this.app = app ?? express()
this.path = path ?? '/'

this.app.use(
text({
type: [DidCommMimeType.V0, DidCommMimeType.V1],
limit: '5mb',
})
)
this.app.use((req, res, next) => {
const contentType = req.headers['content-type']

if (!contentType || !supportedContentTypes.includes(contentType)) {
return res
.status(415)
.send('Unsupported content-type. Supported content-types are: ' + supportedContentTypes.join(', '))
}

return next()
})

this.app.use(text({ type: supportedContentTypes, limit: '5mb' }))
}

public async start(agent: Agent) {
Expand Down