Skip to content

Commit f22d268

Browse files
Validate Set-ConfluenceConfig input at the boundary
Reject the reserved 'ID' config key and require PerPage to be a positive integer before persisting, so a caller cannot corrupt the stored configuration or feed an invalid v2 'limit' value into Invoke-ConfluenceRestMethod (review thread on Set-ConfluenceConfig L37).
1 parent d26bc21 commit f22d268

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/functions/public/Config/Set-ConfluenceConfig.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ function Set-ConfluenceConfig {
3131
)
3232

3333
Initialize-ConfluenceConfig
34+
35+
# Guard the boundary before persisting so a caller cannot corrupt the stored configuration:
36+
# 'ID' is the reserved context key that identifies the config record itself, and 'PerPage'
37+
# is used verbatim as the v2 'limit' query value, so it must be a positive integer.
38+
if ($Name -eq 'ID') {
39+
throw "The configuration key 'ID' is reserved for internal use and cannot be set."
40+
}
41+
if ($Name -eq 'PerPage') {
42+
$perPage = 0
43+
if (-not [int]::TryParse([string]$Value, [ref]$perPage) -or $perPage -lt 1) {
44+
throw "PerPage must be a positive integer; received '$Value'."
45+
}
46+
$Value = $perPage
47+
}
48+
3449
if ($PSCmdlet.ShouldProcess("Confluence config '$Name'", 'Set')) {
3550
$script:Confluence.Config[$Name] = $Value
3651
$null = Set-Context -ID $script:Confluence.DefaultConfig.ID -Context $script:Confluence.Config -Vault $script:Confluence.ContextVault

0 commit comments

Comments
 (0)