mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 03:20:12 +08:00
fix: update CLIFileExistenceChecker to accept containerId in constructor
This commit is contained in:
1 parent
5077f9c677
commit
f7860c6197
2 files changed
+16
-21
No files matched your search
@@ -39,7 +39,7 @@ export const newCommand = asyncHandler(async (req: Request, res: Response) => {
|
|||||||
const gameSession = new GameSession(
|
const gameSession = new GameSession(
|
||||||
session,
|
session,
|
||||||
quest,
|
quest,
|
||||||
new CLIFileExistenceChecker()
|
new CLIFileExistenceChecker(session.containerId!)
|
||||||
)
|
)
|
||||||
|
|
||||||
const event = await gameSession.runCommand(command)
|
const event = await gameSession.runCommand(command)
|
||||||
|
|||||||
@@ -7,26 +7,21 @@ function sanitizeId(id: string) {
|
|||||||
return id.replace(/[^a-zA-Z0-9]/g, '')
|
return id.replace(/[^a-zA-Z0-9]/g, '')
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line import/prefer-default-export
|
|
||||||
export function checkFile(id: string, file: IFileInput) {
|
|
||||||
return new Promise<boolean>((resolve) => {
|
|
||||||
const cmd = buildFileCheckCmd(file)
|
|
||||||
// WARNING: This is vulnerable to command injection
|
|
||||||
execFile(
|
|
||||||
'docker',
|
|
||||||
['exec', sanitizeId(id), ...cmd],
|
|
||||||
{ timeout: 1000 },
|
|
||||||
(error) => {
|
|
||||||
const exists = !error
|
|
||||||
resolve(exists)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export class CLIFileExistenceChecker implements IFileExistenceChecker {
|
export class CLIFileExistenceChecker implements IFileExistenceChecker {
|
||||||
// eslint-disable-next-line class-methods-use-this
|
constructor(private readonly containerId: string) {}
|
||||||
async exists(file: IFileInput) {
|
exists(file: IFileInput) {
|
||||||
return checkFile(file.path, file)
|
return new Promise<boolean>((resolve) => {
|
||||||
|
const cmd = buildFileCheckCmd(file)
|
||||||
|
// WARNING: This is vulnerable to command injection
|
||||||
|
execFile(
|
||||||
|
'docker',
|
||||||
|
['exec', sanitizeId(this.containerId), ...cmd],
|
||||||
|
{ timeout: 1000 },
|
||||||
|
(error) => {
|
||||||
|
const exists = !error
|
||||||
|
resolve(exists)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user