File tree Expand file tree Collapse file tree 3 files changed +76
-0
lines changed
ruby/ql/src/queries/security/cwe-732 Expand file tree Collapse file tree 3 files changed +76
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE qhelp PUBLIC
2
+ "-//Semmle//qhelp//EN"
3
+ "qhelp.dtd">
4
+ <qhelp >
5
+
6
+ <overview >
7
+ <p >
8
+ Cookies can be used for security measures, such as authenticating a user
9
+ based on cookies sent with a request. Misconfiguration of cookie settings
10
+ in a web application can expose users to attacks that compromise these
11
+ security measures.
12
+ </p >
13
+ </overview >
14
+
15
+ <recommendation >
16
+ <p >
17
+ Modern web frameworks typically have good default configuration for cookie
18
+ settings. If an application overrides these settings, then take care to
19
+ ensure that these changes are necessary and that they don't weaken the
20
+ cookie configuration.
21
+ </p >
22
+ </recommendation >
23
+
24
+ <example >
25
+ <p >
26
+ In the first example, the value of
27
+ <code >config.action_dispatch.cookies_same_site_protection</code > is set to
28
+ <code >:none</code >. This has the effect of setting the default
29
+ <code >SameSite</code > attribute sent by the server when setting a cookie
30
+ to <code >None</code > rather than the default of <code >Lax</code >. This may
31
+ make the application more vulnerable to cross-site request forgery
32
+ attacks.
33
+ </p >
34
+
35
+ <p >
36
+ In the second example, this option is instead set to <code >:strict</code >.
37
+ This is a stronger restriction than the default of <code >:lax</code >, and
38
+ doesn't compromise on cookie security.
39
+ </p >
40
+
41
+ <sample src =" examples/weak_cookie_configuration.rb" />
42
+ </example >
43
+
44
+ <references >
45
+ <li >OWASP: <a href =" https://owasp.org/www-community/SameSite" >SameSite</a >.</li >
46
+ <li >Rails: <a href =" https://guides.rubyonrails.org/configuring.html#configuring-action-dispatch" >Configuring Action Dispatch</a >.</li >
47
+ </references >
48
+ </qhelp >
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @name Weak cookie configuration
3
+ * @description Misconfiguring how cookies are encrypted or sent can expose a user to various attacks.
4
+ * @kind problem
5
+ * @problem.severity warning
6
+ * @security-severity 7.8
7
+ * @id rb/weak-cookie-configuration
8
+ * @tags external/cwe/cwe-732
9
+ * external/cwe/cwe-1275
10
+ * security
11
+ * @precision high
12
+ */
13
+
14
+ import ruby
15
+ import codeql.ruby.Concepts
16
+ import codeql.ruby.Frameworks
17
+
18
+ from CookieSecurityConfigurationSetting s
19
+ select s , s .getSecurityWarningMessage ( )
Original file line number Diff line number Diff line change
1
+ module App
2
+ class Application < Rails ::Application
3
+ # Sets default `Set-Cookie` `SameSite` attribute to `None`
4
+ config . action_dispatch . cookies_same_site_protection = :none
5
+
6
+ # Sets default `Set-Cookie` `SameSite` attribute to `Strict`
7
+ config . action_dispatch . cookies_same_site_protection = :strict
8
+ end
9
+ end
You can’t perform that action at this time.
0 commit comments