-
Notifications
You must be signed in to change notification settings - Fork 69
Feat(Platform): Replace httproute include with httproute block #3721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ Deploy Preview for kongdeveloper ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| 'name' => config['name'], | ||
| 'namespace' => config['namespace'], | ||
| 'annotations' => { | ||
| 'konghq.com/rewrite' => config['annotation_rewrite']&.gsub('$', '\$'), |
Check failure
Code scanning / CodeQL
Incomplete string escaping or encoding High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 15 days ago
To fix the problem, we need to ensure that config['annotation_rewrite'] is properly escaped. The correct sequence is:
- Escape every backslash in the string by replacing each
\with\\. - Then, escape each
$character by replacing each$with\$.
This order ensures that any$already preceded by a backslash will still be correctly escaped, and that we do not accidentally produce unescaped$.
Specifically, we need to change line 77 of app/_plugins/blocks/httproute.rb from:
'konghq.com/rewrite' => config['annotation_rewrite']&.gsub('$', '\$'),to:
'konghq.com/rewrite' => config['annotation_rewrite']&.gsub('\\', '\\\\')&.gsub('$', '\$'),No new methods or imports are required—just the chained gsub calls. This keeps existing functionality the same but correctly escapes the value.
-
Copy modified line R77
| @@ -74,7 +74,7 @@ | ||
| 'name' => config['name'], | ||
| 'namespace' => config['namespace'], | ||
| 'annotations' => { | ||
| 'konghq.com/rewrite' => config['annotation_rewrite']&.gsub('$', '\$'), | ||
| 'konghq.com/rewrite' => config['annotation_rewrite']&.gsub('\\', '\\\\')&.gsub('$', '\$'), | ||
| 'konghq.com/plugins' => config['annotation_plugins']&.join(','), | ||
| 'konghq.com/strip-path' => 'true' | ||
| }.compact |
| 'name' => config['name'], | ||
| 'namespace' => config['namespace'], | ||
| 'annotations' => { | ||
| 'konghq.com/rewrite' => config['annotation_rewrite']&.gsub('$', '\$'), |
Check failure
Code scanning / CodeQL
Incomplete string escaping or encoding High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 15 days ago
To correctly escape $ in an input string, all existing backslashes must also be escaped, to avoid ambiguity in the resulting value. The correct order is to first escape all backslashes (\ replaced with \\), then escape all dollar signs ($ replaced with \$). This is traditionally done using two gsub calls in sequence.
For the code in app/_plugins/blocks/httproute.rb, line 124:
'konghq.com/rewrite' => config['annotation_rewrite']&.gsub('$', '\$'),replace this with:
'konghq.com/rewrite' => config['annotation_rewrite']&.gsub('\\', '\\\\')&.gsub('$', '\$'),This correctly escapes both backslashes and dollar signs in the input string.
No new imports are necessary, as Ruby's gsub method is used.
Scope: Only replace the specific occurrence on line 124 in to_ingress.
-
Copy modified line R124
| @@ -121,7 +121,7 @@ | ||
| 'name' => config['name'], | ||
| 'namespace' => config['namespace'], | ||
| 'annotations' => { | ||
| 'konghq.com/rewrite' => config['annotation_rewrite']&.gsub('$', '\$'), | ||
| 'konghq.com/rewrite' => config['annotation_rewrite']&.gsub('\\', '\\\\')&.gsub('$', '\$'), | ||
| 'konghq.com/strip-path' => 'true' | ||
| }.compact | ||
| }, |
386bfa0 to
e68c341
Compare
e68c341 to
3984571
Compare
Description
Generating YAML using liquid always felt wrong. The giveaway was when we had to start passing paths as a comma separated list, and keep track of the loop index in other parameters. The refactor lets you specify a list of
matchesPreview Links
To be added once the preview app is live
Checklist
descriptionentry in frontmatter. N/A