Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you set multiple file extensions to allowed for request filtering? #597

Open
obsolete3032 opened this issue May 25, 2021 · 1 comment
Labels
needs investigation The issue needs to be investigated by the maintainers or/and the community.

Comments

@obsolete3032
Copy link

I am trying to add multiple file extensions to the allowed list for request filtering using the xWebConfigPropertyCollection resource but am stuck on exactly how to do it. I can add an individual extension, but can't figure out how to indicate multiples. Below adds one extension with the whole string. If I remove the ", .aspz" then it successfully adds the .aspx extension.

WebsitePath = 'MACHINE/WEBROOT/APPHOST'
Filter = 'system.webServer/security/requestFiltering'
CollectionName = 'fileExtensions'
ItemName = 'add'
ItemKeyName = 'fileExtension'
ItemKeyValue = '.aspx, .aspz'
ItemPropertyName = 'allowed'
ItemPropertyValue = 'true'
Ensure = 'Present'

@johlju johlju added the needs investigation The issue needs to be investigated by the maintainers or/and the community. label May 27, 2021
@remcoeissing
Copy link
Contributor

Using the above configuration would result in this configuration <add fileExtension=".aspx, .aspz" />. This will mean that a file should be named like index.aspx, .aspz, which is not what you want to achieve. Instead you could loop over the extensions that you would like to allow and add all of them. That could look something like

Configuration Sample_xWebConfigPropertyCollection_Add
{
    param
    (
        # Target nodes to apply the configuration.
        [Parameter()]
        [String[]]
        $NodeName = 'localhost',

        # File extensions to allow in request filtering configuration
        [Parameter()]
        [String[]]
        $AllowedFileExtensions = @('.aspx', '.aspz')
    )

    # Import the modules that define custom resources
    Import-DscResource -ModuleName xWebAdministration

    Node $NodeName
    {
        foreach($extension in $AllowedFileExtensions)
        {
            xWebConfigPropertyCollection "$($NodeName) - Request Filtering allow fileextension $($extension)"
            {
                WebsitePath       = 'MACHINE/WEBROOT/APPHOST'
                Filter            = 'system.webServer/security/requestFiltering'
                CollectionName    = 'fileExtensions'
                ItemName          = 'add'
                ItemKeyName       = 'fileExtension'
                ItemKeyValue      = $extension
                ItemPropertyName  = 'allowed'
                ItemPropertyValue = 'true'
                Ensure            = 'Present'
            }
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs investigation The issue needs to be investigated by the maintainers or/and the community.
Projects
None yet
Development

No branches or pull requests

3 participants