alleyinteractive / alleyinteractive/alley-coding-standards

Add a sniff for dynamic keys passed to get_block_wrapper_attributes

Open
#76 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
7
Forks
0
PR merge metrics
No merged PRs in 30d

Description

### Description

Keys provided to the `get_block_wrapper_attributes` function are turned into attribute names, and are not escaped. That's fine if we're specifying a hardcoded value and that hardcoded value is known to be safe, like:

```php
echo get_block_wrapper_attributes( [ 'data-my-key' => $my_value ] );
```

Values are already escaped via `esc_attr` in `get_block_wrapper_attributes`, so dynamic values are okay there.

However, if there is a dynamic key, like:

```php
$attributes[ $my_key ] = $my_value;
echo get_block_wrapper_attributes( $attributes );
```

We should flag that, because the key is dynamic and isn't escaped. Escaping should be done by `sanitize_key`.

### Use Case

When a user uses the `get_block_wrapper_attributes` function, phpcs should throw an error if the user has a dynamic key that is unescaped.

Contributor guide

Open the contributing guide

Research direction

Start from the project’s existing PHPCS sniffs and find how they inspect function calls and array keys. The target behavior is for calls to get_block_wrapper_attributes to flag dynamic attribute keys that are not sanitized, while allowing hardcoded keys and dynamic values. Done means PHPCS reports the unsafe dynamic-key case described in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, wordpress
Domain
security, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.