# Test for field name containing special characters

**URL:** <https://discuss.elastic.co/t/test-for-field-name-containing-special-characters/226117>\
**Category:** Logstash\
**Created:** [April 1, 2020, 7:23pm UTC](https://discuss.elastic.co/t/test-for-field-name-containing-special-characters/226117 "2020-04-01T19:23:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sampas](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@sampas](https://discuss.elastic.co/u/sampas)\
**Post date:** [April 1, 2020, 7:23pm UTC](https://discuss.elastic.co/t/test-for-field-name-containing-special-characters/226117/1 "2020-04-01T19:23:52Z")

</div>

I want to test a field name to see if it contains a "%" character and drop it if it does. I do a KV on web logs, and we regularly see threat actors trying to escape application logic with long strings in the URI, e.g.  
[burpcollaborator.net](http://burpcollaborator.net)%2f%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%.

I see lots of ruby options for string manipulation on the contents of fields, but not on names of fields.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [April 1, 2020, 7:54pm UTC](https://discuss.elastic.co/t/test-for-field-name-containing-special-characters/226117/2 "2020-04-01T19:54:53Z")

</div>

You can do this in ruby...

```
ruby {
    code => '
         event.to_hash.each { |k, v|
               # Write some code here to modify k to newk. e.g newk = k.gsub(/%/, "")
               event.remove(k)
               event.set(newk, v)
         }
     '
}

```

Did you want to drop the %, or drop the entire field whose name contains %?

---

<div class="post-metadata">

**Author:** ![sampas](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@sampas](https://discuss.elastic.co/u/sampas)\
**Post date:** [April 1, 2020, 8:00pm UTC](https://discuss.elastic.co/t/test-for-field-name-containing-special-characters/226117/3 "2020-04-01T20:00:59Z")

</div>

If the field name has a % in it, drop the field.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [April 1, 2020, 8:06pm UTC](https://discuss.elastic.co/t/test-for-field-name-containing-special-characters/226117/4 "2020-04-01T20:06:10Z")

</div>

OK, change the body of the .each to

```
        if k.include? "%"
            event.remove(k)
        end
```

---

<div class="post-metadata">

**Author:** ![sampas](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@sampas](https://discuss.elastic.co/u/sampas)\
**Post date:** [April 1, 2020, 8:10pm UTC](https://discuss.elastic.co/t/test-for-field-name-containing-special-characters/226117/5 "2020-04-01T20:10:35Z")

</div>

I am trying that out now.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 29, 2020, 8:10pm UTC](https://discuss.elastic.co/t/test-for-field-name-containing-special-characters/226117/6 "2020-04-29T20:10:37Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
