Skip to content

Commit 789bee2

Browse files
feat: typing ingest lambda and related files, app entry, adjusting types as needed (#1087)
* feat: convert errors.js to typescript fix: fix issue with ava test runner not identifying the error typescript file and finding temporary workaround during migration. * feat: creating base STAC types fix: updating linter overrides fro typescript * feat: convert geo-utils and logger to typescript feat: use BBox type from geojson lib * feat: typing stac-utils fix: tweaking types based on experience in stac-utils.ts * feat: deleted s3-utils.js which was slightly different from s3-utils.ts. Confirmed using s3-utils.ts passes all tests * feat: rounding out typing for s3-utils.ts * feat: typing sns file * feat: typing aws clients * feat: converting database clients to typescript * complete typing of asset-proxy and asset-buckets files tests: flesh out input object in test to be a more complete StacItem to pass an expected logic gate * feat: first quick pass at typing Searchparams and DbOperation * feat: updating changelog * logger: change to 'info' not 'error' in case of index already existing * feat: typing database.ts and updating types as required * feat: cleaning up types, remove unused, consolidating where appropriate * updating changelog * feat: typing a few remainig untyped params * feat: moved some utils to api-utils.ts and typed them feat: changed api.js to api.ts * feat: typing api.ts, adjusting types as needed * feat: adding missing type, adding return type in a few spots where it was missing * updating changelog * PR feedback * feat: typing ingest lambda and related files, adjusting types as needed * converting lambdas to typescript * feat: finishing typing lambdas, extending base express Request type, adding types as necessary * updating changelog * fix: PR feedback * PR feedback changs after reviewing Claude suggestions * updating .nsprc file
1 parent 28950b3 commit 789bee2

22 files changed

Lines changed: 342 additions & 240 deletions

.nsprc

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@
22
"1113461": {
33
"active": true,
44
"notes": "minimatch is a transitive dependency of @redocly/cli and redoc, used only for API documentation rendering. The vulnerable wildcard pattern matching is not exposed to user input in our usage context, making ReDoS exploitation not feasible.",
5-
"expiry": "2026-04-25"
5+
"expiry": "2026-09-30"
66
},
77
"1113466": {
88
"active": true,
99
"notes": "minimatch is a transitive dependency of @redocly/cli and redoc, used only for API documentation rendering. The vulnerable wildcard pattern matching is not exposed to user input in our usage context, making ReDoS exploitation not feasible.",
10-
"expiry": "2026-04-25"
10+
"expiry": "2026-09-30"
1111
},
1212
"1113540": {
1313
"active": true,
1414
"notes": "minimatch is a transitive dependency of @redocly/cli and redoc, used only for API documentation rendering. The vulnerable wildcard pattern matching is not exposed to user input in our usage context, making ReDoS exploitation not feasible.",
15-
"expiry": "2026-04-25"
15+
"expiry": "2026-09-30"
1616
},
1717
"1113545": {
1818
"active": true,
1919
"notes": "minimatch is a transitive dependency of @redocly/cli and redoc, used only for API documentation rendering. The vulnerable wildcard pattern matching is not exposed to user input in our usage context, making ReDoS exploitation not feasible.",
20-
"expiry": "2026-04-25"
20+
"expiry": "2026-09-30"
2121
},
2222
"1113548": {
2323
"active": true,
2424
"notes": "minimatch is a transitive dependency of @redocly/cli and redoc, used only for API documentation rendering. The vulnerable wildcard pattern matching is not exposed to user input in our usage context, making ReDoS exploitation not feasible.",
25-
"expiry": "2026-04-25"
25+
"expiry": "2026-09-30"
2626
},
2727
"1113553": {
2828
"active": true,
2929
"notes": "minimatch is a transitive dependency of @redocly/cli and redoc, used only for API documentation rendering. The vulnerable wildcard pattern matching is not exposed to user input in our usage context, making ReDoS exploitation not feasible.",
30-
"expiry": "2026-04-25"
30+
"expiry": "2026-09-30"
3131
},
3232
"1115339": {
3333
"active": true,
@@ -39,6 +39,11 @@
3939
"notes": "fast-xml-parser is a transitive dependency of @redocly/cli via openapi-sampler, used only as a build tool to generate static API documentation. The entity expansion limit bypass via JavaScript falsy evaluation of zero values only affects applications that explicitly configure maxEntityCount:0 or maxEntitySize:0. We do not configure fast-xml-parser directly and @redocly/cli is never run against untrusted input, making this not exploitable.",
4040
"expiry": "2026-06-30"
4141
},
42+
"1116957": {
43+
"active": true,
44+
"notes": "fast-xml-parser is a transitive dependency of @redocly/cli via openapi-sampler, used only as a build tool to generate static API documentation. The XMLBuilder XML comment and CDATA injection via unescaped delimiters requires use of the XMLBuilder API with attacker-controlled input. We do not use fast-xml-parser directly and @redocly/cli is never run against untrusted input, making this not exploitable.",
45+
"expiry": "2026-06-30"
46+
},
4247
"1115541": {
4348
"active": true,
4449
"notes": "brace-expansion is a transitive dependency of redoc, used only for API documentation rendering. The zero-step sequence causing process hang is not exploitable as brace-expansion is never used to process untrusted input in our usage context.",
@@ -112,14 +117,34 @@
112117
"1115527": {
113118
"active": true,
114119
"notes": "path-to-regexp is a transitive dependency of express. A DoS via multiple route parameters is a low practical risk for stac-server: deployments are primarily hosted on AWS which provides built-in DDoS detection and mitigation, and the underlying data is generally not mission critical. A fix is expected upstream in the near future and will be incorporated before the next release.",
115-
"expiry": "2026-04-30"
120+
"expiry": "2026-09-30"
116121
},
117122
"1116663": {
118123
"active": true,
119124
"notes": "dompurify is a transitive dependency of @redocly/cli via redoc, used only for API documentation rendering. The ADD_TAGS function form bypassing FORBID_TAGS due to short-circuit evaluation requires both ADD_TAGS as a function and FORBID_TAGS to be configured simultaneously. We do not configure DOMPurify directly and redoc is only used to render static API documentation, making this not exploitable in our usage context.",
120125
"expiry": "2026-09-30"
121126
},
122-
"1116832": {
127+
"1117138": {
128+
"active": true,
129+
"notes": "dompurify is a transitive dependency of @redocly/cli via redoc, used only for API documentation rendering. The FORBID_TAGS bypass via function-based ADD_TAGS predicate requires direct DOMPurify configuration with both options simultaneously. We do not configure DOMPurify directly and redoc is only used to render static API documentation, making this not exploitable in our usage context.",
130+
"expiry": "2026-09-30"
131+
},
132+
"1117139": {
133+
"active": true,
134+
"notes": "dompurify is a transitive dependency of @redocly/cli via redoc, used only for API documentation rendering. The SAFE_FOR_TEMPLATES bypass in RETURN_DOM mode requires direct DOMPurify configuration with RETURN_DOM mode enabled. We do not configure DOMPurify directly and redoc is only used to render static API documentation, making this not exploitable in our usage context.",
135+
"expiry": "2026-09-30"
136+
},
137+
"1117140": {
138+
"active": true,
139+
"notes": "dompurify is a transitive dependency of @redocly/cli via redoc, used only for API documentation rendering. The prototype pollution to XSS bypass via CUSTOM_ELEMENT_HANDLING fallback requires attacker-controlled input to DOMPurify. We do not configure DOMPurify directly and redoc is only used to render static API documentation, making this not exploitable in our usage context.",
140+
"expiry": "2026-09-30"
141+
},
142+
"1117015": {
143+
"active": true,
144+
"notes": "postcss is a transitive dependency of @redocly/cli via styled-components, used only as a build tool to generate static API documentation. The XSS via unescaped </style> in CSS stringify output requires attacker-controlled CSS input processed by PostCSS. We do not use PostCSS directly and @redocly/cli is never run against untrusted input, making this not exploitable.",
145+
"expiry": "2026-09-30"
146+
},
147+
"1117042": {
123148
"active": true,
124149
"notes": "protobufjs is a transitive dependency of @redocly/cli via @opentelemetry/otlp-transformer, used only as a build tool to generate static API documentation. The arbitrary code execution via malicious protobuf definitions requires attacker-controlled protobuf definition files, which is not possible in our usage context as @redocly/cli is never run against untrusted input.",
125150
"expiry": "2026-06-30"

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
},
1818
"editor.tabSize": 2,
1919
"files.insertFinalNewline": true,
20+
"typescript.tsserver.maxTsServerMemory": 4096,
21+
"typescript.tsserver.experimental.enableProjectDiagnostics": false,
22+
"typescript.disableAutomaticTypeAcquisition": true
2023
}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1414

1515
### Changed
1616

17+
- Typing the top level lambda layer ([1087](https://github.com/stac-utils/stac-server/pull/1087))
1718
- Typing the api layer in `api.ts`, pushing some minor functions to a new utility files `api-utils.ts` ([1081](https://github.com/stac-utils/stac-server/pull/1081))
1819
- Converting the database layer to typescript as part of migration ([1077](https://github.com/stac-utils/stac-server/pull/1077))
1920
- Converting additional files to typescript as part of typescript migration and generating related types ([1071](https://github.com/stac-utils/stac-server/pull/1071))

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@
8383
"@smithy/types": "^4.13.1",
8484
"@stoplight/spectral-cli": "^6.15.0",
8585
"@tsconfig/node22": "^22.0.5",
86-
"@types/aws-lambda": "^8.10.159",
86+
"@types/aws-lambda": "^8.10.161",
8787
"@types/color-convert": "^2.0.4",
8888
"@types/color-name": "^2.0.0",
8989
"@types/color-string": "^1.5.5",
9090
"@types/compression": "^1.8.1",
9191
"@types/cors": "^2.8.19",
9292
"@types/debug": "^4.1.12",
9393
"@types/eslint": "^9.6.1",
94-
"@types/express": "^4.17.21",
94+
"@types/express": "^4.17.25",
9595
"@types/geojson": "^7946.0.16",
9696
"@types/http-errors": "^2.0.5",
9797
"@types/lodash-es": "^4.17.12",

src/@types/express/index.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { APIGatewayProxyEvent } from 'aws-lambda'
2+
3+
// extending the main 'express' 'Request' type to add 'endpoint'
4+
// that is not on the default type
5+
declare global {
6+
namespace Express {
7+
interface Request {
8+
endpoint: string
9+
event?: APIGatewayProxyEvent
10+
}
11+
}
12+
}
Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-nocheck
22
import cors from 'cors'
3-
import createError from 'http-errors'
4-
import express from 'express'
3+
import createError, { HttpError } from 'http-errors'
4+
import express, { Request, Response, NextFunction } from 'express'
55
import compression from 'compression'
66
import morgan from 'morgan'
77
import path from 'path'
@@ -13,13 +13,8 @@ import { readFile } from '../../lib/fs.js'
1313
import addEndpoint from './middleware/add-endpoint.js'
1414
import logger from '../../lib/logger.js'
1515
import { AssetProxy } from '../../lib/asset-proxy.js'
16-
17-
/**
18-
* @typedef {import('express').Request} Request
19-
* @typedef {import('express').Response} Response
20-
* @typedef {import('express').NextFunction} NextFunction
21-
* @typedef {import('express').ErrorRequestHandler} ErrorRequestHandler
22-
*/
16+
import { StacItem } from '../../lib/types.js'
17+
import { isFeatureCollection } from '../../lib/stac-utils.js'
2318

2419
export const createApp = async () => {
2520
const txnEnabled = process.env['ENABLE_TRANSACTIONS_EXTENSION'] === 'true'
@@ -115,7 +110,7 @@ export const createApp = async () => {
115110
}
116111
})
117112

118-
app.get('/search', async (req, res, next) => {
113+
app.get('/search', async (req: Request, res: Response, next) => {
119114
try {
120115
const result = await api.searchItems(
121116
database, 'GET', null, req.endpoint, req.query, req.headers
@@ -333,8 +328,8 @@ export const createApp = async () => {
333328
next(error)
334329
}
335330
}
336-
} else if (req.body.type === 'FeatureCollection') {
337-
const duplicateItemErrors = []
331+
} else if (isFeatureCollection(req.body)) {
332+
const duplicateItemErrors: StacItem[] = []
338333
let itemsCreated = 0
339334
for (const item of req.body.features) {
340335
try {
@@ -569,14 +564,13 @@ export const createApp = async () => {
569564
})
570565

571566
// catch 404 and forward to error handler
572-
app.use((_req, _res, next) => {
567+
app.use((_req: Request, _res: Response, next: NextFunction) => {
573568
next(createError(404))
574569
})
575570

576571
// error handler
577572
app.use(
578-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
579-
/** @type {ErrorRequestHandler} */ ((err, _req, res, _next) => {
573+
((err: HttpError, _req: Request, res: Response, _next: NextFunction) => {
580574
res.status(err.status || 500)
581575

582576
res.type('application/json')
@@ -601,5 +595,3 @@ export const createApp = async () => {
601595

602596
return app
603597
}
604-
605-
export default { createApp }

0 commit comments

Comments
 (0)