-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathsettings.dist.py
1754 lines (1578 loc) · 82.3 KB
/
settings.dist.py
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#########################################################################################################
# It is not allowed to edit file 'settings.dist.py', for production deployemnts. #
# Any customization of variables need to be done via environmental variables or in 'local_settings.py'. #
# For more information check https://documentation.defectdojo.com/getting_started/configuration/ #
#########################################################################################################
#########################################################################################################
# If as a developer of a new feature, you need to perform an update of file 'settings.dist.py', #
# after the change, calculate the checksum and store it related file by calling the following command: #
# $ sha256sum settings.dist.py | cut -d ' ' -f1 > .settings.dist.py.sha256sum #
#########################################################################################################
# Django settings for DefectDojo
import json
import logging
import os
import warnings
from datetime import timedelta
from email.utils import getaddresses
import environ
from celery.schedules import crontab
from netaddr import IPNetwork, IPSet
from dojo import __version__
logger = logging.getLogger(__name__)
root = environ.Path(__file__) - 3 # Three folders back
# reference: https://pypi.org/project/django-environ/
env = environ.FileAwareEnv(
# Set casting and default values
DD_SITE_URL=(str, "http://localhost:8080"),
DD_DEBUG=(bool, False),
DD_TEMPLATE_DEBUG=(bool, False),
DD_LOG_LEVEL=(str, ""),
DD_DJANGO_METRICS_ENABLED=(bool, False),
DD_LOGIN_REDIRECT_URL=(str, "/"),
DD_LOGIN_URL=(str, "/login"),
DD_DJANGO_ADMIN_ENABLED=(bool, True),
DD_SESSION_COOKIE_HTTPONLY=(bool, True),
DD_CSRF_COOKIE_HTTPONLY=(bool, True),
DD_SECURE_SSL_REDIRECT=(bool, False),
DD_SECURE_CROSS_ORIGIN_OPENER_POLICY=(str, "same-origin"),
DD_SECURE_HSTS_INCLUDE_SUBDOMAINS=(bool, False),
DD_SECURE_HSTS_SECONDS=(int, 31536000), # One year expiration
DD_SESSION_COOKIE_SECURE=(bool, False),
DD_SESSION_EXPIRE_AT_BROWSER_CLOSE=(bool, False),
DD_SESSION_COOKIE_AGE=(int, 1209600), # 14 days
DD_CSRF_COOKIE_SECURE=(bool, False),
DD_CSRF_TRUSTED_ORIGINS=(list, []),
DD_SECURE_CONTENT_TYPE_NOSNIFF=(bool, True),
DD_CSRF_COOKIE_SAMESITE=(str, "Lax"),
DD_SESSION_COOKIE_SAMESITE=(str, "Lax"),
DD_APPEND_SLASH=(bool, True),
DD_TIME_ZONE=(str, "UTC"),
DD_LANG=(str, "en-us"),
DD_TEAM_NAME=(str, "Security Team"),
DD_ADMINS=(str, "DefectDojo:dojo@localhost,Admin:admin@localhost"),
DD_WHITENOISE=(bool, False),
DD_TRACK_MIGRATIONS=(bool, True),
DD_SECURE_PROXY_SSL_HEADER=(bool, False),
DD_TEST_RUNNER=(str, "django.test.runner.DiscoverRunner"),
DD_URL_PREFIX=(str, ""),
DD_ROOT=(str, root("dojo")),
DD_LANGUAGE_CODE=(str, "en-us"),
DD_SITE_ID=(int, 1),
DD_USE_I18N=(bool, True),
DD_USE_TZ=(bool, True),
DD_MEDIA_URL=(str, "/media/"),
DD_MEDIA_ROOT=(str, root("media")),
DD_STATIC_URL=(str, "/static/"),
DD_STATIC_ROOT=(str, root("static")),
DD_CELERY_BROKER_URL=(str, ""),
DD_CELERY_BROKER_SCHEME=(str, "sqla+sqlite"),
DD_CELERY_BROKER_USER=(str, ""),
DD_CELERY_BROKER_PASSWORD=(str, ""),
DD_CELERY_BROKER_HOST=(str, ""),
DD_CELERY_BROKER_PORT=(int, -1),
DD_CELERY_BROKER_PATH=(str, "/dojo.celerydb.sqlite"),
DD_CELERY_BROKER_PARAMS=(str, ""),
DD_CELERY_BROKER_TRANSPORT_OPTIONS=(str, ""),
DD_CELERY_TASK_IGNORE_RESULT=(bool, True),
DD_CELERY_RESULT_BACKEND=(str, "django-db"),
DD_CELERY_RESULT_EXPIRES=(int, 86400),
DD_CELERY_BEAT_SCHEDULE_FILENAME=(str, root("dojo.celery.beat.db")),
DD_CELERY_TASK_SERIALIZER=(str, "pickle"),
DD_CELERY_PASS_MODEL_BY_ID=(str, True),
DD_FOOTER_VERSION=(str, ""),
# models should be passed to celery by ID, default is False (for now)
DD_FORCE_LOWERCASE_TAGS=(bool, True),
DD_MAX_TAG_LENGTH=(int, 25),
DD_DATABASE_ENGINE=(str, "django.db.backends.mysql"),
DD_DATABASE_HOST=(str, "mysql"),
DD_DATABASE_NAME=(str, "defectdojo"),
# default django database name for testing is test_<dbname>
DD_TEST_DATABASE_NAME=(str, "test_defectdojo"),
DD_DATABASE_PASSWORD=(str, "defectdojo"),
DD_DATABASE_PORT=(int, 3306),
DD_DATABASE_USER=(str, "defectdojo"),
DD_SECRET_KEY=(str, ""),
DD_CREDENTIAL_AES_256_KEY=(str, "."),
DD_DATA_UPLOAD_MAX_MEMORY_SIZE=(int, 8388608), # Max post size set to 8mb
DD_FORGOT_PASSWORD=(bool, True), # do we show link "I forgot my password" on login screen
DD_PASSWORD_RESET_TIMEOUT=(int, 259200), # 3 days, in seconds (the deafult)
DD_FORGOT_USERNAME=(bool, True), # do we show link "I forgot my username" on login screen
DD_SOCIAL_AUTH_SHOW_LOGIN_FORM=(bool, True), # do we show user/pass input
DD_SOCIAL_AUTH_CREATE_USER=(bool, True), # if True creates user at first login
DD_SOCIAL_LOGIN_AUTO_REDIRECT=(bool, False), # auto-redirect if there is only one social login method
DD_SOCIAL_AUTH_TRAILING_SLASH=(bool, True),
DD_SOCIAL_AUTH_AUTH0_OAUTH2_ENABLED=(bool, False),
DD_SOCIAL_AUTH_AUTH0_KEY=(str, ""),
DD_SOCIAL_AUTH_AUTH0_SECRET=(str, ""),
DD_SOCIAL_AUTH_AUTH0_DOMAIN=(str, ""),
DD_SOCIAL_AUTH_AUTH0_SCOPE=(list, ["openid", "profile", "email"]),
DD_SOCIAL_AUTH_GOOGLE_OAUTH2_ENABLED=(bool, False),
DD_SOCIAL_AUTH_GOOGLE_OAUTH2_KEY=(str, ""),
DD_SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET=(str, ""),
DD_SOCIAL_AUTH_GOOGLE_OAUTH2_WHITELISTED_DOMAINS=(list, [""]),
DD_SOCIAL_AUTH_GOOGLE_OAUTH2_WHITELISTED_EMAILS=(list, [""]),
DD_SOCIAL_AUTH_OKTA_OAUTH2_ENABLED=(bool, False),
DD_SOCIAL_AUTH_OKTA_OAUTH2_KEY=(str, ""),
DD_SOCIAL_AUTH_OKTA_OAUTH2_SECRET=(str, ""),
DD_SOCIAL_AUTH_OKTA_OAUTH2_API_URL=(str, "https://{your-org-url}/oauth2"),
DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_ENABLED=(bool, False),
DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_KEY=(str, ""),
DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_SECRET=(str, ""),
DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_TENANT_ID=(str, ""),
DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_RESOURCE=(str, "https://graph.microsoft.com/"),
DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_GET_GROUPS=(bool, False),
DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_GROUPS_FILTER=(str, ""),
DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_CLEANUP_GROUPS=(bool, True),
DD_SOCIAL_AUTH_GITLAB_OAUTH2_ENABLED=(bool, False),
DD_SOCIAL_AUTH_GITLAB_PROJECT_AUTO_IMPORT=(bool, False),
DD_SOCIAL_AUTH_GITLAB_PROJECT_IMPORT_TAGS=(bool, False),
DD_SOCIAL_AUTH_GITLAB_PROJECT_IMPORT_URL=(bool, False),
DD_SOCIAL_AUTH_GITLAB_PROJECT_MIN_ACCESS_LEVEL=(int, 20),
DD_SOCIAL_AUTH_GITLAB_KEY=(str, ""),
DD_SOCIAL_AUTH_GITLAB_SECRET=(str, ""),
DD_SOCIAL_AUTH_GITLAB_API_URL=(str, "https://gitlab.com"),
DD_SOCIAL_AUTH_GITLAB_SCOPE=(list, ["read_user", "openid"]),
DD_SOCIAL_AUTH_KEYCLOAK_OAUTH2_ENABLED=(bool, False),
DD_SOCIAL_AUTH_KEYCLOAK_KEY=(str, ""),
DD_SOCIAL_AUTH_KEYCLOAK_SECRET=(str, ""),
DD_SOCIAL_AUTH_KEYCLOAK_PUBLIC_KEY=(str, ""),
DD_SOCIAL_AUTH_KEYCLOAK_AUTHORIZATION_URL=(str, ""),
DD_SOCIAL_AUTH_KEYCLOAK_ACCESS_TOKEN_URL=(str, ""),
DD_SOCIAL_AUTH_KEYCLOAK_LOGIN_BUTTON_TEXT=(str, "Login with Keycloak"),
DD_SOCIAL_AUTH_GITHUB_ENTERPRISE_OAUTH2_ENABLED=(bool, False),
DD_SOCIAL_AUTH_GITHUB_ENTERPRISE_URL=(str, ""),
DD_SOCIAL_AUTH_GITHUB_ENTERPRISE_API_URL=(str, ""),
DD_SOCIAL_AUTH_GITHUB_ENTERPRISE_KEY=(str, ""),
DD_SOCIAL_AUTH_GITHUB_ENTERPRISE_SECRET=(str, ""),
DD_SAML2_ENABLED=(bool, False),
# Allows to override default SAML authentication backend. Check https://djangosaml2.readthedocs.io/contents/setup.html#custom-user-attributes-processing
DD_SAML2_AUTHENTICATION_BACKENDS=(str, "djangosaml2.backends.Saml2Backend"),
# Force Authentication to make SSO possible with SAML2
DD_SAML2_FORCE_AUTH=(bool, True),
DD_SAML2_LOGIN_BUTTON_TEXT=(str, "Login with SAML"),
# Optional: display the idp SAML Logout URL in DefectDojo
DD_SAML2_LOGOUT_URL=(str, ""),
# Metadata is required for SAML, choose either remote url or local file path
DD_SAML2_METADATA_AUTO_CONF_URL=(str, ""),
DD_SAML2_METADATA_LOCAL_FILE_PATH=(str, ""), # ex. '/public/share/idp_metadata.xml'
# Optional, default is SITE_URL + /saml2/metadata/
DD_SAML2_ENTITY_ID=(str, ""),
# Allow to create user that are not already in the Django database
DD_SAML2_CREATE_USER=(bool, False),
DD_SAML2_ATTRIBUTES_MAP=(dict, {
# Change Email/UserName/FirstName/LastName to corresponding SAML2 userprofile attributes.
# format: SAML attrib:django_user_model
"Email": "email",
"UserName": "username",
"Firstname": "first_name",
"Lastname": "last_name",
}),
DD_SAML2_ALLOW_UNKNOWN_ATTRIBUTE=(bool, False),
# Authentication via HTTP Proxy which put username to HTTP Header REMOTE_USER
DD_AUTH_REMOTEUSER_ENABLED=(bool, False),
# Names of headers which will be used for processing user data.
# WARNING: Possible spoofing of headers. Read Warning in https://docs.djangoproject.com/en/3.2/howto/auth-remote-user/#configuration
DD_AUTH_REMOTEUSER_USERNAME_HEADER=(str, "REMOTE_USER"),
DD_AUTH_REMOTEUSER_EMAIL_HEADER=(str, ""),
DD_AUTH_REMOTEUSER_FIRSTNAME_HEADER=(str, ""),
DD_AUTH_REMOTEUSER_LASTNAME_HEADER=(str, ""),
DD_AUTH_REMOTEUSER_GROUPS_HEADER=(str, ""),
DD_AUTH_REMOTEUSER_GROUPS_CLEANUP=(bool, True),
# Comma separated list of IP ranges with trusted proxies
DD_AUTH_REMOTEUSER_TRUSTED_PROXY=(list, ["127.0.0.1/32"]),
# REMOTE_USER will be processed only on login page. Check https://docs.djangoproject.com/en/3.2/howto/auth-remote-user/#using-remote-user-on-login-pages-only
DD_AUTH_REMOTEUSER_LOGIN_ONLY=(bool, False),
# `RemoteUser` is usually used behind AuthN proxy and users should not know about this mechanism from Swagger because it is not usable by users.
# It should be hidden by default.
DD_AUTH_REMOTEUSER_VISIBLE_IN_SWAGGER=(bool, False),
# if somebody is using own documentation how to use DefectDojo in his own company
DD_DOCUMENTATION_URL=(str, "https://documentation.defectdojo.com"),
# merging findings doesn't always work well with dedupe and reimport etc.
# disable it if you see any issues (and report them on github)
DD_DISABLE_FINDING_MERGE=(bool, False),
# SLA Notifications via alerts and JIRA comments
# enable either DD_SLA_NOTIFY_ACTIVE or DD_SLA_NOTIFY_ACTIVE_VERIFIED_ONLY to enable the feature.
# If desired you can enable to only notify for Findings that are linked to JIRA issues.
# All three flags are moved to system_settings, will be removed from settings file
DD_SLA_NOTIFY_ACTIVE=(bool, False),
DD_SLA_NOTIFY_ACTIVE_VERIFIED_ONLY=(bool, False),
DD_SLA_NOTIFY_WITH_JIRA_ONLY=(bool, False),
# finetuning settings for when enabled
DD_SLA_NOTIFY_PRE_BREACH=(int, 3),
DD_SLA_NOTIFY_POST_BREACH=(int, 7),
# Use business day's to calculate SLA's and age instead of calendar days
DD_SLA_BUSINESS_DAYS=(bool, False),
# maximum number of result in search as search can be an expensive operation
DD_SEARCH_MAX_RESULTS=(int, 100),
DD_SIMILAR_FINDINGS_MAX_RESULTS=(int, 25),
# The maximum number of request/response pairs to return from the API. Values <0 return all pairs.
DD_MAX_REQRESP_FROM_API=(int, -1),
DD_MAX_AUTOCOMPLETE_WORDS=(int, 20000),
DD_JIRA_SSL_VERIFY=(bool, True),
# You can set extra Jira issue types via a simple env var that supports a csv format, like "Work Item,Vulnerability"
DD_JIRA_EXTRA_ISSUE_TYPES=(str, ""),
# if you want to keep logging to the console but in json format, change this here to 'json_console'
DD_LOGGING_HANDLER=(str, "console"),
# If true, drf-spectacular will load CSS & JS from default CDN, otherwise from static resources
DD_DEFAULT_SWAGGER_UI=(bool, False),
DD_ALERT_REFRESH=(bool, True),
DD_DISABLE_ALERT_COUNTER=(bool, False),
# to disable deleting alerts per user set value to -1
DD_MAX_ALERTS_PER_USER=(int, 999),
DD_TAG_PREFETCHING=(bool, True),
DD_QUALYS_WAS_WEAKNESS_IS_VULN=(bool, False),
# regular expression to exclude one or more parsers
# could be usefull to limit parser allowed
# AWS Scout2 Scan Parser is deprecated (see https://github.com/DefectDojo/django-DefectDojo/pull/5268)
DD_PARSER_EXCLUDE=(str, ""),
# when enabled in sytem settings, every minute a job run to delete excess duplicates
# we limit the amount of duplicates that can be deleted in a single run of that job
# to prevent overlapping runs of that job from occurrring
DD_DUPE_DELETE_MAX_PER_RUN=(int, 200),
# when enabled 'mitigated date' and 'mitigated by' of a finding become editable
DD_EDITABLE_MITIGATED_DATA=(bool, False),
# new feature that tracks history across multiple reimports for the same test
DD_TRACK_IMPORT_HISTORY=(bool, True),
# Delete Auditlogs older than x month; -1 to keep all logs
DD_AUDITLOG_FLUSH_RETENTION_PERIOD=(int, -1),
# Allow grouping of findings in the same test, for example to group findings per dependency
# DD_FEATURE_FINDING_GROUPS feature is moved to system_settings, will be removed from settings file
DD_FEATURE_FINDING_GROUPS=(bool, True),
DD_JIRA_TEMPLATE_ROOT=(str, "dojo/templates/issue-trackers"),
DD_TEMPLATE_DIR_PREFIX=(str, "dojo/templates/"),
# Initial behaviour in Defect Dojo was to delete all duplicates when an original was deleted
# New behaviour is to leave the duplicates in place, but set the oldest of duplicates as new original
# Set to True to revert to the old behaviour where all duplicates are deleted
DD_DUPLICATE_CLUSTER_CASCADE_DELETE=(str, False),
# Enable Rate Limiting for the login page
DD_RATE_LIMITER_ENABLED=(bool, False),
# Examples include 5/m 100/h and more https://django-ratelimit.readthedocs.io/en/stable/rates.html#simple-rates
DD_RATE_LIMITER_RATE=(str, "5/m"),
# Block the requests after rate limit is exceeded
DD_RATE_LIMITER_BLOCK=(bool, False),
# Forces the user to change password on next login.
DD_RATE_LIMITER_ACCOUNT_LOCKOUT=(bool, False),
# when enabled SonarQube API parser will download the security hotspots
DD_SONARQUBE_API_PARSER_HOTSPOTS=(bool, True),
# when enabled, finding importing will occur asynchronously, default False
DD_ASYNC_FINDING_IMPORT=(bool, False),
# The number of findings to be processed per celeryworker
DD_ASYNC_FINDING_IMPORT_CHUNK_SIZE=(int, 100),
# When enabled, deleting objects will be occur from the bottom up. In the example of deleting an engagement
# The objects will be deleted as follows Endpoints -> Findings -> Tests -> Engagement
DD_ASYNC_OBJECT_DELETE=(bool, False),
# The number of objects to be deleted per celeryworker
DD_ASYNC_OBEJECT_DELETE_CHUNK_SIZE=(int, 100),
# When enabled, display the preview of objects to be deleted. This can take a long time to render
# for very large objects
DD_DELETE_PREVIEW=(bool, True),
# List of acceptable file types that can be uploaded to a given object via arbitrary file upload
DD_FILE_UPLOAD_TYPES=(list, [".txt", ".pdf", ".json", ".xml", ".csv", ".yml", ".png", ".jpeg",
".sarif", ".xlsx", ".doc", ".html", ".js", ".nessus", ".zip"]),
# Max file size for scan added via API in MB
DD_SCAN_FILE_MAX_SIZE=(int, 100),
# When disabled, existing user tokens will not be removed but it will not be
# possible to create new and it will not be possible to use exising.
DD_API_TOKENS_ENABLED=(bool, True),
# You can set extra Jira headers by suppling a dictionary in header: value format (pass as env var like "headr_name=value,another_header=anohter_value")
DD_ADDITIONAL_HEADERS=(dict, {}),
# Set fields used by the hashcode generator for deduplication, via en env variable that contains a JSON string
DD_HASHCODE_FIELDS_PER_SCANNER=(str, ""),
# Set deduplication algorithms per parser, via en env variable that contains a JSON string
DD_DEDUPLICATION_ALGORITHM_PER_PARSER=(str, ""),
# Dictates whether cloud banner is created or not
DD_CREATE_CLOUD_BANNER=(bool, True),
# With this setting turned on, Dojo maintains an audit log of changes made to entities (Findings, Tests, Engagements, Procuts, ...)
# If you run big import you may want to disable this because the way django-auditlog currently works, there's
# a big performance hit. Especially during (re-)imports.
DD_ENABLE_AUDITLOG=(bool, True),
# Specifies whether the "first seen" date of a given report should be used over the "last seen" date
DD_USE_FIRST_SEEN=(bool, False),
# When set to True, use the older version of the qualys parser that is a more heavy handed in setting severity
# with the use of CVSS scores to potentially override the severity found in the report produced by the tool
DD_QUALYS_LEGACY_SEVERITY_PARSING=(bool, True),
# Use System notification settings to override user's notification settings
DD_NOTIFICATIONS_SYSTEM_LEVEL_TRUMP=(list, ["user_mentioned", "review_requested"]),
)
def generate_url(scheme, double_slashes, user, password, host, port, path, params):
result_list = []
result_list.append(scheme)
result_list.append(":")
if double_slashes:
result_list.append("//")
result_list.append(user)
if len(password) > 0:
result_list.append(":")
result_list.append(password)
if len(user) > 0 or len(password) > 0:
result_list.append("@")
result_list.append(host)
if port >= 0:
result_list.append(":")
result_list.append(str(port))
if len(path) > 0 and path[0] != "/":
result_list.append("/")
result_list.append(path)
if len(params) > 0 and params[0] != "?":
result_list.append("?")
result_list.append(params)
return "".join(result_list)
# Read .env file as default or from the command line, DD_ENV_PATH
if os.path.isfile(root("dojo/settings/.env.prod")) or "DD_ENV_PATH" in os.environ:
env.read_env(root("dojo/settings/" + env.str("DD_ENV_PATH", ".env.prod")))
# ------------------------------------------------------------------------------
# GENERAL
# ------------------------------------------------------------------------------
# False if not in os.environ
DEBUG = env("DD_DEBUG")
TEMPLATE_DEBUG = env("DD_TEMPLATE_DEBUG")
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/2.0/ref/settings/#allowed-hosts
SITE_URL = env("DD_SITE_URL")
ALLOWED_HOSTS = tuple(env.list("DD_ALLOWED_HOSTS", default=["localhost", "127.0.0.1"]))
# Raises django's ImproperlyConfigured exception if SECRET_KEY not in os.environ
SECRET_KEY = env("DD_SECRET_KEY")
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = env("DD_TIME_ZONE")
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = env("DD_LANGUAGE_CODE")
SITE_ID = env("DD_SITE_ID")
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = env("DD_USE_I18N")
# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = env("DD_USE_TZ")
TEST_RUNNER = env("DD_TEST_RUNNER")
ALERT_REFRESH = env("DD_ALERT_REFRESH")
DISABLE_ALERT_COUNTER = env("DD_DISABLE_ALERT_COUNTER")
MAX_ALERTS_PER_USER = env("DD_MAX_ALERTS_PER_USER")
TAG_PREFETCHING = env("DD_TAG_PREFETCHING")
# ------------------------------------------------------------------------------
# DATABASE
# ------------------------------------------------------------------------------
# Parse database connection url strings like psql://user:[email protected]:8458/db
if os.getenv("DD_DATABASE_URL") is not None:
DATABASES = {
"default": env.db("DD_DATABASE_URL"),
}
else:
DATABASES = {
"default": {
"ENGINE": env("DD_DATABASE_ENGINE"),
"NAME": env("DD_DATABASE_NAME"),
"TEST": {
"NAME": env("DD_TEST_DATABASE_NAME"),
},
"USER": env("DD_DATABASE_USER"),
"PASSWORD": env("DD_DATABASE_PASSWORD"),
"HOST": env("DD_DATABASE_HOST"),
"PORT": env("DD_DATABASE_PORT"),
},
}
# Track migrations through source control rather than making migrations locally
if env("DD_TRACK_MIGRATIONS"):
MIGRATION_MODULES = {"dojo": "dojo.db_migrations"}
# Default for automatically created id fields,
# see https://docs.djangoproject.com/en/3.2/releases/3.2/#customizing-type-of-auto-created-primary-keys
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
# ------------------------------------------------------------------------------
# MEDIA
# ------------------------------------------------------------------------------
DOJO_ROOT = env("DD_ROOT")
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/var/www/example.com/media/"
MEDIA_ROOT = env("DD_MEDIA_ROOT")
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = env("DD_MEDIA_URL")
# ------------------------------------------------------------------------------
# STATIC
# ------------------------------------------------------------------------------
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = env("DD_STATIC_ROOT")
# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = env("DD_STATIC_URL")
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(os.path.dirname(DOJO_ROOT), "components", "node_modules"),
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
)
FILE_UPLOAD_HANDLERS = (
"django.core.files.uploadhandler.TemporaryFileUploadHandler",
)
DATA_UPLOAD_MAX_MEMORY_SIZE = env("DD_DATA_UPLOAD_MAX_MEMORY_SIZE")
# ------------------------------------------------------------------------------
# URLS
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf
# AUTHENTICATION_BACKENDS = [
# 'axes.backends.AxesModelBackend',
# ]
ROOT_URLCONF = "dojo.urls"
# Python dotted path to the WSGI application used by Django's runserver.
# https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
WSGI_APPLICATION = "dojo.wsgi.application"
URL_PREFIX = env("DD_URL_PREFIX")
# ------------------------------------------------------------------------------
# AUTHENTICATION
# ------------------------------------------------------------------------------
LOGIN_REDIRECT_URL = env("DD_LOGIN_REDIRECT_URL")
LOGIN_URL = env("DD_LOGIN_URL")
# These are the individidual modules supported by social-auth
AUTHENTICATION_BACKENDS = (
"social_core.backends.auth0.Auth0OAuth2",
"social_core.backends.google.GoogleOAuth2",
"social_core.backends.okta.OktaOAuth2",
"social_core.backends.azuread_tenant.AzureADTenantOAuth2",
"social_core.backends.gitlab.GitLabOAuth2",
"social_core.backends.keycloak.KeycloakOAuth2",
"social_core.backends.github_enterprise.GithubEnterpriseOAuth2",
"dojo.remote_user.RemoteUserBackend",
"django.contrib.auth.backends.RemoteUserBackend",
"django.contrib.auth.backends.ModelBackend",
)
# Make Argon2 the default password hasher by listing it first
# Unfortunately Django doesn't provide the default built-in
# PASSWORD_HASHERS list here as a variable which we could modify,
# so we have to list all the hashers present in Django :-(
PASSWORD_HASHERS = [
"django.contrib.auth.hashers.Argon2PasswordHasher",
"django.contrib.auth.hashers.PBKDF2PasswordHasher",
"django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher",
"django.contrib.auth.hashers.BCryptSHA256PasswordHasher",
"django.contrib.auth.hashers.BCryptPasswordHasher",
"django.contrib.auth.hashers.MD5PasswordHasher",
]
SOCIAL_AUTH_PIPELINE = (
"social_core.pipeline.social_auth.social_details",
"dojo.pipeline.social_uid",
"social_core.pipeline.social_auth.auth_allowed",
"social_core.pipeline.social_auth.social_user",
"social_core.pipeline.user.get_username",
"social_core.pipeline.social_auth.associate_by_email",
"dojo.pipeline.create_user",
"dojo.pipeline.modify_permissions",
"social_core.pipeline.social_auth.associate_user",
"social_core.pipeline.social_auth.load_extra_data",
"social_core.pipeline.user.user_details",
"dojo.pipeline.update_azure_groups",
"dojo.pipeline.update_product_access",
)
CLASSIC_AUTH_ENABLED = True
FORGOT_PASSWORD = env("DD_FORGOT_PASSWORD")
FORGOT_USERNAME = env("DD_FORGOT_USERNAME")
PASSWORD_RESET_TIMEOUT = env("DD_PASSWORD_RESET_TIMEOUT")
# Showing login form (form is not needed for external auth: OKTA, Google Auth, etc.)
SHOW_LOGIN_FORM = env("DD_SOCIAL_AUTH_SHOW_LOGIN_FORM")
SOCIAL_LOGIN_AUTO_REDIRECT = env("DD_SOCIAL_LOGIN_AUTO_REDIRECT")
SOCIAL_AUTH_CREATE_USER = env("DD_SOCIAL_AUTH_CREATE_USER")
SOCIAL_AUTH_STRATEGY = "social_django.strategy.DjangoStrategy"
SOCIAL_AUTH_STORAGE = "social_django.models.DjangoStorage"
SOCIAL_AUTH_ADMIN_USER_SEARCH_FIELDS = ["username", "first_name", "last_name", "email"]
SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL = True
GOOGLE_OAUTH_ENABLED = env("DD_SOCIAL_AUTH_GOOGLE_OAUTH2_ENABLED")
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = env("DD_SOCIAL_AUTH_GOOGLE_OAUTH2_KEY")
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = env("DD_SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET")
SOCIAL_AUTH_GOOGLE_OAUTH2_WHITELISTED_DOMAINS = env("DD_SOCIAL_AUTH_GOOGLE_OAUTH2_WHITELISTED_DOMAINS")
SOCIAL_AUTH_GOOGLE_OAUTH2_WHITELISTED_EMAILS = env("DD_SOCIAL_AUTH_GOOGLE_OAUTH2_WHITELISTED_EMAILS")
SOCIAL_AUTH_LOGIN_ERROR_URL = "/login"
SOCIAL_AUTH_BACKEND_ERROR_URL = "/login"
OKTA_OAUTH_ENABLED = env("DD_SOCIAL_AUTH_OKTA_OAUTH2_ENABLED")
SOCIAL_AUTH_OKTA_OAUTH2_KEY = env("DD_SOCIAL_AUTH_OKTA_OAUTH2_KEY")
SOCIAL_AUTH_OKTA_OAUTH2_SECRET = env("DD_SOCIAL_AUTH_OKTA_OAUTH2_SECRET")
SOCIAL_AUTH_OKTA_OAUTH2_API_URL = env("DD_SOCIAL_AUTH_OKTA_OAUTH2_API_URL")
AZUREAD_TENANT_OAUTH2_ENABLED = env("DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_ENABLED")
SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_KEY = env("DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_KEY")
SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_SECRET = env("DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_SECRET")
SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_TENANT_ID = env("DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_TENANT_ID")
SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_RESOURCE = env("DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_RESOURCE")
AZUREAD_TENANT_OAUTH2_GET_GROUPS = env("DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_GET_GROUPS")
AZUREAD_TENANT_OAUTH2_GROUPS_FILTER = env("DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_GROUPS_FILTER")
AZUREAD_TENANT_OAUTH2_CLEANUP_GROUPS = env("DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_CLEANUP_GROUPS")
GITLAB_OAUTH2_ENABLED = env("DD_SOCIAL_AUTH_GITLAB_OAUTH2_ENABLED")
GITLAB_PROJECT_AUTO_IMPORT = env("DD_SOCIAL_AUTH_GITLAB_PROJECT_AUTO_IMPORT")
GITLAB_PROJECT_IMPORT_TAGS = env("DD_SOCIAL_AUTH_GITLAB_PROJECT_IMPORT_TAGS")
GITLAB_PROJECT_IMPORT_URL = env("DD_SOCIAL_AUTH_GITLAB_PROJECT_IMPORT_URL")
GITLAB_PROJECT_MIN_ACCESS_LEVEL = env("DD_SOCIAL_AUTH_GITLAB_PROJECT_MIN_ACCESS_LEVEL")
SOCIAL_AUTH_GITLAB_KEY = env("DD_SOCIAL_AUTH_GITLAB_KEY")
SOCIAL_AUTH_GITLAB_SECRET = env("DD_SOCIAL_AUTH_GITLAB_SECRET")
SOCIAL_AUTH_GITLAB_API_URL = env("DD_SOCIAL_AUTH_GITLAB_API_URL")
SOCIAL_AUTH_GITLAB_SCOPE = env("DD_SOCIAL_AUTH_GITLAB_SCOPE")
# Add required scope if auto import is enabled
if GITLAB_PROJECT_AUTO_IMPORT:
SOCIAL_AUTH_GITLAB_SCOPE += ["read_repository"]
AUTH0_OAUTH2_ENABLED = env("DD_SOCIAL_AUTH_AUTH0_OAUTH2_ENABLED")
SOCIAL_AUTH_AUTH0_KEY = env("DD_SOCIAL_AUTH_AUTH0_KEY")
SOCIAL_AUTH_AUTH0_SECRET = env("DD_SOCIAL_AUTH_AUTH0_SECRET")
SOCIAL_AUTH_AUTH0_DOMAIN = env("DD_SOCIAL_AUTH_AUTH0_DOMAIN")
SOCIAL_AUTH_AUTH0_SCOPE = env("DD_SOCIAL_AUTH_AUTH0_SCOPE")
SOCIAL_AUTH_TRAILING_SLASH = env("DD_SOCIAL_AUTH_TRAILING_SLASH")
KEYCLOAK_OAUTH2_ENABLED = env("DD_SOCIAL_AUTH_KEYCLOAK_OAUTH2_ENABLED")
SOCIAL_AUTH_KEYCLOAK_KEY = env("DD_SOCIAL_AUTH_KEYCLOAK_KEY")
SOCIAL_AUTH_KEYCLOAK_SECRET = env("DD_SOCIAL_AUTH_KEYCLOAK_SECRET")
SOCIAL_AUTH_KEYCLOAK_PUBLIC_KEY = env("DD_SOCIAL_AUTH_KEYCLOAK_PUBLIC_KEY")
SOCIAL_AUTH_KEYCLOAK_AUTHORIZATION_URL = env("DD_SOCIAL_AUTH_KEYCLOAK_AUTHORIZATION_URL")
SOCIAL_AUTH_KEYCLOAK_ACCESS_TOKEN_URL = env("DD_SOCIAL_AUTH_KEYCLOAK_ACCESS_TOKEN_URL")
SOCIAL_AUTH_KEYCLOAK_LOGIN_BUTTON_TEXT = env("DD_SOCIAL_AUTH_KEYCLOAK_LOGIN_BUTTON_TEXT")
GITHUB_ENTERPRISE_OAUTH2_ENABLED = env("DD_SOCIAL_AUTH_GITHUB_ENTERPRISE_OAUTH2_ENABLED")
SOCIAL_AUTH_GITHUB_ENTERPRISE_URL = env("DD_SOCIAL_AUTH_GITHUB_ENTERPRISE_URL")
SOCIAL_AUTH_GITHUB_ENTERPRISE_API_URL = env("DD_SOCIAL_AUTH_GITHUB_ENTERPRISE_API_URL")
SOCIAL_AUTH_GITHUB_ENTERPRISE_KEY = env("DD_SOCIAL_AUTH_GITHUB_ENTERPRISE_KEY")
SOCIAL_AUTH_GITHUB_ENTERPRISE_SECRET = env("DD_SOCIAL_AUTH_GITHUB_ENTERPRISE_SECRET")
DOCUMENTATION_URL = env("DD_DOCUMENTATION_URL")
# Setting SLA_NOTIFY_ACTIVE and SLA_NOTIFY_ACTIVE_VERIFIED to False will disable the feature
# If you import thousands of Active findings through your pipeline everyday,
# and make the choice of enabling SLA notifications for non-verified findings,
# be mindful of performance.
# 'SLA_NOTIFY_ACTIVE', 'SLA_NOTIFY_ACTIVE_VERIFIED_ONLY' and 'SLA_NOTIFY_WITH_JIRA_ONLY' are moved to system settings, will be removed here
SLA_NOTIFY_ACTIVE = env("DD_SLA_NOTIFY_ACTIVE") # this will include 'verified' findings as well as non-verified.
SLA_NOTIFY_ACTIVE_VERIFIED_ONLY = env("DD_SLA_NOTIFY_ACTIVE_VERIFIED_ONLY")
SLA_NOTIFY_WITH_JIRA_ONLY = env("DD_SLA_NOTIFY_WITH_JIRA_ONLY") # Based on the 2 above, but only with a JIRA link
SLA_NOTIFY_PRE_BREACH = env("DD_SLA_NOTIFY_PRE_BREACH") # in days, notify between dayofbreach minus this number until dayofbreach
SLA_NOTIFY_POST_BREACH = env("DD_SLA_NOTIFY_POST_BREACH") # in days, skip notifications for findings that go past dayofbreach plus this number
SLA_BUSINESS_DAYS = env("DD_SLA_BUSINESS_DAYS") # Use business days to calculate SLA's and age of a finding instead of calendar days
SEARCH_MAX_RESULTS = env("DD_SEARCH_MAX_RESULTS")
SIMILAR_FINDINGS_MAX_RESULTS = env("DD_SIMILAR_FINDINGS_MAX_RESULTS")
MAX_REQRESP_FROM_API = env("DD_MAX_REQRESP_FROM_API")
MAX_AUTOCOMPLETE_WORDS = env("DD_MAX_AUTOCOMPLETE_WORDS")
LOGIN_EXEMPT_URLS = (
rf"^{URL_PREFIX}static/",
rf"^{URL_PREFIX}webhook/([\w-]+)$",
rf"^{URL_PREFIX}webhook/",
rf"^{URL_PREFIX}jira/webhook/([\w-]+)$",
rf"^{URL_PREFIX}jira/webhook/",
rf"^{URL_PREFIX}reports/cover$",
rf"^{URL_PREFIX}finding/image/(?P<token>[^/]+)$",
rf"^{URL_PREFIX}api/v2/",
r"complete/",
r"empty_questionnaire/([\d]+)/answer",
rf"^{URL_PREFIX}password_reset/",
rf"^{URL_PREFIX}forgot_username",
rf"^{URL_PREFIX}reset/",
)
AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "dojo.user.validators.DojoCommonPasswordValidator",
},
{
"NAME": "dojo.user.validators.MinLengthValidator",
},
{
"NAME": "dojo.user.validators.MaxLengthValidator",
},
{
"NAME": "dojo.user.validators.NumberValidator",
},
{
"NAME": "dojo.user.validators.UppercaseValidator",
},
{
"NAME": "dojo.user.validators.LowercaseValidator",
},
{
"NAME": "dojo.user.validators.SymbolValidator",
},
]
# https://django-ratelimit.readthedocs.io/en/stable/index.html
RATE_LIMITER_ENABLED = env("DD_RATE_LIMITER_ENABLED")
RATE_LIMITER_RATE = env("DD_RATE_LIMITER_RATE") # Examples include 5/m 100/h and more https://django-ratelimit.readthedocs.io/en/stable/rates.html#simple-rates
RATE_LIMITER_BLOCK = env("DD_RATE_LIMITER_BLOCK") # Block the requests after rate limit is exceeded
RATE_LIMITER_ACCOUNT_LOCKOUT = env("DD_RATE_LIMITER_ACCOUNT_LOCKOUT") # Forces the user to change password on next login.
# ------------------------------------------------------------------------------
# SECURITY DIRECTIVES
# ------------------------------------------------------------------------------
# If True, the SecurityMiddleware redirects all non-HTTPS requests to HTTPS
# (except for those URLs matching a regular expression listed in SECURE_REDIRECT_EXEMPT).
SECURE_SSL_REDIRECT = env("DD_SECURE_SSL_REDIRECT")
# If True, the SecurityMiddleware sets the X-Content-Type-Options: nosniff;
SECURE_CONTENT_TYPE_NOSNIFF = env("DD_SECURE_CONTENT_TYPE_NOSNIFF")
# Whether to use HTTPOnly flag on the session cookie.
# If this is set to True, client-side JavaScript will not to be able to access the session cookie.
SESSION_COOKIE_HTTPONLY = env("DD_SESSION_COOKIE_HTTPONLY")
# Whether to use HttpOnly flag on the CSRF cookie. If this is set to True,
# client-side JavaScript will not to be able to access the CSRF cookie.
CSRF_COOKIE_HTTPONLY = env("DD_CSRF_COOKIE_HTTPONLY")
# Whether to use a secure cookie for the session cookie. If this is set to True,
# the cookie will be marked as secure, which means browsers may ensure that the
# cookie is only sent with an HTTPS connection.
SESSION_COOKIE_SECURE = env("DD_SESSION_COOKIE_SECURE")
SESSION_COOKIE_SAMESITE = env("DD_SESSION_COOKIE_SAMESITE")
# Override default Django behavior for incorrect URLs
APPEND_SLASH = env("DD_APPEND_SLASH")
# Whether to use a secure cookie for the CSRF cookie.
CSRF_COOKIE_SECURE = env("DD_CSRF_COOKIE_SECURE")
CSRF_COOKIE_SAMESITE = env("DD_CSRF_COOKIE_SAMESITE")
# A list of trusted origins for unsafe requests (e.g. POST).
# Use comma-separated list of domains, they will be split to list automatically
# Only specify this settings if the contents is not an empty list (the default)
if env("DD_CSRF_TRUSTED_ORIGINS") != ["[]"]:
CSRF_TRUSTED_ORIGINS = env("DD_CSRF_TRUSTED_ORIGINS")
# Unless set to None, the SecurityMiddleware sets the Cross-Origin Opener Policy
# header on all responses that do not already have it to the value provided.
SECURE_CROSS_ORIGIN_OPENER_POLICY = env("DD_SECURE_CROSS_ORIGIN_OPENER_POLICY") if env("DD_SECURE_CROSS_ORIGIN_OPENER_POLICY") != "None" else None
if env("DD_SECURE_PROXY_SSL_HEADER"):
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
if env("DD_SECURE_HSTS_INCLUDE_SUBDOMAINS"):
SECURE_HSTS_SECONDS = env("DD_SECURE_HSTS_SECONDS")
SECURE_HSTS_INCLUDE_SUBDOMAINS = env("DD_SECURE_HSTS_INCLUDE_SUBDOMAINS")
SESSION_EXPIRE_AT_BROWSER_CLOSE = env("DD_SESSION_EXPIRE_AT_BROWSER_CLOSE")
SESSION_COOKIE_AGE = env("DD_SESSION_COOKIE_AGE")
# ------------------------------------------------------------------------------
# DEFECTDOJO SPECIFIC
# ------------------------------------------------------------------------------
# Credential Key
CREDENTIAL_AES_256_KEY = env("DD_CREDENTIAL_AES_256_KEY")
DB_KEY = env("DD_CREDENTIAL_AES_256_KEY")
# Used in a few places to prefix page headings and in email salutations
TEAM_NAME = env("DD_TEAM_NAME")
# Used to configure a custom version in the footer of the base.html template.
FOOTER_VERSION = env("DD_FOOTER_VERSION")
# Django-tagging settings
FORCE_LOWERCASE_TAGS = env("DD_FORCE_LOWERCASE_TAGS")
MAX_TAG_LENGTH = env("DD_MAX_TAG_LENGTH")
# ------------------------------------------------------------------------------
# ADMIN
# ------------------------------------------------------------------------------
ADMINS = getaddresses([env("DD_ADMINS")])
# https://docs.djangoproject.com/en/dev/ref/settings/#managers
MANAGERS = ADMINS
# Django admin enabled
DJANGO_ADMIN_ENABLED = env("DD_DJANGO_ADMIN_ENABLED")
# ------------------------------------------------------------------------------
# API V2
# ------------------------------------------------------------------------------
API_TOKENS_ENABLED = env("DD_API_TOKENS_ENABLED")
REST_FRAMEWORK = {
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework.authentication.SessionAuthentication",
"rest_framework.authentication.BasicAuthentication",
),
"DEFAULT_PERMISSION_CLASSES": (
"rest_framework.permissions.DjangoModelPermissions",
),
"DEFAULT_RENDERER_CLASSES": (
"rest_framework.renderers.JSONRenderer",
),
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.LimitOffsetPagination",
"PAGE_SIZE": 25,
"EXCEPTION_HANDLER": "dojo.api_v2.exception_handler.custom_exception_handler",
}
if API_TOKENS_ENABLED:
REST_FRAMEWORK["DEFAULT_AUTHENTICATION_CLASSES"] += ("rest_framework.authentication.TokenAuthentication",)
SPECTACULAR_SETTINGS = {
"TITLE": "Defect Dojo API v2",
"DESCRIPTION": "Defect Dojo - Open Source vulnerability Management made easy. Prefetch related parameters/responses not yet in the schema.",
"VERSION": __version__,
"SCHEMA_PATH_PREFIX": "/api/v2",
# OTHER SETTINGS
# the following set to False could help some client generators
# 'ENUM_ADD_EXPLICIT_BLANK_NULL_CHOICE': False,
"PREPROCESSING_HOOKS": ["dojo.urls.drf_spectacular_preprocessing_filter_spec"],
"POSTPROCESSING_HOOKS": ["dojo.api_v2.prefetch.schema.prefetch_postprocessing_hook"],
# show file selection dialogue, see https://github.com/tfranzel/drf-spectacular/issues/455
"COMPONENT_SPLIT_REQUEST": True,
"SWAGGER_UI_SETTINGS": {
"docExpansion": "none",
},
}
if not env("DD_DEFAULT_SWAGGER_UI"):
SPECTACULAR_SETTINGS["SWAGGER_UI_DIST"] = "SIDECAR"
SPECTACULAR_SETTINGS["SWAGGER_UI_FAVICON_HREF"] = "SIDECAR"
# ------------------------------------------------------------------------------
# TEMPLATES
# ------------------------------------------------------------------------------
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"APP_DIRS": True,
"OPTIONS": {
"debug": env("DD_DEBUG"),
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"social_django.context_processors.backends",
"social_django.context_processors.login_redirect",
"dojo.context_processors.globalize_vars",
"dojo.context_processors.bind_system_settings",
"dojo.context_processors.bind_alert_count",
"dojo.context_processors.bind_announcement",
],
},
},
]
# ------------------------------------------------------------------------------
# APPS
# ------------------------------------------------------------------------------
INSTALLED_APPS = (
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.sites",
"django.contrib.messages",
"django.contrib.staticfiles",
"polymorphic", # provides admin templates
"django.contrib.admin",
"django.contrib.humanize",
"auditlog",
"dojo",
"watson",
"tagging", # not used, but still needed for migration 0065_django_tagulous.py (v1.10.0)
"imagekit",
"multiselectfield",
"rest_framework",
"rest_framework.authtoken",
"dbbackup",
"django_celery_results",
"social_django",
"drf_spectacular",
"drf_spectacular_sidecar", # required for Django collectstatic discovery
"tagulous",
"fontawesomefree",
"django_filters",
)
# ------------------------------------------------------------------------------
# MIDDLEWARE
# ------------------------------------------------------------------------------
DJANGO_MIDDLEWARE_CLASSES = [
"django.middleware.common.CommonMiddleware",
"dojo.middleware.APITrailingSlashMiddleware",
"dojo.middleware.DojoSytemSettingsMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.middleware.security.SecurityMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"dojo.middleware.LoginRequiredMiddleware",
"dojo.middleware.AdditionalHeaderMiddleware",
"social_django.middleware.SocialAuthExceptionMiddleware",
"watson.middleware.SearchContextMiddleware",
"dojo.middleware.AuditlogMiddleware",
"crum.CurrentRequestUserMiddleware",
"dojo.request_cache.middleware.RequestCacheMiddleware",
]
MIDDLEWARE = DJANGO_MIDDLEWARE_CLASSES
# WhiteNoise allows your web app to serve its own static files,
# making it a self-contained unit that can be deployed anywhere without relying on nginx
if env("DD_WHITENOISE"):
WHITE_NOISE = [
# Simplified static file serving.
# https://warehouse.python.org/project/whitenoise/
"whitenoise.middleware.WhiteNoiseMiddleware",
]
MIDDLEWARE = MIDDLEWARE + WHITE_NOISE
EMAIL_CONFIG = env.email_url(
"DD_EMAIL_URL", default="smtp://user@:password@localhost:25")
vars().update(EMAIL_CONFIG)
# ------------------------------------------------------------------------------
# SAML
# ------------------------------------------------------------------------------
# For more configuration and customization options, see djangosaml2 documentation
# https://djangosaml2.readthedocs.io/contents/setup.html#configuration
# To override not configurable settings, you can use local_settings.py
# function that helps convert env var into the djangosaml2 attribute mapping format
# https://djangosaml2.readthedocs.io/contents/setup.html#users-attributes-and-account-linking
def saml2_attrib_map_format(dict):
dout = {}
for i in dict:
dout[i] = (dict[i],)
return dout
SAML2_ENABLED = env("DD_SAML2_ENABLED")
SAML2_LOGIN_BUTTON_TEXT = env("DD_SAML2_LOGIN_BUTTON_TEXT")
SAML2_LOGOUT_URL = env("DD_SAML2_LOGOUT_URL")
if SAML2_ENABLED:
from os import path
import saml2
import saml2.saml
# SSO_URL = env('DD_SSO_URL')
SAML_METADATA = {}
if len(env("DD_SAML2_METADATA_AUTO_CONF_URL")) > 0:
SAML_METADATA["remote"] = [{"url": env("DD_SAML2_METADATA_AUTO_CONF_URL")}]
if len(env("DD_SAML2_METADATA_LOCAL_FILE_PATH")) > 0:
SAML_METADATA["local"] = [env("DD_SAML2_METADATA_LOCAL_FILE_PATH")]
INSTALLED_APPS += ("djangosaml2",)
MIDDLEWARE.append("djangosaml2.middleware.SamlSessionMiddleware")
AUTHENTICATION_BACKENDS += (env("DD_SAML2_AUTHENTICATION_BACKENDS"),)
LOGIN_EXEMPT_URLS += (rf"^{URL_PREFIX}saml2/",)
SAML_LOGOUT_REQUEST_PREFERRED_BINDING = saml2.BINDING_HTTP_POST
SAML_IGNORE_LOGOUT_ERRORS = True
SAML_DJANGO_USER_MAIN_ATTRIBUTE = "username"
# SAML_DJANGO_USER_MAIN_ATTRIBUTE_LOOKUP = '__iexact'
SAML_USE_NAME_ID_AS_USERNAME = True
SAML_CREATE_UNKNOWN_USER = env("DD_SAML2_CREATE_USER")
SAML_ATTRIBUTE_MAPPING = saml2_attrib_map_format(env("DD_SAML2_ATTRIBUTES_MAP"))
SAML_FORCE_AUTH = env("DD_SAML2_FORCE_AUTH")
SAML_ALLOW_UNKNOWN_ATTRIBUTES = env("DD_SAML2_ALLOW_UNKNOWN_ATTRIBUTE")
BASEDIR = path.dirname(path.abspath(__file__))
if len(env("DD_SAML2_ENTITY_ID")) == 0:
SAML2_ENTITY_ID = f"{SITE_URL}/saml2/metadata/"
else:
SAML2_ENTITY_ID = env("DD_SAML2_ENTITY_ID")
SAML_CONFIG = {
# full path to the xmlsec1 binary programm
"xmlsec_binary": "/usr/bin/xmlsec1",
# your entity id, usually your subdomain plus the url to the metadata view
"entityid": str(SAML2_ENTITY_ID),
# directory with attribute mapping
"attribute_map_dir": path.join(BASEDIR, "attribute-maps"),
# do now discard attributes not specified in attribute-maps
"allow_unknown_attributes": SAML_ALLOW_UNKNOWN_ATTRIBUTES,
# this block states what services we provide
"service": {
# we are just a lonely SP
"sp": {
"name": "Defect_Dojo",
"name_id_format": saml2.saml.NAMEID_FORMAT_TRANSIENT,
"want_response_signed": False,
"want_assertions_signed": True,
"force_authn": SAML_FORCE_AUTH,
"allow_unsolicited": True,
# For Okta add signed logout requets. Enable this:
# "logout_requests_signed": True,
"endpoints": {
# url and binding to the assetion consumer service view
# do not change the binding or service name
"assertion_consumer_service": [
(f"{SITE_URL}/saml2/acs/",
saml2.BINDING_HTTP_POST),
],
# url and binding to the single logout service view
# do not change the binding or service name
"single_logout_service": [
# Disable next two lines for HTTP_REDIRECT for IDP's that only support HTTP_POST. Ex. Okta:
(f"{SITE_URL}/saml2/ls/",
saml2.BINDING_HTTP_REDIRECT),
(f"{SITE_URL}/saml2/ls/post",
saml2.BINDING_HTTP_POST),
],
},
# attributes that this project need to identify a user
"required_attributes": ["Email", "UserName"],
# attributes that may be useful to have but not required
"optional_attributes": ["Firstname", "Lastname"],
# in this section the list of IdPs we talk to are defined
# This is not mandatory! All the IdP available in the metadata will be considered.
# 'idp': {
# # we do not need a WAYF service since there is
# # only an IdP defined here. This IdP should be
# # present in our metadata
# # the keys of this dictionary are entity ids
# 'https://localhost/simplesaml/saml2/idp/metadata.php': {
# 'single_sign_on_service': {
# saml2.BINDING_HTTP_REDIRECT: 'https://localhost/simplesaml/saml2/idp/SSOService.php',