(ref: StructuredOutputSchemaRef)
| 78 | } |
| 79 | |
| 80 | function schemaPathFor(ref: StructuredOutputSchemaRef): string { |
| 81 | const schemasDir = getStructuredOutputSchemasDir(); |
| 82 | const schemaPath = path.join(schemasDir, ref.schema, `${ref.version}.schema.json`); |
| 83 | const resolvedPath = path.resolve(schemaPath); |
| 84 | const resolvedSchemasDir = path.resolve(schemasDir); |
| 85 | |
| 86 | // Prevent path traversal attacks by ensuring the resolved path is within the schemas directory |
| 87 | if ( |
| 88 | !resolvedPath.startsWith(resolvedSchemasDir + path.sep) && |
| 89 | resolvedPath !== resolvedSchemasDir |
| 90 | ) { |
| 91 | throw new Error( |
| 92 | `Invalid schema path: attempted path traversal detected for ${ref.schema}@${ref.version}`, |
| 93 | ); |
| 94 | } |
| 95 | |
| 96 | return schemaPath; |
| 97 | } |
| 98 | |
| 99 | function collectAndRewriteCommonRefs(value: unknown, pendingDefs: Set<string>): unknown { |
| 100 | if (Array.isArray(value)) { |
no test coverage detected