Skip to content

Commit c994c3d

Browse files
committed
ActionController: Prevent bad join
1 parent 687f3c6 commit c994c3d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

ruby/ql/lib/codeql/ruby/frameworks/ActionController.qll

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,15 +520,18 @@ ActionControllerClass getAssociatedControllerClass(ErbFile f) {
520520
* templates in `app/views/` and `app/views/layouts/`.
521521
*/
522522
predicate controllerTemplateFile(ActionControllerClass cls, ErbFile templateFile) {
523-
exists(string templatesPath, string sourcePrefix, string subPath, string controllerPath |
523+
exists(string sourcePrefix, string subPath, string controllerPath |
524524
controllerPath = cls.getLocation().getFile().getRelativePath() and
525-
templatesPath = templateFile.getParentContainer().getRelativePath() and
526525
// `sourcePrefix` is either a prefix path ending in a slash, or empty if
527526
// the rails app is at the source root
528527
sourcePrefix = [controllerPath.regexpCapture("^(.*/)app/controllers/(?:.*?)/(?:[^/]*)$", 1), ""] and
529528
controllerPath = sourcePrefix + "app/controllers/" + subPath + "_controller.rb" and
530529
(
531-
templatesPath = sourcePrefix + "app/views/" + subPath or
530+
exists(string templatesPath |
531+
templatesPath = templateFile.getParentContainer().getRelativePath() and
532+
templatesPath = sourcePrefix + "app/views/" + subPath
533+
)
534+
or
532535
templateFile.getRelativePath().matches(sourcePrefix + "app/views/layouts/" + subPath + "%")
533536
)
534537
)

0 commit comments

Comments
 (0)