-
Notifications
You must be signed in to change notification settings - Fork 13k
chore: add hono as router #35078
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
chore: add hono as router #35078
Changes from all commits
4876e39
2a32480
24bb56a
d674f39
c85f9a9
a875f77
c3c7bd2
377f5a6
427f3b9
9ba4601
904865e
fd7806b
f61cea1
6a1f080
b874815
9d6f82c
b1b67bf
f554f3c
583e29c
ff2508b
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 |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ import type { IUser, LicenseModule } from '@rocket.chat/core-typings'; | |
| import type { Logger } from '@rocket.chat/logger'; | ||
| import type { Method, MethodOf, OperationParams, OperationResult, PathPattern, UrlParams } from '@rocket.chat/rest-typings'; | ||
| import type { ValidateFunction } from 'ajv'; | ||
| import type { Request, Response } from 'express'; | ||
|
|
||
| import type { ITwoFactorOptions } from '../../2fa/server/code'; | ||
|
|
||
|
|
@@ -12,7 +11,7 @@ export type RedirectStatusCodes = Exclude<Range<308>, Range<300>>; | |
|
|
||
| export type AuthorizationStatusCodes = Exclude<Range<451>, Range<400>>; | ||
|
|
||
| export type ErrorStatusCodes = Exclude<Range<511>, Range<500>>; | ||
| export type ErrorStatusCodes = Exclude<Exclude<Range<511>, Range<500>>, 509>; | ||
|
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. export type ErrorStatusCodes = 500 | 510;The ErrorStatusCodes type now excludes 509 from the range. This could potentially cause issues if 509 is a valid error code in the system. Consider documenting this exclusion or ensuring it's intentional. Talk to Kody by mentioning @kody Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction. |
||
|
|
||
| export type SuccessResult<T, TStatusCode extends SuccessStatusCodes = 200> = { | ||
| statusCode: TStatusCode; | ||
|
|
@@ -137,6 +136,7 @@ export type PartialThis = { | |
| readonly response: Response; | ||
| readonly userId: string; | ||
| readonly bodyParams: Record<string, unknown>; | ||
| readonly path: string; | ||
| readonly queryParams: Record<string, string>; | ||
| readonly queryOperations?: string[]; | ||
| readonly queryFields?: string[]; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,10 @@ | ||
| import type { IUser } from '@rocket.chat/core-typings'; | ||
| import { Users } from '@rocket.chat/models'; | ||
| import type { Request } from 'express'; | ||
| import { Accounts } from 'meteor/accounts-base'; | ||
|
|
||
| export async function getLoggedInUser(request: Request): Promise<Pick<IUser, '_id' | 'username'> | null> { | ||
| const token = request.headers['x-auth-token']; | ||
| const userId = request.headers['x-user-id']; | ||
| const token = request.headers.get('x-auth-token'); | ||
|
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. const token = request.headers.get('x-auth-token')?.trim();
const userId = request.headers.get('x-user-id')?.trim();Multiple instances of missing input validation for critical parameters, potentially leading to security vulnerabilities or runtime errors. 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. |
||
| const userId = request.headers.get('x-user-id'); | ||
| if (!token || !userId || typeof token !== 'string' || typeof userId !== 'string') { | ||
| return null; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,13 +25,13 @@ export async function parseJsonQuery(api: PartialThis): Promise<{ | |
| query: Record<string, unknown>; | ||
| }> { | ||
| const { | ||
| request: { path: route }, | ||
| userId, | ||
| queryParams: params, | ||
| logger, | ||
| queryFields, | ||
| queryOperations, | ||
| response, | ||
| request: { route }, | ||
| } = api; | ||
|
|
||
| let sort; | ||
|
|
@@ -60,7 +60,7 @@ export async function parseJsonQuery(api: PartialThis): Promise<{ | |
| let fields: Record<string, 0 | 1> | undefined; | ||
| if (params.fields && isUnsafeQueryParamsAllowed) { | ||
| try { | ||
| apiDeprecationLogger.parameter(route, 'fields', '8.0.0', response, messageGenerator); | ||
| apiDeprecationLogger.parameter(api.path, 'fields', '8.0.0', response, messageGenerator); | ||
|
Member
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. [nitpick] if you're destructuring a ton of things from |
||
| fields = JSON.parse(params.fields) as Record<string, 0 | 1>; | ||
| Object.entries(fields).forEach(([key, value]) => { | ||
| if (value !== 1 && value !== 0) { | ||
|
|
@@ -99,7 +99,7 @@ export async function parseJsonQuery(api: PartialThis): Promise<{ | |
|
|
||
| // Limit the fields by default | ||
| fields = Object.assign({}, fields, API.v1.defaultFieldsToExclude); | ||
| if (route.includes('/v1/users.')) { | ||
| if (api.path.includes('/v1/users.')) { | ||
| if (await hasPermissionAsync(userId, 'view-full-other-user-info')) { | ||
| fields = Object.assign(fields, API.v1.limitedUserFieldsToExcludeIfIsPrivilegedUser); | ||
| } else { | ||
|
|
@@ -109,7 +109,7 @@ export async function parseJsonQuery(api: PartialThis): Promise<{ | |
|
|
||
| let query: Record<string, any> = {}; | ||
| if (params.query && isUnsafeQueryParamsAllowed) { | ||
| apiDeprecationLogger.parameter(route, 'query', '8.0.0', response, messageGenerator); | ||
| apiDeprecationLogger.parameter(api.path, 'query', '8.0.0', response, messageGenerator); | ||
| try { | ||
| query = ejson.parse(params.query); | ||
| query = clean(query, pathAllowConf.def); | ||
|
|
@@ -125,7 +125,7 @@ export async function parseJsonQuery(api: PartialThis): Promise<{ | |
| if (typeof query === 'object') { | ||
| let nonQueryableFields = Object.keys(API.v1.defaultFieldsToExclude); | ||
|
|
||
| if (route.includes('/v1/users.')) { | ||
| if (api.path.includes('/v1/users.')) { | ||
| if (await hasPermissionAsync(userId, 'view-full-other-user-info')) { | ||
| nonQueryableFields = nonQueryableFields.concat(Object.keys(API.v1.limitedUserFieldsToExcludeIfIsPrivilegedUser)); | ||
| } else { | ||
|
|
||
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 removal of the explicit 'express' import and the associated types 'Request' and 'Response' might lead to issues with type checking and code completion. While the 'WebApp' object might provide similar functionality, it's crucial to ensure type safety. Consider adding explicit types for request and response objects within the affected methods to maintain type correctness and avoid potential runtime errors.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.