Skip to content

Prevent importing files outside import paths #1897

Closed
@gimenete

Description

@gimenete

We are thinking to include Less in a software-as-a-service where users can edit their own templates.

We've made a simple test to prevent users @import sensitive files.

var parser = new(less.Parser)({
    paths: ['./less_files'],
    filename: 'style.less'
})

parser.parse('@import "../forbidden.less";', function (e, tree) {
    var output = tree.toCSS({ compress: true }) // Minify CSS output
    console.log('output', output)
})

This works so they would be able to import files outside their directories. Is there any way to prevent this behavior? It would be great to have something like a 'safeImports" flag that would prevent this.

We know that the parser fails if the imported file is not a valid less file, but we would like to prevent the parser even to read the file. Is that possible?

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions