Commit fd648ef
fix(csharp): improve server-side property name validation (#72)
## Summary
Improves server-side property name validation to support standard Spark
configuration naming conventions while maintaining security against SQL
injection attacks.
### Changes
- **Updated validation regex**: Changed from `^[a-zA-Z_]+$` to
`^[a-zA-Z0-9_.]+$`
- Now supports dots (e.g., `spark.databricks.sql.metricViewV2.enabled `)
- Now supports numbers (e.g., `spark.databricks.sql.metricViewV2.enabled
`)
- Maintains security by blocking special characters
- **Refactored validation logic**:
- Moved validation into `GetServerSideProperties()` for centralized
filtering
- Changed `IsValidPropertyName` from `private` to `internal` for
testability
- Removed duplicate validation code from
`ApplyServerSidePropertiesAsync`
- **Enhanced observability**:
- Added Activity tracing with `connection.server_side_property.filtered`
event
- Added Activity tracing for SET query failures
- Wrapped `ApplyServerSidePropertiesAsync` in `TraceActivityAsync`
- **Added comprehensive tests**:
- Created `DatabricksConnectionUnitTests.cs` with 41 test cases
- Tests cover valid patterns, invalid characters, and edge cases
- All tests passing ✅
### Test Plan
```bash
dotnet test --filter "FullyQualifiedName~DatabricksConnectionUnitTests"
```
**Result**: All 41 tests passed
### Examples of Now-Supported Properties
- ✅ `spark.sql.adaptive.enabled`
- ✅ `spark.executor.instances`
- ✅ `spark.databricks.delta.optimizeWrite.enabled`
- ✅ `my_custom_property123`
### Security
Still blocks potentially dangerous input:
- ❌ Hyphens, spaces, semicolons
- ❌ Quotes, equals signs
- ❌ Special characters that could enable SQL injection
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Sonnet 4.5 <[email protected]>1 parent 9066f08 commit fd648ef
File tree
2 files changed
+231
-38
lines changed- csharp
- src
- test/Unit
2 files changed
+231
-38
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
578 | 578 | | |
579 | 579 | | |
580 | 580 | | |
581 | | - | |
| 581 | + | |
582 | 582 | | |
583 | 583 | | |
584 | 584 | | |
| |||
677 | 677 | | |
678 | 678 | | |
679 | 679 | | |
| 680 | + | |
| 681 | + | |
680 | 682 | | |
681 | | - | |
682 | | - | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
683 | 686 | | |
684 | | - | |
685 | | - | |
686 | | - | |
687 | | - | |
688 | | - | |
689 | | - | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
690 | 706 | | |
691 | 707 | | |
692 | 708 | | |
| |||
695 | 711 | | |
696 | 712 | | |
697 | 713 | | |
698 | | - | |
699 | | - | |
700 | | - | |
701 | | - | |
702 | | - | |
703 | | - | |
704 | | - | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
| 714 | + | |
713 | 715 | | |
714 | | - | |
| 716 | + | |
715 | 717 | | |
716 | | - | |
717 | | - | |
| 718 | + | |
718 | 719 | | |
719 | 720 | | |
720 | | - | |
721 | | - | |
722 | | - | |
| 721 | + | |
723 | 722 | | |
724 | | - | |
| 723 | + | |
725 | 724 | | |
726 | | - | |
| 725 | + | |
727 | 726 | | |
728 | | - | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
729 | 733 | | |
730 | | - | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
731 | 749 | | |
732 | | - | |
| 750 | + | |
733 | 751 | | |
734 | 752 | | |
735 | | - | |
| 753 | + | |
736 | 754 | | |
737 | | - | |
| 755 | + | |
| 756 | + | |
738 | 757 | | |
739 | 758 | | |
740 | | - | |
| 759 | + | |
741 | 760 | | |
742 | 761 | | |
743 | 762 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
0 commit comments