avoid-hardcoded-credentials
- Group
- Security
- Path
lint/security/avoid-hardcoded-credentials- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 68 of 512
Warns when credential-like variables, fields, or parameter defaults use nonempty string or numeric literals.
Names such as password, apiKey, clientSecret, and accessToken are
checked case-insensitively, including snake_case and private spellings.
String values matching their variable name are ignored as storage-key names.
Read credentials from secure runtime configuration instead. This is a naming
heuristic, not a general-purpose secrets scanner.
Invalid
const password = 'not-a-real-password';
class Settings {
final _apiKey = 'fixture-key';
String clientSecret = '';
void update() {
clientSecret = 'fixture-secret';
this.clientSecret = 'other-fixture-secret';
}
}
const ACCESS_TOKEN = 'fixture-token';
void connect({String password = 'fixture-password'}) {}
void authenticate([String apiKey = 'fixture-key']) {}
void configure({String client_secret = ('fixture-secret')}) {}
void unlock({int passwd = 1234}) {}
void authorize([double authToken = 1.5]) {}
class Connection {
final String password;
Connection({this.password = 'fixture-password'});
Connection.positional([this.password = 'fixture-password']);
Connection.named({String secret = 'fixture-secret'}) : password = secret;
void login({String accessToken = 'fixture-token'}) {}
void refresh([String privateKey = 'fixture-key']) {}
}
class ChildConnection extends Connection {
ChildConnection({super.password = 'fixture-password'});
ChildConnection.positional([super.password = 'fixture-password']) : super.positional();
}
void callbacks() {
void local([String _PASSWORD = 'fixture-password']) {}
final named = ({String api_key = 'fixture-key'}) {};
final positional = ([String clientSecret = 'fixture-secret']) {};
}const password = 'not-a-real-password';class Settings { final _apiKey = 'fixture-key'; void update() { clientSecret = 'fixture-secret'; clientSecret = 'fixture-secret'; this.clientSecret = 'other-fixture-secret';}const ACCESS_TOKEN = 'fixture-token'; void connect({String password = 'fixture-password'}) {}void connect({String password = 'fixture-password'}) {}void authenticate([String apiKey = 'fixture-key']) {}void authenticate([String apiKey = 'fixture-key']) {}void configure({String client_secret = ('fixture-secret')}) {}void configure({String client_secret = ('fixture-secret')}) {}void unlock({int passwd = 1234}) {}void unlock({int passwd = 1234}) {}void authorize([double authToken = 1.5]) {} final String password; Connection({this.password = 'fixture-password'}); Connection({this.password = 'fixture-password'}); Connection.positional([this.password = 'fixture-password']); Connection.positional([this.password = 'fixture-password']); Connection.named({String secret = 'fixture-secret'}) : password = secret; Connection.named({String secret = 'fixture-secret'}) : password = secret; void login({String accessToken = 'fixture-token'}) {} void login({String accessToken = 'fixture-token'}) {} void refresh([String privateKey = 'fixture-key']) {}class ChildConnection extends Connection { ChildConnection({super.password = 'fixture-password'}); ChildConnection({super.password = 'fixture-password'}); ChildConnection.positional([super.password = 'fixture-password']) : super.positional();void callbacks() { void local([String _PASSWORD = 'fixture-password']) {} void local([String _PASSWORD = 'fixture-password']) {} final named = ({String api_key = 'fixture-key'}) {}; final named = ({String api_key = 'fixture-key'}) {}; final positional = ([String clientSecret = 'fixture-secret']) {};Valid
String readSecret() => '';
final password = readSecret();
const apiKey = '';
const secretCount = 3;
const token = 'not-a-credential-name';
const accessToken = 'access_token';
const _authToken = 'AUTH-TOKEN';
class StorageKeys {
static const password = 'password';
}
void update(String supplied) {
final clientSecret = supplied;
final accessToken = 'prefix-$supplied';
}
const configuredSecret = 'fixture-configured-value';
void connect({
String password = '',
String? passwd = null,
String clientSecret = configuredSecret,
String apiKey = 'API-KEY',
String token = 'not-a-credential-name',
int secretCount = 3,
}) {}
void authenticate([String password = 'password']) {}
void storageKey([String _access_token = 'accessToken']) {}
void requiredCredentials(String password, {required String apiKey}) {}
class Connection {
final String password;
Connection({this.password = 'password'});
Connection.positional([this.password = configuredSecret]);
void login({String authToken = 'auth_token'}) {}
void refresh([String privateKey = configuredSecret]) {}
}
class ChildConnection extends Connection {
ChildConnection({super.password = ''});
ChildConnection.positional([super.password = 'password']) : super.positional();
}
void callbacks() {
void local({String secret = 'secret'}) {}
final named = ({String apiKey = configuredSecret}) {};
final positional = ([String clientSecret = 'CLIENT-SECRET']) {};
}Configure avoid-hardcoded-credentials
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"security": {
"avoid-hardcoded-credentials": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/security/avoid-hardcoded-credentials: <reason>More security rules
- avoid-sensitive-query-params
Detect explicit secret-bearing URL query keys, not arbitrary occurrences of words such as
tokenin paths, fragments, map values, or prose. - avoid-weak-cryptographic-algorithmsrecommended
Flags references to MD5, SHA-1, DES, triple DES, and RC4 package APIs.
- prefer-random-secure
Prefer the cryptographically secure
dart:mathrandom generator. - secure-pubspec-urls
secure_pubspec_urlsrecommendedcross-fileDisallow insecure URL schemes in
pubspec.yamlstring values.