mirror of
https://github.com/caprover/caprover.git
synced 2026-12-05 09:08:18 +00:00
ShellQuote.parse() returns { op: 'glob', pattern } objects instead of
strings for unquoted wildcard tokens such as *.${domainName}, causing
CertCommandGenerator.getCertbotCertCommand() to throw Invalid command.
Because CertbotManager executes commands directly via Docker exec without
a shell, unquoted glob tokens cannot trigger shell expansion and can be
passed through as their literal pattern strings while continuing to reject
shell control operators and comments.
Fixes #2222
94 lines
3.0 KiB
TypeScript
94 lines
3.0 KiB
TypeScript
import { CertCommandGenerator } from '../src/user/system/CertbotManager'
|
|
|
|
const defaultCommand = 'certbot certonly --domain ${domainName}'
|
|
const fakeWebroot = '/path/to/webroot'
|
|
|
|
describe('CertCommandGenerator wildcard and glob handling', () => {
|
|
test('supports unquoted wildcard domain arguments in command rules', () => {
|
|
const generator = new CertCommandGenerator(
|
|
[
|
|
{
|
|
domain: '*',
|
|
command:
|
|
'certbot certonly --dns-cloudflare --dns-cloudflare-credentials /etc/letsencrypt/captain-cloudflare.token -d ${domainName} -d *.${domainName}',
|
|
},
|
|
],
|
|
defaultCommand
|
|
)
|
|
|
|
expect(
|
|
generator.getCertbotCertCommand('example.com', fakeWebroot)
|
|
).toEqual([
|
|
'certbot',
|
|
'certonly',
|
|
'--dns-cloudflare',
|
|
'--dns-cloudflare-credentials',
|
|
'/etc/letsencrypt/captain-cloudflare.token',
|
|
'-d',
|
|
'example.com',
|
|
'-d',
|
|
'*.example.com',
|
|
])
|
|
})
|
|
|
|
test('supports quoted wildcard domain arguments identically', () => {
|
|
const generator = new CertCommandGenerator(
|
|
[
|
|
{
|
|
domain: '*',
|
|
command:
|
|
'certbot certonly -d ${domainName} -d "*.${domainName}"',
|
|
},
|
|
],
|
|
defaultCommand
|
|
)
|
|
|
|
expect(
|
|
generator.getCertbotCertCommand('example.com', fakeWebroot)
|
|
).toEqual([
|
|
'certbot',
|
|
'certonly',
|
|
'-d',
|
|
'example.com',
|
|
'-d',
|
|
'*.example.com',
|
|
])
|
|
})
|
|
|
|
test('supports unquoted question mark glob characters as literal arguments', () => {
|
|
const generator = new CertCommandGenerator(
|
|
[
|
|
{
|
|
domain: '*',
|
|
command: 'certbot certonly -d ??.${domainName}',
|
|
},
|
|
],
|
|
defaultCommand
|
|
)
|
|
|
|
expect(
|
|
generator.getCertbotCertCommand('example.com', fakeWebroot)
|
|
).toEqual(['certbot', 'certonly', '-d', '??.example.com'])
|
|
})
|
|
|
|
test('rejects shell control operators and comments in command rules', () => {
|
|
const invalidCommands = [
|
|
'certbot certonly -d ${domainName}; rm -rf /',
|
|
'certbot certonly -d *.${domainName}; rm -rf /',
|
|
'certbot certonly -d ${domainName} && echo ok',
|
|
'certbot certonly -d ${domainName} | cat',
|
|
'certbot certonly -d ${domainName} # trailing comment',
|
|
]
|
|
|
|
for (const command of invalidCommands) {
|
|
const generator = new CertCommandGenerator(
|
|
[{ domain: '*', command }],
|
|
defaultCommand
|
|
)
|
|
expect(() =>
|
|
generator.getCertbotCertCommand('example.com', fakeWebroot)
|
|
).toThrow(`Invalid command: ${command}`)
|
|
}
|
|
})
|
|
})
|