Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Improve variable scope tracking for set directives across blocks #100

@dvershinin

Description

@dvershinin

Summary

When analyzing configs that use set directive to define variables in one block and reference them in another, gixy produces INFO messages like:

[variable] INFO Can't find variable 'Root_Path' in script '$Root_Path/server-error-pages/_site' inside block 'location @error {'.

The variable is actually defined via set $Root_Path /path/... in the parent server block, but gixy's static analysis doesn't trace it across block scopes.

Example Config

server {
    set $Root_Path /usr/share/nginx/html/www/vhosts_dir/example.com;
    root $Root_Path;
    
    location @error {
        # gixy can't find $Root_Path here
        root $Root_Path/server-error-pages/_site;
    }
}

Current Behavior

Gixy logs INFO messages about not finding the variable, even though:

  1. The variable IS defined in the config
  2. The config is valid and works at runtime
  3. nginx correctly resolves the variable

Expected Behavior

Gixy should trace set directive variables through the config tree and recognize that variables defined in a server block are available in nested location blocks.

Technical Notes

The variable tracking in gixy/core/context.py and gixy/core/manager.py currently:

  • Pushes/pops context for blocks with self_context=True
  • Adds variables from directives with provide_variables=True

The set directive defines named variables that should persist through child blocks, but the current scoping logic may not properly inherit these across all block types.

Impact

This is an INFO-level message, not a security finding. The analysis still works, but users may be confused by messages about undefined variables that are actually valid.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions